]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
tests: create entry for testDeleteEntry, fix missing id
authorKevin Decherf <kevin@kdecherf.com>
Sun, 17 Feb 2019 14:25:21 +0000 (15:25 +0100)
committerKevin Decherf <kevin@kdecherf.com>
Sun, 17 Feb 2019 14:25:21 +0000 (15:25 +0100)
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>
tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php

index 2a1d2e155448db29bc107c2596ce56eef5424ac1..ddeca4c047f296e68b165bcb2214865ea870f049 100644 (file)
@@ -400,14 +400,36 @@ class EntryRestControllerTest extends WallabagApiTestCase
 
     public function testDeleteEntry()
     {
-        $entry = $this->client->getContainer()
-            ->get('doctrine.orm.entity_manager')
-            ->getRepository('WallabagCoreBundle:Entry')
-            ->findOneByUser(1, ['id' => 'asc']);
+        $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
+        $entry = new Entry($em->getReference(User::class, 1));
+        $entry->setUrl('http://0.0.0.0/test-delete-entry');
+        $entry->setTitle('Test delete entry');
+        $em->persist($entry);
+        $em->flush();
 
-        if (!$entry) {
-            $this->markTestSkipped('No content found in db.');
-        }
+        $em->clear();
+
+        $e = [
+            'title' => $entry->getTitle(),
+            'url' => $entry->getUrl(),
+            'id' => $entry->getId(),
+        ];
+
+        $this->client->request('DELETE', '/api/entries/' . $e['id'] . '.json');
+
+        $this->assertSame(200, $this->client->getResponse()->getStatusCode());
+
+        $content = json_decode($this->client->getResponse()->getContent(), true);
+
+        $this->assertSame($e['title'], $content['title']);
+        $this->assertSame($e['url'], $content['url']);
+        $this->assertSame($e['id'], $content['id']);
+
+        // We'll try to delete this entry again
+        $this->client->request('DELETE', '/api/entries/' . $e['id'] . '.json');
+
+        $this->assertSame(404, $this->client->getResponse()->getStatusCode());
+    }
 
         $this->client->request('DELETE', '/api/entries/' . $entry->getId() . '.json');