aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag
diff options
context:
space:
mode:
authorKevin Decherf <kevin@kdecherf.com>2019-02-17 15:25:21 +0100
committerKevin Decherf <kevin@kdecherf.com>2019-02-17 15:25:21 +0100
commit4e0ed3368d2bdc2fa0d330e58902e792a896be06 (patch)
tree8343e13a3d04a6bf51f8b96a7d244ddbedecfd4d /tests/Wallabag
parentb1992b340e21b6846a1ec2ae6ddd7217f3b24fb5 (diff)
downloadwallabag-4e0ed3368d2bdc2fa0d330e58902e792a896be06.tar.gz
wallabag-4e0ed3368d2bdc2fa0d330e58902e792a896be06.tar.zst
wallabag-4e0ed3368d2bdc2fa0d330e58902e792a896be06.zip
tests: create entry for testDeleteEntry, fix missing id
When using the entity manager to retrieve an already stored entry, the id disapears from $entry after the first delete call. This leads to testing a nonexistent endpoint (api/entries/.json) during the second delete call. This change now creates an entry specifically for the test. Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
Diffstat (limited to 'tests/Wallabag')
-rw-r--r--tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php36
1 files changed, 29 insertions, 7 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
index 2a1d2e15..ddeca4c0 100644
--- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
@@ -400,14 +400,36 @@ class EntryRestControllerTest extends WallabagApiTestCase
400 400
401 public function testDeleteEntry() 401 public function testDeleteEntry()
402 { 402 {
403 $entry = $this->client->getContainer() 403 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
404 ->get('doctrine.orm.entity_manager') 404 $entry = new Entry($em->getReference(User::class, 1));
405 ->getRepository('WallabagCoreBundle:Entry') 405 $entry->setUrl('http://0.0.0.0/test-delete-entry');
406 ->findOneByUser(1, ['id' => 'asc']); 406 $entry->setTitle('Test delete entry');
407 $em->persist($entry);
408 $em->flush();
407 409
408 if (!$entry) { 410 $em->clear();
409 $this->markTestSkipped('No content found in db.'); 411
410 } 412 $e = [
413 'title' => $entry->getTitle(),
414 'url' => $entry->getUrl(),
415 'id' => $entry->getId(),
416 ];
417
418 $this->client->request('DELETE', '/api/entries/' . $e['id'] . '.json');
419
420 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
421
422 $content = json_decode($this->client->getResponse()->getContent(), true);
423
424 $this->assertSame($e['title'], $content['title']);
425 $this->assertSame($e['url'], $content['url']);
426 $this->assertSame($e['id'], $content['id']);
427
428 // We'll try to delete this entry again
429 $this->client->request('DELETE', '/api/entries/' . $e['id'] . '.json');
430
431 $this->assertSame(404, $this->client->getResponse()->getStatusCode());
432 }
411 433
412 $this->client->request('DELETE', '/api/entries/' . $entry->getId() . '.json'); 434 $this->client->request('DELETE', '/api/entries/' . $entry->getId() . '.json');
413 435