From 08f29ae7b6af585f3af1dd2f8b01854fb0985668 Mon Sep 17 00:00:00 2001 From: adev Date: Mon, 8 May 2017 12:35:02 +0200 Subject: Create a new entry via API even when its content can't be retrieved Fix #2988 --- .../Controller/EntryRestControllerTest.php | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 409a8291..0979ca93 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -4,6 +4,7 @@ namespace Tests\Wallabag\ApiBundle\Controller; use Tests\Wallabag\ApiBundle\WallabagApiTestCase; use Wallabag\CoreBundle\Entity\Tag; +use Wallabag\CoreBundle\Helper\ContentProxy; class EntryRestControllerTest extends WallabagApiTestCase { @@ -359,6 +360,29 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertCount(2, $content['tags']); } + public function testPostEntryWhenFetchContentFails() + { + /** @var \Symfony\Component\DependencyInjection\Container $container */ + $container = $this->client->getContainer(); + $contentProxy = $this->getMockBuilder(ContentProxy::class) + ->disableOriginalConstructor() + ->setMethods(['updateEntry']) + ->getMock(); + $contentProxy->expects($this->any()) + ->method('updateEntry') + ->willThrowException(new \Exception('Test Fetch content fails')); + $container->set('wallabag_core.content_proxy', $contentProxy); + + $this->client->request('POST', '/api/entries.json', [ + 'url' => 'http://www.example.com/', + ]); + + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $content = json_decode($this->client->getResponse()->getContent(), true); + $this->assertGreaterThan(0, $content['id']); + $this->assertEquals('http://www.example.com/', $content['url']); + } + public function testPostArchivedAndStarredEntry() { $this->client->request('POST', '/api/entries.json', [ -- cgit v1.2.3 From 1b1647175d7eaa2800a2eff9f984ef37e9976fba Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 9 May 2017 12:12:23 +0200 Subject: Add some tests --- .../CoreBundle/Controller/EntryControllerTest.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 3eb6d47f..7db4cf1f 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -591,6 +591,26 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertCount(1, $crawler->filter('div[class=entry]')); } + public function testFilterOnReadingTimeWithNegativeValue() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/unread/list'); + + $form = $crawler->filter('button[id=submit-filter]')->form(); + + $data = [ + 'entry_filter[readingTime][right_number]' => -22, + 'entry_filter[readingTime][left_number]' => -22, + ]; + + $crawler = $client->submit($form, $data); + + // forcing negative value results in no entry displayed + $this->assertCount(0, $crawler->filter('div[class=entry]')); + } + public function testFilterOnReadingTimeOnlyUpper() { $this->logInAs('admin'); -- cgit v1.2.3 From a9357a8311b2a3a9a114ec8400a9878d5f1f8345 Mon Sep 17 00:00:00 2001 From: adev Date: Tue, 9 May 2017 23:19:24 +0200 Subject: Remove the created entry to avoid side effects on other tests --- .../Controller/EntryRestControllerTest.php | 26 +++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 0979ca93..deafd1fa 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -373,14 +373,24 @@ class EntryRestControllerTest extends WallabagApiTestCase ->willThrowException(new \Exception('Test Fetch content fails')); $container->set('wallabag_core.content_proxy', $contentProxy); - $this->client->request('POST', '/api/entries.json', [ - 'url' => 'http://www.example.com/', - ]); - - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); - $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertGreaterThan(0, $content['id']); - $this->assertEquals('http://www.example.com/', $content['url']); + try { + $this->client->request('POST', '/api/entries.json', [ + 'url' => 'http://www.example.com/', + ]); + + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $content = json_decode($this->client->getResponse()->getContent(), true); + $this->assertGreaterThan(0, $content['id']); + $this->assertEquals('http://www.example.com/', $content['url']); + } finally { + // Remove the created entry to avoid side effects on other tests + if (isset($content['id'])) { + $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); + $entry = $em->getReference('WallabagCoreBundle:Entry', $content['id']); + $em->remove($entry); + $em->flush(); + } + } } public function testPostArchivedAndStarredEntry() -- cgit v1.2.3