From 0a6f4568b5e4f6291cc19cbea929ed1ebeca3a54 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 20 Nov 2016 13:08:41 +0100 Subject: Add ability to reload entry from API --- .../Controller/EntryRestControllerTest.php | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'tests') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 566e9493..3c8b7980 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -678,4 +678,41 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertEquals(403, $this->client->getResponse()->getStatusCode()); } + + public function testReloadEntryErrorWhileFetching() + { + $entry = $this->client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneBy(['user' => 1, 'isArchived' => false]); + + if (!$entry) { + $this->markTestSkipped('No content found in db.'); + } + + $this->client->request('PATCH', '/api/entries/'.$entry->getId().'/reload.json'); + $this->assertEquals(304, $this->client->getResponse()->getStatusCode()); + } + + public function testReloadEntry() + { + $this->client->request('POST', '/api/entries.json', [ + 'url' => 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', + 'archive' => '1', + 'tags' => 'google, apple', + ]); + + $json = json_decode($this->client->getResponse()->getContent(), true); + + $this->setUp(); + + $this->client->request('PATCH', '/api/entries/'.$json['id'].'/reload.json'); + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertNotEmpty($content['title']); + + $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); + } } -- cgit v1.2.3 From 70584b42aaa75c2fe9adda5cf6c37ab63adcccb3 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 20 Nov 2016 15:15:13 +0100 Subject: Fixing tests --- tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 3c8b7980..409a8291 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -681,10 +681,9 @@ class EntryRestControllerTest extends WallabagApiTestCase public function testReloadEntryErrorWhileFetching() { - $entry = $this->client->getContainer() - ->get('doctrine.orm.entity_manager') + $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneBy(['user' => 1, 'isArchived' => false]); + ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); if (!$entry) { $this->markTestSkipped('No content found in db.'); -- cgit v1.2.3 From 56da73969ac49e400ade89248f87c643047221d6 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 20 Nov 2016 16:25:13 +0100 Subject: Return an explicit error if reload fail --- tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 409a8291..432ce7d8 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -690,7 +690,11 @@ class EntryRestControllerTest extends WallabagApiTestCase } $this->client->request('PATCH', '/api/entries/'.$entry->getId().'/reload.json'); - $this->assertEquals(304, $this->client->getResponse()->getStatusCode()); + $this->assertEquals(400, $this->client->getResponse()->getStatusCode()); + + $this->assertContains('Error while trying to extract content', $this->client->getResponse()->getContent()); + + $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); } public function testReloadEntry() -- cgit v1.2.3