From c9fa9677c1ae7b9be2305cef8f61fa2e0fc14d58 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nicolas=20L=C5=93uillet?= Date: Wed, 11 Feb 2015 07:43:43 +0100 Subject: [PATCH] DELETE entry and use of query for fetch entries --- .../Controller/WallabagRestControllerTest.php | 49 ++++++++++++++++--- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php index 1240844b..c7704aa8 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/WallabagRestControllerTest.php @@ -45,12 +45,21 @@ class WallabagRestControllerTest extends WebTestCase { $client = $this->createClient(); $client->request('GET', '/api/salts/admin.json'); - $content = json_decode($client->getResponse()->getContent()); + $salt = json_decode($client->getResponse()->getContent()); - $headers = $this->generateHeaders('admin', 'test', $content[0]); + $headers = $this->generateHeaders('admin', 'test', $salt[0]); - $client->request('GET', '/api/entries/1.json', array(), array(), $headers); - $this->assertContains('This is my content', $client->getResponse()->getContent()); + $entry = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneByIsArchived(false); + + if (!$entry) { + $this->markTestSkipped('No content found in db.'); + } + + $client->request('GET', '/api/entries/'.$entry->getId().'.json', array(), array(), $headers); + $this->assertContains($entry->getTitle(), $client->getResponse()->getContent()); $this->assertTrue( $client->getResponse()->headers->contains( @@ -64,9 +73,9 @@ class WallabagRestControllerTest extends WebTestCase { $client = $this->createClient(); $client->request('GET', '/api/salts/admin.json'); - $content = json_decode($client->getResponse()->getContent()); + $salt = json_decode($client->getResponse()->getContent()); - $headers = $this->generateHeaders('admin', 'test', $content[0]); + $headers = $this->generateHeaders('admin', 'test', $salt[0]); $client->request('GET', '/api/entries', array(), array(), $headers); $this->assertContains('Mailjet', $client->getResponse()->getContent()); @@ -78,4 +87,32 @@ class WallabagRestControllerTest extends WebTestCase ) ); } + + public function testDeleteEntry() + { + $client = $this->createClient(); + $client->request('GET', '/api/salts/admin.json'); + $salt = json_decode($client->getResponse()->getContent()); + + $headers = $this->generateHeaders('admin', 'test', $salt[0]); + + $entry = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneByIsDeleted(false); + + if (!$entry) { + $this->markTestSkipped('No content found in db.'); + } + + $client->request('DELETE', '/api/entries/'.$entry->getId().'.json', array(), array(), $headers); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $res = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneById($entry->getId()); + $this->assertEquals($res->isDeleted(), true); + } } -- 2.41.0