From e5fb89e5d31c1c0645e8dd252bb4f970dc5f3226 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sat, 25 Jun 2016 21:05:50 +0200 Subject: Add since parameter --- .../Controller/WallabagRestControllerTest.php | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php index c39cc357..f256a7f9 100644 --- a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php @@ -121,6 +121,51 @@ class WallabagRestControllerTest extends WallabagApiTestCase ); } + public function testGetDatedEntries() + { + $this->client->request('GET', '/api/entries', ['since' => 1]); + + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertGreaterThanOrEqual(1, count($content)); + $this->assertNotEmpty($content['_embedded']['items']); + $this->assertGreaterThanOrEqual(1, $content['total']); + $this->assertEquals(1, $content['page']); + $this->assertGreaterThanOrEqual(1, $content['pages']); + + $this->assertTrue( + $this->client->getResponse()->headers->contains( + 'Content-Type', + 'application/json' + ) + ); + } + + public function testGetDatedSupEntries() + { + $future = new \DateTime(date('Y-m-d H:i:s')); + $this->client->request('GET', '/api/entries', ['since' => $future->getTimestamp() + 1000]); + + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertGreaterThanOrEqual(1, count($content)); + $this->assertEmpty($content['_embedded']['items']); + $this->assertEquals(0, $content['total']); + $this->assertEquals(1, $content['page']); + $this->assertEquals(1, $content['pages']); + + $this->assertTrue( + $this->client->getResponse()->headers->contains( + 'Content-Type', + 'application/json' + ) + ); + } + public function testDeleteEntry() { $entry = $this->client->getContainer() -- cgit v1.2.3 From 28803f106bd091b5a7540a134cba2545d12d25ea Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sat, 25 Jun 2016 16:27:38 +0200 Subject: Add filter for tags on API --- .../Controller/WallabagRestControllerTest.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php index f256a7f9..528366af 100644 --- a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php @@ -121,6 +121,28 @@ class WallabagRestControllerTest extends WallabagApiTestCase ); } + public function testGetTaggedEntries() + { + $this->client->request('GET', '/api/entries', ['tags' => 'foo,bar']); + + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertGreaterThanOrEqual(1, count($content)); + $this->assertNotEmpty($content['_embedded']['items']); + $this->assertGreaterThanOrEqual(1, $content['total']); + $this->assertEquals(1, $content['page']); + $this->assertGreaterThanOrEqual(1, $content['pages']); + + $this->assertTrue( + $this->client->getResponse()->headers->contains( + 'Content-Type', + 'application/json' + ) + ); + } + public function testGetDatedEntries() { $this->client->request('GET', '/api/entries', ['since' => 1]); -- cgit v1.2.3 From db4d63fc1ae513335b751beb8f89e1eed61871c2 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 24 Jul 2016 11:15:51 +0200 Subject: Upgrade PHPUnit to version 5 - Fix deprecated getMock - Use PHPUnit 4 for PHP 5.5 build Manually cherry-picked from PR https://github.com/wallabag/wallabag/pull/2201 --- tests/Wallabag/CoreBundle/EventListener/LocaleListenerTest.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/CoreBundle/EventListener/LocaleListenerTest.php b/tests/Wallabag/CoreBundle/EventListener/LocaleListenerTest.php index 2a7f9390..078bb69a 100644 --- a/tests/Wallabag/CoreBundle/EventListener/LocaleListenerTest.php +++ b/tests/Wallabag/CoreBundle/EventListener/LocaleListenerTest.php @@ -15,7 +15,11 @@ class LocaleListenerTest extends \PHPUnit_Framework_TestCase { private function getEvent(Request $request) { - return new GetResponseEvent($this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'), $request, HttpKernelInterface::MASTER_REQUEST); + $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface') + ->disableOriginalConstructor() + ->getMock(); + + return new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); } public function testWithoutSession() -- cgit v1.2.3 From 9c545fe028013b30417c1a932cd6b9027bff752d Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sat, 21 May 2016 18:09:38 +0200 Subject: Added name on client - Fix typos in field name - Added migration for name field in API client table Manually cherry-picked from PR https://github.com/wallabag/wallabag/pull/2171 --- tests/Wallabag/CoreBundle/Controller/DeveloperControllerTest.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/CoreBundle/Controller/DeveloperControllerTest.php b/tests/Wallabag/CoreBundle/Controller/DeveloperControllerTest.php index 79452ace..97ed0d58 100644 --- a/tests/Wallabag/CoreBundle/Controller/DeveloperControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/DeveloperControllerTest.php @@ -18,12 +18,19 @@ class DeveloperControllerTest extends WallabagCoreTestCase $form = $crawler->filter('button[type=submit]')->form(); - $client->submit($form); + $data = [ + 'client[name]' => 'My app', + ]; + + $crawler = $client->submit($form, $data); $this->assertEquals(200, $client->getResponse()->getStatusCode()); $newNbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); $this->assertGreaterThan(count($nbClients), count($newNbClients)); + + $this->assertGreaterThan(1, $alert = $crawler->filter('.settings ul li strong')->extract(['_text'])); + $this->assertContains('My app', $alert[0]); } public function testListingClient() -- cgit v1.2.3 From 267e8d6361f8e7791a8687f2370a3e9d08af6648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sat, 30 Apr 2016 15:03:22 +0200 Subject: Add tests for tag list routes --- .../CoreBundle/Controller/TagControllerTest.php | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index 58450e5f..71652760 100644 --- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php @@ -131,4 +131,35 @@ class TagControllerTest extends WallabagCoreTestCase $this->assertEquals(404, $client->getResponse()->getStatusCode()); } + + public function testShowEntriesForTagAction() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $entry = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneByUsernameAndNotArchived('admin'); + + $tag = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Tag') + ->findOneByEntryAndTagLabel($entry, 'foo'); + + $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug()); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertCount(2, $crawler->filter('div[class=entry]')); + + $tag = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Tag') + ->findOneByLabel('baz'); + + $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug()); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertCount(0, $crawler->filter('div[class=entry]')); + } } -- cgit v1.2.3 From a0e1eafc35e1007056555651ace7221d09cd8270 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 24 Jul 2016 10:55:49 +0200 Subject: Add some tests Also, retrieve tag from the request instead of the query (which will be the same but it's more easy to test). Moved down `deleteTagAction` because it conflicted with the new action: api_delete_tag => /api/tags/{tag}.{_format} api_delete_tags_label => /api/tags/label.{_format} And finally, throw exception when a tag is not found before removing it. --- .../Controller/WallabagRestControllerTest.php | 113 ++++++++++++++++++++- 1 file changed, 110 insertions(+), 3 deletions(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php index 528366af..ee5b2ab7 100644 --- a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php @@ -3,6 +3,7 @@ namespace Tests\Wallabag\ApiBundle\Controller; use Tests\Wallabag\ApiBundle\WallabagApiTestCase; +use Wallabag\CoreBundle\Entity\Tag; class WallabagRestControllerTest extends WallabagApiTestCase { @@ -359,7 +360,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase $entry = $this->client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneWithTags(1); + ->findOneWithTags($this->user->getId()); $entry = $entry[0]; @@ -421,7 +422,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase $entry = $this->client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneWithTags(1); + ->findOneWithTags($this->user->getId()); $entry = $entry[0]; if (!$entry) { @@ -472,7 +473,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase $this->assertEquals($tag['label'], $content['label']); $this->assertEquals($tag['slug'], $content['slug']); - $entries = $entry = $this->client->getContainer() + $entries = $this->client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') ->findAllByTagId($this->user->getId(), $tag['id']); @@ -480,6 +481,112 @@ class WallabagRestControllerTest extends WallabagApiTestCase $this->assertCount(0, $entries); } + public function testDeleteTagByLabel() + { + $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); + $entry = $this->client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneWithTags($this->user->getId()); + + $entry = $entry[0]; + + $tag = new Tag(); + $tag->setLabel('Awesome tag for test'); + $em->persist($tag); + + $entry->addTag($tag); + + $em->persist($entry); + $em->flush(); + + $this->client->request('DELETE', '/api/tag/label.json', ['tag' => $tag->getLabel()]); + + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertArrayHasKey('label', $content); + $this->assertEquals($tag->getLabel(), $content['label']); + $this->assertEquals($tag->getSlug(), $content['slug']); + + $entries = $this->client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findAllByTagId($this->user->getId(), $tag->getId()); + + $this->assertCount(0, $entries); + } + + public function testDeleteTagByLabelNotFound() + { + $this->client->request('DELETE', '/api/tag/label.json', ['tag' => 'does not exist']); + + $this->assertEquals(404, $this->client->getResponse()->getStatusCode()); + } + + public function testDeleteTagsByLabel() + { + $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); + $entry = $this->client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneWithTags($this->user->getId()); + + $entry = $entry[0]; + + $tag = new Tag(); + $tag->setLabel('Awesome tag for tagsLabel'); + $em->persist($tag); + + $tag2 = new Tag(); + $tag2->setLabel('Awesome tag for tagsLabel 2'); + $em->persist($tag2); + + $entry->addTag($tag); + $entry->addTag($tag2); + + $em->persist($entry); + $em->flush(); + + $this->client->request('DELETE', '/api/tags/label.json', ['tags' => $tag->getLabel().','.$tag2->getLabel()]); + + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertCount(2, $content); + + $this->assertArrayHasKey('label', $content[0]); + $this->assertEquals($tag->getLabel(), $content[0]['label']); + $this->assertEquals($tag->getSlug(), $content[0]['slug']); + + $this->assertArrayHasKey('label', $content[1]); + $this->assertEquals($tag2->getLabel(), $content[1]['label']); + $this->assertEquals($tag2->getSlug(), $content[1]['slug']); + + $entries = $this->client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findAllByTagId($this->user->getId(), $tag->getId()); + + $this->assertCount(0, $entries); + + $entries = $this->client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findAllByTagId($this->user->getId(), $tag2->getId()); + + $this->assertCount(0, $entries); + } + + public function testDeleteTagsByLabelNotFound() + { + $this->client->request('DELETE', '/api/tags/label.json', ['tags' => 'does not exist']); + + $this->assertEquals(404, $this->client->getResponse()->getStatusCode()); + } + public function testGetVersion() { $this->client->request('GET', '/api/version'); -- cgit v1.2.3 From a7e2218e253138ed53e18b4775dce291c78246c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 15 Apr 2016 13:42:13 +0200 Subject: Add test and fix migration --- .../CoreBundle/Controller/EntryControllerTest.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 5c739c78..3b54f057 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -698,4 +698,22 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->submit($form, $data); $this->assertCount(2, $crawler->filter('div[class=entry]')); } + + public function testCache() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneByUser($this->getLoggedInUserId()); + + $client->request('GET', '/share/'.$content->getUuid()); + $this->assertContains('max-age=25200, public', $client->getResponse()->headers->get('cache-control')); + $this->assertNotContains('no-cache', $client->getResponse()->headers->get('cache-control')); + + $client->request('GET', '/view/'.$content->getId()); + $this->assertContains('no-cache', $client->getResponse()->headers->get('cache-control')); + } } -- cgit v1.2.3 From f1be7af446052c6fed7033664c6c6350f558961b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 23 Aug 2016 16:49:12 +0200 Subject: Change share entry behavior --- tests/Wallabag/CoreBundle/Command/InstallCommandTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php index c0133af4..07ff2772 100644 --- a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php @@ -33,7 +33,7 @@ class InstallCommandTest extends WallabagCoreTestCase } /** - * Ensure next tests will have a clean database + * Ensure next tests will have a clean database. */ public static function tearDownAfterClass() { -- cgit v1.2.3 From 8541b3c4fdf35788129483060499fef50818222c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Wed, 24 Aug 2016 10:28:43 +0200 Subject: Add simple test --- tests/Wallabag/CoreBundle/Command/InstallCommandTest.php | 2 +- .../CoreBundle/Controller/SecurityControllerTest.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php index c0133af4..07ff2772 100644 --- a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php @@ -33,7 +33,7 @@ class InstallCommandTest extends WallabagCoreTestCase } /** - * Ensure next tests will have a clean database + * Ensure next tests will have a clean database. */ public static function tearDownAfterClass() { diff --git a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php index 03355f5a..08f4676e 100644 --- a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php @@ -69,4 +69,19 @@ class SecurityControllerTest extends WallabagCoreTestCase $this->assertTrue($user->isTrustedComputer('ABCDEF')); $this->assertFalse($user->isTrustedComputer('FEDCBA')); } + + public function testEnabledRegistration() + { + $client = $this->getClient(); + + if (!$client->getContainer()->getParameter('fosuser_registration')) { + $this->markTestSkipped('fosuser_registration is not enabled.'); + + return; + } + + $client->followRedirects(); + $crawler = $client->request('GET', '/register'); + $this->assertContains('registration.submit', $crawler->filter('body')->extract(['_text'])[0]); + } } -- cgit v1.2.3 From eddda878a0ec375fa738e3228a72dd01b23e0fab Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 24 Aug 2016 22:29:36 +0200 Subject: Update test and some cleanup --- .../CoreBundle/Controller/EntryControllerTest.php | 27 +++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 3b54f057..f9ac28c3 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -709,11 +709,36 @@ class EntryControllerTest extends WallabagCoreTestCase ->getRepository('WallabagCoreBundle:Entry') ->findOneByUser($this->getLoggedInUserId()); + // no uuid $client->request('GET', '/share/'.$content->getUuid()); - $this->assertContains('max-age=25200, public', $client->getResponse()->headers->get('cache-control')); + $this->assertEquals(404, $client->getResponse()->getStatusCode()); + + // generating the uuid + $client->request('GET', '/share/'.$content->getId()); + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + // follow link with uuid + $crawler = $client->followRedirect(); + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control')); + $this->assertContains('public', $client->getResponse()->headers->get('cache-control')); + $this->assertContains('s-maxage=25200', $client->getResponse()->headers->get('cache-control')); $this->assertNotContains('no-cache', $client->getResponse()->headers->get('cache-control')); + // sharing is now disabled + $client->getContainer()->get('craue_config')->set('share_public', 0); + $client->request('GET', '/share/'.$content->getUuid()); + $this->assertEquals(404, $client->getResponse()->getStatusCode()); + $client->request('GET', '/view/'.$content->getId()); $this->assertContains('no-cache', $client->getResponse()->headers->get('cache-control')); + + // removing the share + $client->request('GET', '/share/delete/'.$content->getId()); + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + // share is now disable + $client->request('GET', '/share/'.$content->getUuid()); + $this->assertEquals(404, $client->getResponse()->getStatusCode()); } } -- cgit v1.2.3 From d5d161215390ca6465d246a77b485ab64efa842e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 26 Aug 2016 21:01:56 +0200 Subject: Add tests for untagged entries --- tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index f9ac28c3..a74c17d9 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -236,6 +236,16 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertEquals(200, $client->getResponse()->getStatusCode()); } + public function testUntagged() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $client->request('GET', '/untagged/list'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + } + public function testStarred() { $this->logInAs('admin'); -- cgit v1.2.3 From 03e3753f6bd36f12c0757c76b49b683c49de48ae Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 1 Sep 2016 08:00:30 +0200 Subject: Add Readability import Based on the JSON export instead of the API (which will be shutting down by the September 30, 2016) --- .../ImportBundle/fixtures/readability.json | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/Wallabag/ImportBundle/fixtures/readability.json (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ImportBundle/fixtures/readability.json b/tests/Wallabag/ImportBundle/fixtures/readability.json new file mode 100644 index 00000000..34379905 --- /dev/null +++ b/tests/Wallabag/ImportBundle/fixtures/readability.json @@ -0,0 +1,25 @@ +{ + "bookmarks": [ + { + "article__excerpt": "When Twitter started it had so much promise to change the way we communicate. But now it has been ruined by the amount of garbage and hate we have to wade through. It’s like that polluted…", + "favorite": false, + "date_archived": null, + "article__url": "https://venngage.com/blog/hashtags-are-worthless/", + "date_added": "2016-08-25T12:05:00", + "date_favorited": null, + "article__title": "We Looked At 167,943 Tweets & Found Out Hashtags Are Worthless", + "archive": false + }, + { + "article__excerpt": "TL;DR: Re-use your DOM elements and remove the ones that are far away from the viewport. Use placeholders to account for delayed data. Here’s a demo and the code for the infinite…", + "favorite": false, + "date_archived": "2016-08-26T12:21:54", + "article__url": "https://developers.google.com/web/updates/2016/07/infinite-scroller?imm_mid=0e6839&cmp=em-webops-na-na-newsltr_20160805", + "date_added": "2016-08-06T05:35:26", + "date_favorited": null, + "article__title": "Complexities of an infinite scroller | Web Updates", + "archive": true + } + ], + "recommendations": [] +} -- cgit v1.2.3 From ca15aaac188a1ad4b08595d3dbb06634320183ed Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 1 Sep 2016 09:36:11 +0200 Subject: Fix import count tests --- tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php index 96b5300b..d869cdf9 100644 --- a/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php @@ -24,6 +24,6 @@ class ImportControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/import/'); $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->assertEquals(3, $crawler->filter('blockquote')->count()); + $this->assertEquals(4, $crawler->filter('blockquote')->count()); } } -- cgit v1.2.3 From a1a107705948c724aca7326f8550c336a25a6364 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 1 Sep 2016 09:57:02 +0200 Subject: Add tests on ReadabilityImport --- .../Controller/ReadabilityControllerTest.php | 122 +++++++++++++++++ .../ImportBundle/Import/ReadabilityImportTest.php | 150 +++++++++++++++++++++ .../ImportBundle/fixtures/readability-read.json | 25 ++++ 3 files changed, 297 insertions(+) create mode 100644 tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php create mode 100644 tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php create mode 100644 tests/Wallabag/ImportBundle/fixtures/readability-read.json (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php new file mode 100644 index 00000000..92cf4bfc --- /dev/null +++ b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php @@ -0,0 +1,122 @@ +logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/readability'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + } + + public function testImportReadabilityWithFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/readability'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/readability.json', 'readability.json'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId( + 'https://venngage.com/blog/hashtags-are-worthless/', + $this->getLoggedInUserId() + ); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + } + + public function testImportReadabilityWithFileAndMarkAllAsRead() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/readability'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/readability-read.json', 'readability-read.json'); + + $data = [ + 'upload_import_file[file]' => $file, + 'upload_import_file[mark_as_read]' => 1, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $content1 = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId( + 'https://blog.travis-ci.com/2016-07-28-what-we-learned-from-analyzing-2-million-travis-builds/', + $this->getLoggedInUserId() + ); + + $this->assertTrue($content1->isArchived()); + + $content2 = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId( + 'https://facebook.github.io/graphql/', + $this->getLoggedInUserId() + ); + + $this->assertTrue($content2->isArchived()); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + } + + public function testImportReadabilityWithEmptyFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/readability'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.failed', $body[0]); + } +} diff --git a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php new file mode 100644 index 00000000..706d707b --- /dev/null +++ b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php @@ -0,0 +1,150 @@ +user = new User(); + + $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') + ->disableOriginalConstructor() + ->getMock(); + + $wallabag = new ReadabilityImport($this->em, $this->contentProxy); + + $this->logHandler = new TestHandler(); + $logger = new Logger('test', [$this->logHandler]); + $wallabag->setLogger($logger); + + if (false === $unsetUser) { + $wallabag->setUser($this->user); + } + + return $wallabag; + } + + public function testInit() + { + $readabilityImport = $this->getReadabilityImport(); + + $this->assertEquals('Readability', $readabilityImport->getName()); + $this->assertNotEmpty($readabilityImport->getUrl()); + $this->assertEquals('import.readability.description', $readabilityImport->getDescription()); + } + + public function testImport() + { + $readabilityImport = $this->getReadabilityImport(); + $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->exactly(2)) + ->method('findByUrlAndUserId') + ->will($this->onConsecutiveCalls(false, true)); + + $this->em + ->expects($this->any()) + ->method('getRepository') + ->willReturn($entryRepo); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->exactly(1)) + ->method('updateEntry') + ->willReturn($entry); + + $res = $readabilityImport->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 1, 'imported' => 1], $readabilityImport->getSummary()); + } + + public function testImportAndMarkAllAsRead() + { + $readabilityImport = $this->getReadabilityImport(); + $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability-read.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->exactly(2)) + ->method('findByUrlAndUserId') + ->will($this->onConsecutiveCalls(false, false)); + + $this->em + ->expects($this->any()) + ->method('getRepository') + ->willReturn($entryRepo); + + $this->contentProxy + ->expects($this->exactly(2)) + ->method('updateEntry') + ->willReturn(new Entry($this->user)); + + // check that every entry persisted are archived + $this->em + ->expects($this->any()) + ->method('persist') + ->with($this->callback(function ($persistedEntry) { + return $persistedEntry->isArchived(); + })); + + $res = $readabilityImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + + $this->assertEquals(['skipped' => 0, 'imported' => 2], $readabilityImport->getSummary()); + } + + public function testImportBadFile() + { + $readabilityImport = $this->getReadabilityImport(); + $readabilityImport->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx'); + + $res = $readabilityImport->import(); + + $this->assertFalse($res); + + $records = $this->logHandler->getRecords(); + $this->assertContains('ReadabilityImport: unable to read file', $records[0]['message']); + $this->assertEquals('ERROR', $records[0]['level_name']); + } + + public function testImportUserNotDefined() + { + $readabilityImport = $this->getReadabilityImport(true); + $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + + $res = $readabilityImport->import(); + + $this->assertFalse($res); + + $records = $this->logHandler->getRecords(); + $this->assertContains('ReadabilityImport: user is not defined', $records[0]['message']); + $this->assertEquals('ERROR', $records[0]['level_name']); + } +} diff --git a/tests/Wallabag/ImportBundle/fixtures/readability-read.json b/tests/Wallabag/ImportBundle/fixtures/readability-read.json new file mode 100644 index 00000000..c60767dc --- /dev/null +++ b/tests/Wallabag/ImportBundle/fixtures/readability-read.json @@ -0,0 +1,25 @@ +{ + "bookmarks": [ + { + "article__excerpt": "This is a guest post from Moritz Beller from the Delft University of Technology in The Netherlands. His team produced amazing research on several million Travis CI builds, creating invaluable…", + "favorite": false, + "date_archived": "2016-08-02T06:49:30", + "article__url": "https://blog.travis-ci.com/2016-07-28-what-we-learned-from-analyzing-2-million-travis-builds/", + "date_added": "2016-08-01T05:24:16", + "date_favorited": null, + "article__title": "Travis", + "archive": true + }, + { + "article__excerpt": "The GraphQL Type system describes the capabilities of a GraphQL server and is used to determine if a query is valid. The type system also describes the input types of query variables to determine if…", + "favorite": false, + "date_archived": "2016-07-19T06:48:31", + "article__url": "https://facebook.github.io/graphql/", + "date_added": "2016-06-24T17:50:16", + "date_favorited": null, + "article__title": "GraphQL", + "archive": true + } + ], + "recommendations": [] +} -- cgit v1.2.3 From 9401696fe4ac78863fa5318de9cd9765c3a139bf Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 8 Sep 2016 16:38:08 +0200 Subject: Export dates from entries --- .../CoreBundle/Controller/ExportControllerTest.php | 6 ++- .../ImportBundle/fixtures/wallabag-v2-read.json | 4 ++ .../ImportBundle/fixtures/wallabag-v2.json | 48 ++++++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php index b22156c3..47b86117 100644 --- a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php @@ -168,7 +168,7 @@ class ExportControllerTest extends WallabagCoreTestCase $this->assertGreaterThan(1, $csv); // +1 for title line $this->assertEquals(count($contentInDB) + 1, count($csv)); - $this->assertEquals('Title;URL;Content;Tags;"MIME Type";Language', $csv[0]); + $this->assertEquals('Title;URL;Content;Tags;"MIME Type";Language;"Creation date"', $csv[0]); } public function testJsonExport() @@ -210,6 +210,8 @@ class ExportControllerTest extends WallabagCoreTestCase $this->assertArrayHasKey('reading_time', $content[0]); $this->assertArrayHasKey('domain_name', $content[0]); $this->assertArrayHasKey('tags', $content[0]); + $this->assertArrayHasKey('created_at', $content[0]); + $this->assertArrayHasKey('updated_at', $content[0]); } public function testXmlExport() @@ -247,5 +249,7 @@ class ExportControllerTest extends WallabagCoreTestCase $this->assertNotEmpty('url', (string) $content->entry[0]->url); $this->assertNotEmpty('content', (string) $content->entry[0]->content); $this->assertNotEmpty('domain_name', (string) $content->entry[0]->domain_name); + $this->assertNotEmpty('created_at', (string) $content->entry[0]->created_at); + $this->assertNotEmpty('updated_at', (string) $content->entry[0]->updated_at); } } diff --git a/tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json b/tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json index 3fa0bddf..d8609280 100644 --- a/tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json +++ b/tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json @@ -4,6 +4,8 @@ "title": "Wikimedia Foundation removes The Diary of Anne Frank due to copyright law requirements « Wikimedia blog", "url": "https://blog.wikimedia.org/2016/02/10/anne-frank-diary-removal/", "is_archived": true, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": false, "content": "

\"AnneFrankSchoolPhoto\"
Anne Frank in 1940. Photo by Collectie Anne Frank Stichting Amsterdam, public domain.

\n

Today, in an unfortunate example of the overreach of the United States’ current copyright law, the Wikimedia Foundation removed the Dutch-language text of The Diary of a Young Girl—more commonly known in English as the Diary of Anne Frank—from Wikisource.[1]

\n

We took this action to comply with the United States’ Digital Millennium Copyright Act (DMCA), as we believe the diary is still under US copyright protection under the law as it is currently written. Nevertheless, our removal serves as an excellent example of why the law should be changed to prevent repeated extensions of copyright terms, an issue that has plagued our communities for years.

\n

What prompted us to remove the diary?

\n

The deletion was required because the Foundation is under the jurisdiction of US law and is therefore subject to the DMCA, specifically title 17, chapter 5, section 512 of the United States Code. As we noted in 2013, “The location of the servers, incorporation, and headquarters are just three of many factors that establish US jurisdiction … if infringing content is linked to or embedded in Wikimedia projects, then  the Foundation may still be subject to liability for such use—either as a direct or contributory infringer.

\n

Based on email discussions sent to the Wikimedia Foundation at legal[at]wikimedia.org, we determined that the Wikimedia Foundation had either “actual knowledge” (i in the statute quoted below) or what is commonly called “red flag knowledge” (ii in the statute quoted below) that the Anne Frank text was hosted on Wikisource and was under copyright. The statute section states that a service provider is only protected by the DMCA when it:

\n

(i) does not have actual knowledge that the material or an activity using the material on the system or network is infringing;

\n

(ii) in the absence of such actual knowledge, is not aware of facts or circumstances from which infringing activity is apparent; or

\n

(The rest applies when we get a proper DMCA takedown notice.)

\n

Of particular concern, the US’ 9th Circuit Court of Appeals stated in their ruling for UMG Recordings, Inc. v. Shelter Capital Partners LLC that in circumstances where a hosting provider (like the Wikimedia Foundation) is informed by a third party (like an unrelated user) about infringing copyrighted content, that would likely constitute either actual or red flag knowledge under the DMCA.

\n

We believe, based on the detail and specificity contained in the emails, that we received that we had actual knowledge sufficient for the DMCA to require us to perform a takedown even in the absence of a demand letter.

\n

How is the diary still copyrighted?

\n

You may wonder why or how the Anne Frank text is copyrighted at all, as Anne Frank died in February 1945. With 70 years having passed since her death, the text may have passed into public domain in the Netherlands on January 1, 2016, where it was first published, although there is still some dispute about this.

\n

However, in the United States, the Anne Frank original text will be under copyright until 2042. This is the result of several factors coming together, and the English-language Wikipedia has actually covered this issue with a multi-part test on its non-US copyrights content guideline.

\n

In short, there are three major laws that together make the diary still copyrighted:

\n
  1. In general, the U.S. copyright for works published before 1978 is 95 years from date of publication. This came about because copyrights in the U.S. were originally for 28 years, with the ability to then extend that for a second 28 years (making a total of 56). Starting with the 1976 Copyright Act and extending to several more acts, the renewal became automatic and was extended. Today, the total term of works published before 1978 is 95 years from date of publication.
  2. \n
  3. Foreign works of countries that are treaty partners to the United States are covered as if they were US works.
  4. \n
  5. Even if a country was not a treaty partner under copyright law at the time of a publication, the 1994 Uruguay Round Agreements Act (URAA) restored copyright to works that:\n
    • had been published in a foreign country
    • \n
    • were still under copyright in that country in 1996
    • \n
    • and would have had U.S. copyright but for the fact they were published abroad.
    • \n
  6. \n
\n

Court challenges to the URAA have all failed, with the most notable (Golan v. Holder) resulting in a Supreme Court ruling that upheld the URAA.

\n

What that means for Anne Frank’s diary is unfortunately simple: no matter how it wound up in the United States and regardless of what formal copyright notices they used, the US grants it copyright until the year 2042, or 95 years after its original publication in 1947.

\n

Under current copyright law, this remains true regardless of its copyright status anywhere else in the world and regardless of whether it may have been in the public domain in the United States in the past.

\n

Jacob Rogers, Legal Counsel*
Wikimedia Foundation

\n

*Special thanks to Anisha Mangalick, Legal Fellow, for her assistance in this matter.

\n

[1] The diary text was originally located at https://nl.wikisource.org/wiki/Het_Achterhuis_(Anne_Frank).

\n

This article was edited to clarify that it is not just the location of the Wikimedia Foundation’s servers that determine whether we fall in US jurisdiction.

\n\t\t\t\t\t\t\t\t\t\t\t", "mimetype": "text/html", @@ -17,6 +19,8 @@ "title": "Tails - Tails 2.0.1 is out", "url": "https://tails.boum.org/news/version_2.0.1/index.en.html", "is_archived": false, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": false, "content": "
\n

This release fixes numerous security issues. All users must upgrade as soon as possible.

\n\n

New features

\n
  • \n

    Tails now uses the GNOME Shell desktop environment, in its Classic mode. GNOME Shell provides a modern, simple, and actively developed desktop environment. The Classic mode keeps the traditional Applications, Places menu, and windows list. Accessibility and non-Latin input sources are also better integrated.

    \n

    To find your way around, read our introduction to GNOME and the Tails desktop.

    \n\n\n
    The desktop and Applications menu
    \"Tails
    \n\n
    The activities overview
    \"Tails
  • \n

Upgrades and changes

\n
  • \n

    Debian 8 upgrades most included software, for example:

    \n
    • Many core GNOME utilities from 3.4 to 3.14: Files, Disks, Videos, etc.
    • \n
    • LibreOffice from 3.5 to 4.3
    • \n
    • PiTiVi from 0.15 to 0.93
    • \n
    • Git from 1.7.10 to 2.1.4
    • \n
    • Poedit from 1.5.4 to 1.6.10
    • \n
    • Liferea from 1.8.6 to 1.10
    • \n
  • \n
  • \n

    Update Tor Browser to 5.5 (based on Firefox 38.6.0 ESR):

    \n
    • Add Japanese support.
    • \n
  • \n
  • \n

    Remove the Windows camouflage which is currently broken in GNOME Shell. We started working on adding it back but your help is needed!

    \n
  • \n
  • \n

    Change to systemd as init system and use it to:

    \n
    • Sandbox many services using Linux namespaces and make them harder to exploit.
    • \n
    • Make the launching of Tor and the memory wipe on shutdown more robust.
    • \n
    • Sanitize our code base by replacing many custom scripts.
    • \n
  • \n
  • \n

    Update most firmware packages which might improve hardware compatibility.

    \n
  • \n
  • \n

    Notify the user if Tails is running from a non-free virtualization software.

    \n
  • \n
  • \n

    Remove Claws Mail, replaced by Icedove, a rebranded version of Mozilla Thunderbird.

    \n
  • \n

Fixed problems

\n
  • \n

    HiDPI displays are better supported. (#8659)

    \n
  • \n
  • \n

    Remove the option to open a download with an external application in Tor Browser as this is usually impossible due to the AppArmor confinement. (#9285)

    \n
  • \n
  • \n

    Close Vidalia before restarting Tor.

    \n
  • \n
  • \n

    Allow Videos to access the DVD drive. (#10455, #9990)

    \n
  • \n
  • \n

    Allow configuring printers without administration password. (#8443)

    \n
  • \n
\n

See the current list of known issues.

\n

Go to the download or upgrade page.

\n

If your Tails does not boot after an automatic upgrade, please upgrade your Tails manually.

\n

The next Tails release is scheduled for March 08.

\n

Have a look at our roadmap to see where we are heading to.

\n

We need your help and there are many ways to contribute to Tails (donating is only one of them). Come talk to us!

\n
\n

Tags: announce

\n

Pages linking to this one: inc/stable i386 release notes security/Numerous security holes in 2.0

\n

Last edited Sat 13 Feb 2016 02:23:58 PM CET

\n
", "mimetype": "text/html", diff --git a/tests/Wallabag/ImportBundle/fixtures/wallabag-v2.json b/tests/Wallabag/ImportBundle/fixtures/wallabag-v2.json index 37c59668..efa8faf2 100644 --- a/tests/Wallabag/ImportBundle/fixtures/wallabag-v2.json +++ b/tests/Wallabag/ImportBundle/fixtures/wallabag-v2.json @@ -4,6 +4,8 @@ "title": "Site d'information français d'actualités indépendant et participatif en ligne | Mediapart", "url": "https://www.mediapart.fr/", "is_archived": false, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": false, "content": "
Édition CAMédia\n

Deux nouvelles éditions pour débattre dans le club sur la laïcité et sur la démocratie

\n

18 janv. 2016 | Par

\n

CAMédia après un échange sur « l'éthique du débat » a lancé deux discussions , l'une sur le thème de la laïcité, l'autre ( encore en cours) sur celui de la démocratie. Nous sommes heureux de pouvoir signaler la création de deux nouvelles éditions participatives sur ces thèmes. Nous vous invitons à les lire et à participer à leurs débats.

\n
\n

De l'importance de rêver, éloge du merveilleux

\n

17 janv. 2016 | Par

\n

Je parlerai ici des rêves comme moteur de vie, de ces rêves qui vous rattachent et vous font espérer à ce qu’il y a de plus humain dans l’homme, même au milieu de la plus noire des détresses.

\n
\n

Fin(s) d'une toute-puissance

\n

18 janv. 2016 | Par

\n

En ce début d’année, je recommande la lecture du dernier ouvrage de Guillaume Duval, La France ne sera jamais plus une grande puissance ? Tant mieux !

\n
\n

L’Allier, département de destruction massive du tissu culturel

\n

18 janv. 2016 | Par

\n

Les temps sont durs pour les petites structures, les associations culturelles qui, de bourgades en villages, travaillent au cœur des régions. Leurs subventions sont souvent revues à la baisse. Le département de l’Allier les a carrément supprimées. Pour favoriser « l’événementiel ».

\n
Édition Les invités de Mediapart\n

La démocratie déjà attaquée par la coopération réglementaire transatlantique

\n

18 janv. 2016 | Par

\n

Lora Verheecke et David Lundy travaillent pour Corporate Europe Observatory, une ONG basée à Bruxelles qui enquête sur le pouvoir des lobbies des grandes entreprises sur la politique de l’Union européenne. Ils révèlent que depuis 25 ans le projet de « coopération réglementaire » mené par l’Union européenne et les États-Unis a été dominé par les grandes entreprises. ET que le TTIP cherche à entériner ce projet.

\n
\n

2016, une année test pour Jacob Zuma et son gouvernement

\n

18 janv. 2016 | Par

\n

Les turbulences de l’an passé ont toutes les chances de continuer à troubler le climat politique et social de l’Afrique du Sud en 2016. La situation exige des changements profonds dans la conduite des affaires du pays. Jacob Zuma tout en admettant la nécessité de ces changements, est-il l’homme de la situation ? Son gouvernement répondra-t-il aux attentes des citoyens sud-africains ?

\n
\n

Un mal fou (janvier 2016)

\n

14 janv. 2016 | Par

\n

J’ai une fringale d’aventure, d’aventures à venir. J’ai la fringale de la fringale des aventures et soudain, rupture. Je n’y arrive plus, tout est bloqué, tout empêché. Faut dire que depuis un an environ, tout est devenu plus compliqué. Ecrire va de moins en moins de soi.

\n
\n

Redoublement : le changement à bas bruit ?

\n

17 janv. 2016 | Par

\n

S’il est une caractéristique de la forme scolaire française bien établie dans la culture des personnels, des élèves et des parents, c’est bien le redoublement, censé sanctionner des résultats insuffisants pour envisager le passage dans la classe supérieure. Or, en ce domaine, l’évolution est nette.

\n
\n

Samedi-sciences (196): des chasseurs de mammouths en Arctique il y a 45 000 ans

\n

16 janv. 2016 | Par Michel de Pracontal

\n

Les restes d’un mammouth retrouvés en Arctique sibérien, datés de 45 000 ans, portent les traces de blessures infligées par des chasseurs humains. Les scientifiques pensaient jusqu’ici que notre espèce ne s’était pas aventurée dans cette région glaciale il y a plus de 30 000 ou 35 0000 ans. En réalité, des hommes ont réussi à survivre en Arctique au moins 10 000 ans plus tôt que l’on croyait.

\n
\n

De la démocratie, du citoyen et de l'éthique

\n

14 janv. 2016 | Par

\n

Trois ouvrages sont parus au Seuil, qui font état de la nécessité d’intégrer le citoyen dans la gouvernance de la nation. Non pas à titre consultatif mais doté d’un pouvoir délibératif pour constituer une contre-force face aux clans politico-financiers qui dominent la vie publique.

\n
", "mimetype": "text/html", @@ -21,6 +23,8 @@ "title": "Réfugiés: l'UE va créer 100 000 places d'accueil dans les Balkans", "url": "http://www.liberation.fr/planete/2015/10/26/refugies-l-ue-va-creer-100-000-places-d-accueil-dans-les-balkans_1408867", "is_archived": false, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": false, "content": "

Pour un sommet sur les réfugiés qui devait se concentrer sur des «mesures opérationnelles immédiates» dans les Balkans, la réunion, dimanche à Bruxelles, de 11 chefs d’Etat et de gouvernement, dont 8 Européens, a été agitée. Dès leur arrivée, Viktor Orbán (Hongrie) et Aléxis Tsípras (Grèce) se sont jeté des anathèmes. Le Premier ministre grec a dénoncé l’attitude «not in my backyard» (pas de ça chez moi) de certains Etats européens, alors que son pays est montré du doigt par d’autres dirigeants, dont Orbán : ils reprochent à la Grèce de ne pas suffisamment contrôler ses frontières avec la Turquie et ne pas montrer assez de zèle dans l’enregistrement des demandeurs d’asile.

\n

Le sommet, convoqué par la Commission européenne, sur suggestion de l’Allemagne, aura au moins permis à ces 11 Etats – Autriche, Bulgarie, Croatie, Allemagne, Grèce, Hongrie, Roumanie, Slovénie côté européen, et 3 pays «non UE», Albanie, Macédoine et Serbie – de discuter ensemble.

\n

400 policiers européens en Slovénie

\n

L’objectif, rappelé par Angela Merkel, était de trouver une «réponse coordonnée» à la crise des réfugiés. Quelques mesures ont été annoncées : 100 000 places d’accueil seront créées, dont 50 000 en Grèce, et le reste le long de la route des Balkans. 400 officiers de police de pays européens partiront en Slovénie, actuellement submergée, pour aider au contrôle des frontières. Frontex, l’agence européenne de surveillance des frontières, s’impliquera aux frontières gréco-macédonienne et gréco-albanaise pour des contrôles et identifications.

\n

Ce sommet est intervenu dans un contexte de fortes tensions, marqué par des fermetures de frontières bloquant les réfugiés dans des zones tampon. Ces obstacles ont été partiellement levés ces derniers jours, les autorités tentant d’organiser un «corridor» informel vers l’Allemagne, qui pourtant durcit sa politique d’accueil et souhaite désormais ralentir le flux. Mais la situation des réfugiés est catastrophique. L’ONG Human Rights Watch craint que des réfugiés ne meurent dans les Balkans. Des groupes de centaines, voire de milliers de personnes, bloqués près des postes-frontières, se retrouvent dans des conditions humanitaires intenables.

\n

Depuis mi-septembre, 250 000 personnes ont traversé les Balkans. En une semaine, la Slovénie a vu 60 000 réfugiés fouler le sol de son territoire. Dimanche, 15 000 personnes ont transité en Slovénie.

\n

Des zones tampon

\n

L’enjeu principal du sommet, aux yeux de nombreux Etats de l’Union européenne, était aussi que les pays des Balkans «prennent leur part» face à la crise : qu’ils accueillent et enregistrent davantage de réfugiés. Ces Etats craignent que l’Autriche ou l’Allemagne ne ferment leurs frontières et fassent de leurs pays des «zones tampon», comme s’en inquiétait Boyko Borissov, Premier ministre bulgare.

\n

« Aujourd’hui, plusieurs Etats du nord de l’Europe veulent que l’on enregistre les migrants puis que l’on détermine leur éligibilité au statut de réfugié, explique Marc Pierini, du think tank Carnegie Europe. La difficulté, c’est que les gens sont en mouvement. Pour le faire, il faut se poser quelque part. La crainte des pays intermédiaires, donc ceux des Balkans, est qu’on enregistre ces personnes sur leur territoire et qu’ils soient contraints de rester sur leur sol. Donc les pays des Balkans ne sont pas désireux d’accueillir ces réfugiés et ces derniers veulent avancer.»

\n

Le sommet a élaboré quelques principes. L’idée générale est de rendre effective la «logique de hotspot» : un enregistrement des demandeurs d’asile à leur point d’entrée dans l’Union européenne, suivi de l’expulsion de ceux qui ne correspondraient pas aux critères de la Convention de Genève, et la répartition des autres, via le mécanisme de relocalisation.

\n

Dans ce cadre, l’enregistrement des demandeurs d’asile est un élément clé. «Pas d’enregistrement, pas de droit», a prévenu le président de la Commission européenne, Jean-Claude Juncker, dimanche soir. Les Etats ont tenu à rappeler que les migrants qui refusent de demander l’asile à la frontière peuvent se voir refuser l’entrée dans un pays.

\n

Et les Etats «décourageront les mouvements de réfugiés» de frontière en frontière. La politique consistant à laisser passer les migrants vers un autre pays est officiellement jugée «inacceptable».

\n

Se jeter dans la gueule du loup

\n

Voilà pour la théorie. En pratique, la relocalisation ne devrait concerner que 160 000 réfugiés en deux ans, alors que près de 700 000 personnes sont arrivées en Europe depuis le début de l’année. De plus, les Etats ne jouent pas le jeu. La semaine passée, seules 854 places de relocalisation avaient été proposées.

\n

Dans ce contexte, il est probable que les Etats des Balkans ne s’impliqueront pas outre mesure dans les solutions proposées, craignant de devoir «garder» les réfugiés alors que l’Union européenne tarde à mettre en œuvre leur répartition.

\n

Quant aux réfugiés, ils préfèrent traverser les frontières par eux-mêmes, plutôt que de se jeter dans ces «hotspots», considérés comme la gueule du loup.

\nCédric Vallet", "mimetype": "", @@ -34,6 +38,8 @@ "title": "No title found", "url": "http://news.nationalgeographic.com/2016/02/160211-albatrosses-mothers-babies-animals-science/&sf20739758=1", "is_archived": false, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": true, "content": "Oh, what a shame, no content", "mimetype": "", @@ -44,6 +50,8 @@ }, { "is_archived": 0, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 612, "title": "Échecs", @@ -58,6 +66,8 @@ }, { "is_archived": 0, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 608, "title": "90% des dossiers médicaux des Coréens du sud vendus à des entreprises privées - ZATAZ", @@ -73,6 +83,8 @@ }, { "is_archived": 0, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 606, "title": "Mass Surveillance As Art", @@ -87,6 +99,8 @@ }, { "is_archived": 0, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 605, "title": "What David Cameron did to the pig, his party is now doing to the country", @@ -102,6 +116,8 @@ }, { "is_archived": 1, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 604, "title": "CLICK HERE to support 2016 CES Winner, Revolutionary Auto-Tracking Robot", @@ -116,6 +132,8 @@ }, { "is_archived": 0, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 1, "id": 603, "title": "No title found", @@ -129,6 +147,8 @@ }, { "is_archived": 1, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 602, "title": "Présentation d'Arduino - Tuto Arduino - Le blog d'Eskimon", @@ -144,6 +164,8 @@ }, { "is_archived": 1, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 543, "title": "Lenovo ThinkPad X1 Carbon Ultrabook Review", @@ -159,6 +181,8 @@ }, { "is_archived": 0, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 541, "title": "Visitons le Château de Landsberg !", @@ -174,6 +198,8 @@ }, { "is_archived": 1, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 454, "title": "Contrer les stéréotypes par les livres : “C'est dès l'enfance qu'ils se construisent”", @@ -189,6 +215,8 @@ }, { "is_archived": 1, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 99, "title": "[ROM][6.0.1][Layers][N5] TipsyOS official builds {UBER TCs}", @@ -204,6 +232,8 @@ }, { "is_archived": 0, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 98, "title": "Top 15 Podcasts All Web Developers Should Follow - Envato Tuts+ Code Article", @@ -218,6 +248,8 @@ }, { "is_archived": 1, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 97, "title": "University of Mississippi", @@ -232,6 +264,8 @@ }, { "is_archived": 1, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 96, "title": "FinnChristiansen.de Jetzt Dank Let’s Encrypt Per HTTPS Erreichbar", @@ -246,6 +280,8 @@ }, { "is_archived": 1, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 82, "title": "Le développeur et l'ingénierie logicielle", @@ -259,6 +295,8 @@ }, { "is_archived": 1, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 78, "title": "The Role of Methylation in Gene Expression", @@ -273,6 +311,8 @@ }, { "is_archived": 1, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 53, "title": "E-Mail-Adresse kostenlos, FreeMail, De-Mail & Nachrichten", @@ -287,6 +327,8 @@ }, { "is_archived": 1, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 48, "title": "OpenSSH Server on Arch Linux | DominicM test", @@ -302,6 +344,8 @@ }, { "is_archived": 1, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 39, "title": "Site Moved | Site Help", @@ -316,6 +360,8 @@ }, { "is_archived": 1, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 38, "title": "#Maroc : le stylo anti-pédophiles EAGLE d’AMESYS est moins bien configuré que les faux-lowers Twitter du roi Mohammed VI", @@ -331,6 +377,8 @@ }, { "is_archived": 1, + "created_at": "2016-09-08T11:55:58+0200", + "updated_at": "2016-09-08T11:57:16+0200", "is_starred": 0, "id": 3, "title": "Simple Cloud Infrastructure for Developers", -- cgit v1.2.3 From 56c778b4152a1b886353933276ee3626e4e8c004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 15 Jan 2016 08:24:32 +0100 Subject: 1st draft for rabbitMQ --- tests/Wallabag/ImportBundle/Import/PocketImportTest.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index 8534e1c8..a0f943ee 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php @@ -27,8 +27,9 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase protected $em; protected $contentProxy; protected $logHandler; + protected $producer; - private function getPocketImport($consumerKey = 'ConsumerKey') + private function getPocketImport($consumerKey = 'ConsumerKey', $rabbitMQ = false) { $this->user = new User(); @@ -65,11 +66,17 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase ->with('pocket_consumer_key') ->willReturn($consumerKey); + $this->producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') + ->disableOriginalConstructor() + ->getMock(); + $pocket = new PocketImportMock( $this->tokenStorage, $this->em, $this->contentProxy, - $config + $config, + $rabbitMQ, + $this->producer ); $this->logHandler = new TestHandler(); -- cgit v1.2.3 From 40d2a29443df8ef6fdf1f2d09b5ba8808543c245 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 15 Feb 2016 21:30:55 +0100 Subject: Replace RabbitMQ injection with CraueConfiguration --- tests/Wallabag/ImportBundle/Import/PocketImportTest.php | 1 - 1 file changed, 1 deletion(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index a0f943ee..5bf47d96 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php @@ -75,7 +75,6 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase $this->em, $this->contentProxy, $config, - $rabbitMQ, $this->producer ); -- cgit v1.2.3 From ef75e1220ebb76a8df019d946460ad612759f0bb Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 3 Sep 2016 17:36:57 +0200 Subject: Send every imported item to the queue Instead of queing real Entry to process, we queue all the item to import from Pocket in a raw format. Then, the worker retrieve that information, find / create the entry and save it. --- .../ImportBundle/Import/PocketImportTest.php | 28 +++------------------- 1 file changed, 3 insertions(+), 25 deletions(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index 5bf47d96..d6b9617e 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php @@ -27,32 +27,15 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase protected $em; protected $contentProxy; protected $logHandler; - protected $producer; - private function getPocketImport($consumerKey = 'ConsumerKey', $rabbitMQ = false) + private function getPocketImport($consumerKey = 'ConsumerKey') { $this->user = new User(); - $this->tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface') - ->disableOriginalConstructor() - ->getMock(); - - $token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface') - ->disableOriginalConstructor() - ->getMock(); - $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') ->disableOriginalConstructor() ->getMock(); - $token->expects($this->once()) - ->method('getUser') - ->willReturn($this->user); - - $this->tokenStorage->expects($this->once()) - ->method('getToken') - ->willReturn($token); - $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') ->disableOriginalConstructor() ->getMock(); @@ -66,17 +49,12 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase ->with('pocket_consumer_key') ->willReturn($consumerKey); - $this->producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') - ->disableOriginalConstructor() - ->getMock(); - $pocket = new PocketImportMock( - $this->tokenStorage, $this->em, $this->contentProxy, - $config, - $this->producer + $config ); + $pocket->setUser($this->user); $this->logHandler = new TestHandler(); $logger = new Logger('test', [$this->logHandler]); -- cgit v1.2.3 From 02f64895728fe9aee2c696a627e0bbe27a24faf2 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 5 Sep 2016 07:13:09 +0200 Subject: Retrieve all items from Pocket 5000 by 5000. Also, retrieve newest item first. --- tests/Wallabag/ImportBundle/Import/PocketImportTest.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index d6b9617e..26c6b825 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php @@ -12,14 +12,6 @@ use GuzzleHttp\Stream\Stream; use Monolog\Logger; use Monolog\Handler\TestHandler; -class PocketImportMock extends PocketImport -{ - public function getAccessToken() - { - return $this->accessToken; - } -} - class PocketImportTest extends \PHPUnit_Framework_TestCase { protected $token; @@ -49,7 +41,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase ->with('pocket_consumer_key') ->willReturn($consumerKey); - $pocket = new PocketImportMock( + $pocket = new PocketImport( $this->em, $this->contentProxy, $config -- cgit v1.2.3 From 6d65c0a8b089d3caa6f8e20d7935a9fe2f87d926 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 9 Sep 2016 09:36:07 +0200 Subject: Add ability to define created_at for all import At the moment only Readability & wallabag v2 import allow created_at import. Pocket removed `time_added` field from their API v2 to v3... And wallabag v1 doesn't export that value. --- .../Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php | 7 +++++++ .../Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php | 6 ++++++ .../Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php | 2 ++ 3 files changed, 15 insertions(+) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php index 92cf4bfc..fb39356a 100644 --- a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php @@ -49,6 +49,13 @@ class ReadabilityControllerTest extends WallabagCoreTestCase $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); $this->assertContains('flashes.import.notice.summary', $body[0]); + + $this->assertNotEmpty($content->getMimetype()); + $this->assertNotEmpty($content->getPreviewPicture()); + $this->assertNotEmpty($content->getLanguage()); + $this->assertEquals(0, count($content->getTags())); + $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); + $this->assertEquals('2016-08-25', $content->getCreatedAt()->format('Y-m-d')); } public function testImportReadabilityWithFileAndMarkAllAsRead() diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php index c1025b41..ff1bf6f0 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php @@ -56,6 +56,12 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); $this->assertContains('flashes.import.notice.summary', $body[0]); + + $this->assertEmpty($content->getMimetype()); + $this->assertEmpty($content->getPreviewPicture()); + $this->assertEmpty($content->getLanguage()); + $this->assertEquals(1, count($content->getTags())); + $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); } public function testImportWallabagWithFileAndMarkAllAsRead() diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php index d8d2c8bf..149e88bb 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php @@ -67,6 +67,8 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase $this->assertNotEmpty($content->getPreviewPicture()); $this->assertNotEmpty($content->getLanguage()); $this->assertEquals(2, count($content->getTags())); + $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); + $this->assertEquals('2016-09-08', $content->getCreatedAt()->format('Y-m-d')); } public function testImportWallabagWithEmptyFile() -- cgit v1.2.3 From 13470c3596d0b1490bbf18b39128a05bbb3c7f3e Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 9 Sep 2016 18:02:29 +0200 Subject: Add test for RabbitMQ Also update Symfony deps --- .../Consumer/AMPQ/EntryConsumerTest.php | 225 +++++++++++++++++++++ .../Controller/PocketControllerTest.php | 15 ++ .../Controller/ReadabilityControllerTest.php | 16 ++ .../Controller/WallabagV1ControllerTest.php | 16 ++ .../Controller/WallabagV2ControllerTest.php | 16 ++ .../ImportBundle/Import/PocketImportTest.php | 81 ++++++++ .../ImportBundle/Import/ReadabilityImportTest.php | 40 ++++ .../ImportBundle/Import/WallabagV1ImportTest.php | 40 ++++ .../ImportBundle/Import/WallabagV2ImportTest.php | 36 ++++ 9 files changed, 485 insertions(+) create mode 100644 tests/Wallabag/ImportBundle/Consumer/AMPQ/EntryConsumerTest.php (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ImportBundle/Consumer/AMPQ/EntryConsumerTest.php b/tests/Wallabag/ImportBundle/Consumer/AMPQ/EntryConsumerTest.php new file mode 100644 index 00000000..7141874c --- /dev/null +++ b/tests/Wallabag/ImportBundle/Consumer/AMPQ/EntryConsumerTest.php @@ -0,0 +1,225 @@ +getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $em + ->expects($this->once()) + ->method('flush'); + + $em + ->expects($this->exactly(2)) + ->method('clear'); + + $body = <<<'JSON' +{ + "item_id": "1402935436", + "resolved_id": "1402935436", + "given_url": "http://mashable.com/2016/09/04/leslie-jones-back-on-twitter-after-hack/?utm_campaign=Mash-Prod-RSS-Feedburner-All-Partial&utm_cid=Mash-Prod-RSS-Feedburner-All-Partial", + "given_title": "Leslie Jones is back on Twitter and her comeback tweet rules", + "favorite": "0", + "status": "0", + "time_added": "1473020899", + "time_updated": "1473020899", + "time_read": "0", + "time_favorited": "0", + "sort_id": 0, + "resolved_title": "Leslie Jones is back on Twitter and her comeback tweet rules", + "resolved_url": "http://mashable.com/2016/09/04/leslie-jones-back-on-twitter-after-hack/?utm_campaign=Mash-Prod-RSS-Feedburner-All-Partial&utm_cid=Mash-Prod-RSS-Feedburner-All-Partial", + "excerpt": "Leslie Jones is back to communicating with her adoring public on Twitter after cowardly hacker-trolls drove her away, probably to compensate for their own failings. It all started with a mic drop ...", + "is_article": "1", + "is_index": "0", + "has_video": "0", + "has_image": "1", + "word_count": "200", + "tags": { + "ifttt": { + "item_id": "1402935436", + "tag": "ifttt" + }, + "mashable": { + "item_id": "1402935436", + "tag": "mashable" + } + }, + "authors": { + "2484273": { + "item_id": "1402935436", + "author_id": "2484273", + "name": "Adam Rosenberg", + "url": "http://mashable.com/author/adam-rosenberg/" + } + }, + "image": { + "item_id": "1402935436", + "src": "http://i.amz.mshcdn.com/i-V5cS6_sDqFABaVR0hVSBJqG_w=/950x534/https%3A%2F%2Fblueprint-api-production.s3.amazonaws.com%2Fuploads%2Fcard%2Fimage%2F199899%2Fleslie_jones_war_dogs.jpg", + "width": "0", + "height": "0" + }, + "images": { + "1": { + "item_id": "1402935436", + "image_id": "1", + "src": "http://i.amz.mshcdn.com/i-V5cS6_sDqFABaVR0hVSBJqG_w=/950x534/https%3A%2F%2Fblueprint-api-production.s3.amazonaws.com%2Fuploads%2Fcard%2Fimage%2F199899%2Fleslie_jones_war_dogs.jpg", + "width": "0", + "height": "0", + "credit": "Image: Steve Eichner/NameFace/Sipa USA", + "caption": "" + } + }, + "userId": 1 +} +JSON; + + $user = new User(); + $entry = new Entry($user); + + $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') + ->disableOriginalConstructor() + ->getMock(); + + $userRepository + ->expects($this->once()) + ->method('find') + // userId from the body json above + ->with(1) + ->willReturn($user); + + $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') + ->disableOriginalConstructor() + ->getMock(); + + $import + ->expects($this->once()) + ->method('setUser') + ->with($user); + + $import + ->expects($this->once()) + ->method('parseEntry') + ->with(json_decode($body, true)) + ->willReturn($entry); + + $consumer = new EntryConsumer( + $em, + $userRepository, + $import + ); + + $message = new AMQPMessage($body); + + $consumer->execute($message); + } + + public function testMessageWithBadUser() + { + $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $em + ->expects($this->never()) + ->method('flush'); + + $em + ->expects($this->never()) + ->method('clear'); + + $body = '{ "userId": 123 }'; + + $user = new User(); + $entry = new Entry($user); + + $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') + ->disableOriginalConstructor() + ->getMock(); + + $userRepository + ->expects($this->once()) + ->method('find') + // userId from the body json above + ->with(123) + ->willReturn(null); + + $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') + ->disableOriginalConstructor() + ->getMock(); + + $consumer = new EntryConsumer( + $em, + $userRepository, + $import + ); + + $message = new AMQPMessage($body); + + $consumer->execute($message); + } + + public function testMessageWithEntryProcessed() + { + $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $em + ->expects($this->never()) + ->method('flush'); + + $em + ->expects($this->never()) + ->method('clear'); + + $body = '{ "userId": 123 }'; + + $user = new User(); + + $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') + ->disableOriginalConstructor() + ->getMock(); + + $userRepository + ->expects($this->once()) + ->method('find') + // userId from the body json above + ->with(123) + ->willReturn($user); + + $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') + ->disableOriginalConstructor() + ->getMock(); + + $import + ->expects($this->once()) + ->method('setUser') + ->with($user); + + $import + ->expects($this->once()) + ->method('parseEntry') + ->with(json_decode($body, true)) + ->willReturn(null); + + $consumer = new EntryConsumer( + $em, + $userRepository, + $import + ); + + $message = new AMQPMessage($body); + + $consumer->execute($message); + } +} diff --git a/tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php b/tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php index e0e61df8..098cf356 100644 --- a/tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php @@ -17,6 +17,21 @@ class PocketControllerTest extends WallabagCoreTestCase $this->assertEquals(1, $crawler->filter('button[type=submit]')->count()); } + public function testImportPocketWithRabbitEnabled() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $client->getContainer()->get('craue_config')->set('rabbitmq', 1); + + $crawler = $client->request('GET', '/import/pocket'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('button[type=submit]')->count()); + + $client->getContainer()->get('craue_config')->set('rabbitmq', 0); + } + public function testImportPocketAuthBadToken() { $this->logInAs('admin'); diff --git a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php index fb39356a..e12a723d 100644 --- a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php @@ -19,6 +19,22 @@ class ReadabilityControllerTest extends WallabagCoreTestCase $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); } + public function testImportReadabilityWithRabbitEnabled() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $client->getContainer()->get('craue_config')->set('rabbitmq', 1); + + $crawler = $client->request('GET', '/import/readability'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + + $client->getContainer()->get('craue_config')->set('rabbitmq', 0); + } + public function testImportReadabilityWithFile() { $this->logInAs('admin'); diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php index ff1bf6f0..96556717 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php @@ -19,6 +19,22 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); } + public function testImportWallabagWithRabbitEnabled() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $client->getContainer()->get('craue_config')->set('rabbitmq', 1); + + $crawler = $client->request('GET', '/import/wallabag-v1'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + + $client->getContainer()->get('craue_config')->set('rabbitmq', 0); + } + public function testImportWallabagWithFile() { $this->logInAs('admin'); diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php index 149e88bb..250d0d3e 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php @@ -19,6 +19,22 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); } + public function testImportWallabagWithRabbitEnabled() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $client->getContainer()->get('craue_config')->set('rabbitmq', 1); + + $crawler = $client->request('GET', '/import/wallabag-v2'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + + $client->getContainer()->get('craue_config')->set('rabbitmq', 0); + } + public function testImportWallabagWithFile() { $this->logInAs('admin'); diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index 26c6b825..5ad3e435 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php @@ -343,6 +343,87 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase $this->assertEquals(['skipped' => 0, 'imported' => 2], $pocketImport->getSummary()); } + /** + * Will sample results from https://getpocket.com/developer/docs/v3/retrieve. + */ + public function testImportWithRabbit() + { + $client = new Client(); + + $body = <<<'JSON' +{ + "item_id": "229279689", + "resolved_id": "229279689", + "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", + "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", + "favorite": "1", + "status": "1", + "resolved_title": "The Massive Ryder Cup Preview", + "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", + "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", + "is_article": "1", + "has_video": "0", + "has_image": "0", + "word_count": "3197" +} +JSON; + + $mock = new Mock([ + new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['access_token' => 'wunderbar_token']))), + new Response(200, ['Content-Type' => 'application/json'], Stream::factory(' + { + "status": 1, + "list": { + "229279690": '.$body.' + } + } + ')), + ]); + + $client->getEmitter()->attach($mock); + + $pocketImport = $this->getPocketImport(); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->never()) + ->method('findByUrlAndUserId'); + + $this->em + ->expects($this->never()) + ->method('getRepository'); + + $entry = new Entry($this->user); + + $this->contentProxy + ->expects($this->never()) + ->method('updateEntry'); + + $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') + ->disableOriginalConstructor() + ->getMock(); + + $bodyAsArray = json_decode($body, true); + // because with just use `new User()` so it doesn't have an id + $bodyAsArray['userId'] = null; + + $producer + ->expects($this->once()) + ->method('publish') + ->with(json_encode($bodyAsArray)); + + $pocketImport->setClient($client); + $pocketImport->setRabbitmqProducer($producer); + $pocketImport->authorize('wunderbar_code'); + + $res = $pocketImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 1], $pocketImport->getSummary()); + } + public function testImportBadResponse() { $client = new Client(); diff --git a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php index 706d707b..69a66d6a 100644 --- a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php @@ -120,6 +120,46 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $this->assertEquals(['skipped' => 0, 'imported' => 2], $readabilityImport->getSummary()); } + public function testImportWithRabbit() + { + $readabilityImport = $this->getReadabilityImport(); + $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->never()) + ->method('findByUrlAndUserId'); + + $this->em + ->expects($this->never()) + ->method('getRepository'); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->never()) + ->method('updateEntry'); + + $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') + ->disableOriginalConstructor() + ->getMock(); + + $producer + ->expects($this->exactly(2)) + ->method('publish'); + + $readabilityImport->setRabbitmqProducer($producer); + + $res = $readabilityImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 2], $readabilityImport->getSummary()); + } + public function testImportBadFile() { $readabilityImport = $this->getReadabilityImport(); diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php index bdc47dac..ada5493e 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php @@ -120,6 +120,46 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $this->assertEquals(['skipped' => 0, 'imported' => 3], $wallabagV1Import->getSummary()); } + public function testImportWithRabbit() + { + $wallabagV1Import = $this->getWallabagV1Import(); + $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->never()) + ->method('findByUrlAndUserId'); + + $this->em + ->expects($this->never()) + ->method('getRepository'); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->never()) + ->method('updateEntry'); + + $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') + ->disableOriginalConstructor() + ->getMock(); + + $producer + ->expects($this->exactly(4)) + ->method('publish'); + + $wallabagV1Import->setRabbitmqProducer($producer); + + $res = $wallabagV1Import->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 4], $wallabagV1Import->getSummary()); + } + public function testImportBadFile() { $wallabagV1Import = $this->getWallabagV1Import(); diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php index 4a45e0f0..51f0aada 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php @@ -116,6 +116,42 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $this->assertEquals(['skipped' => 0, 'imported' => 2], $wallabagV2Import->getSummary()); } + public function testImportWithRabbit() + { + $wallabagV2Import = $this->getWallabagV2Import(); + $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->never()) + ->method('findByUrlAndUserId'); + + $this->em + ->expects($this->never()) + ->method('getRepository'); + + $this->contentProxy + ->expects($this->never()) + ->method('updateEntry'); + + $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') + ->disableOriginalConstructor() + ->getMock(); + + $producer + ->expects($this->exactly(24)) + ->method('publish'); + + $wallabagV2Import->setRabbitmqProducer($producer); + + $res = $wallabagV2Import->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 24], $wallabagV2Import->getSummary()); + } + public function testImportBadFile() { $wallabagV1Import = $this->getWallabagV2Import(); -- cgit v1.2.3 From 7f7531171f6e49110b5842f869e37c766a682473 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 9 Sep 2016 20:45:30 +0200 Subject: Retrieve created date from Pocket --- .../ImportBundle/Import/PocketImportTest.php | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index 5ad3e435..1750e3a1 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php @@ -165,10 +165,16 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", "favorite": "1", "status": "1", + "time_added": "1473020899", + "time_updated": "1473020899", + "time_read": "0", + "time_favorited": "0", + "sort_id": 0, "resolved_title": "The Massive Ryder Cup Preview", "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", "is_article": "1", + "is_index": "0", "has_video": "1", "has_image": "1", "word_count": "3197", @@ -212,10 +218,16 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", "favorite": "1", "status": "1", + "time_added": "1473020899", + "time_updated": "1473020899", + "time_read": "0", + "time_favorited": "0", + "sort_id": 1, "resolved_title": "The Massive Ryder Cup Preview", "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", "is_article": "1", + "is_index": "0", "has_video": "0", "has_image": "0", "word_count": "3197" @@ -278,6 +290,11 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", "favorite": "1", "status": "1", + "time_added": "1473020899", + "time_updated": "1473020899", + "time_read": "0", + "time_favorited": "0", + "sort_id": 0, "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", "is_article": "1", "has_video": "1", @@ -291,6 +308,11 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", "favorite": "1", "status": "0", + "time_added": "1473020899", + "time_updated": "1473020899", + "time_read": "0", + "time_favorited": "0", + "sort_id": 1, "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", "is_article": "1", "has_video": "0", @@ -358,6 +380,11 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", "favorite": "1", "status": "1", + "time_added": "1473020899", + "time_updated": "1473020899", + "time_read": "0", + "time_favorited": "0", + "sort_id": 0, "resolved_title": "The Massive Ryder Cup Preview", "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", -- cgit v1.2.3 From b3437d58ae224121375c99e9288d8b808524e624 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 9 Sep 2016 21:02:03 +0200 Subject: Enable Redis async import - using javibravo/simpleue - internal config value are now `import_with_redis` & `import_with_rabbit` which are more clear - if both option are enable rabbit will be choosen - services imports related to async are now splitted into 2 files: `redis.yml` & `rabbit.yml` - --- .../Consumer/AMPQ/EntryConsumerTest.php | 225 --------------------- .../Consumer/AMPQEntryConsumerTest.php | 225 +++++++++++++++++++++ .../Consumer/RedisEntryConsumerTest.php | 224 ++++++++++++++++++++ .../Controller/PocketControllerTest.php | 19 +- .../Controller/ReadabilityControllerTest.php | 20 +- .../Controller/WallabagV1ControllerTest.php | 20 +- .../Controller/WallabagV2ControllerTest.php | 20 +- .../ImportBundle/Import/PocketImportTest.php | 86 +++++++- .../ImportBundle/Import/ReadabilityImportTest.php | 45 ++++- .../ImportBundle/Import/WallabagV1ImportTest.php | 45 ++++- .../ImportBundle/Import/WallabagV2ImportTest.php | 41 +++- 11 files changed, 733 insertions(+), 237 deletions(-) delete mode 100644 tests/Wallabag/ImportBundle/Consumer/AMPQ/EntryConsumerTest.php create mode 100644 tests/Wallabag/ImportBundle/Consumer/AMPQEntryConsumerTest.php create mode 100644 tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ImportBundle/Consumer/AMPQ/EntryConsumerTest.php b/tests/Wallabag/ImportBundle/Consumer/AMPQ/EntryConsumerTest.php deleted file mode 100644 index 7141874c..00000000 --- a/tests/Wallabag/ImportBundle/Consumer/AMPQ/EntryConsumerTest.php +++ /dev/null @@ -1,225 +0,0 @@ -getMockBuilder('Doctrine\ORM\EntityManager') - ->disableOriginalConstructor() - ->getMock(); - - $em - ->expects($this->once()) - ->method('flush'); - - $em - ->expects($this->exactly(2)) - ->method('clear'); - - $body = <<<'JSON' -{ - "item_id": "1402935436", - "resolved_id": "1402935436", - "given_url": "http://mashable.com/2016/09/04/leslie-jones-back-on-twitter-after-hack/?utm_campaign=Mash-Prod-RSS-Feedburner-All-Partial&utm_cid=Mash-Prod-RSS-Feedburner-All-Partial", - "given_title": "Leslie Jones is back on Twitter and her comeback tweet rules", - "favorite": "0", - "status": "0", - "time_added": "1473020899", - "time_updated": "1473020899", - "time_read": "0", - "time_favorited": "0", - "sort_id": 0, - "resolved_title": "Leslie Jones is back on Twitter and her comeback tweet rules", - "resolved_url": "http://mashable.com/2016/09/04/leslie-jones-back-on-twitter-after-hack/?utm_campaign=Mash-Prod-RSS-Feedburner-All-Partial&utm_cid=Mash-Prod-RSS-Feedburner-All-Partial", - "excerpt": "Leslie Jones is back to communicating with her adoring public on Twitter after cowardly hacker-trolls drove her away, probably to compensate for their own failings. It all started with a mic drop ...", - "is_article": "1", - "is_index": "0", - "has_video": "0", - "has_image": "1", - "word_count": "200", - "tags": { - "ifttt": { - "item_id": "1402935436", - "tag": "ifttt" - }, - "mashable": { - "item_id": "1402935436", - "tag": "mashable" - } - }, - "authors": { - "2484273": { - "item_id": "1402935436", - "author_id": "2484273", - "name": "Adam Rosenberg", - "url": "http://mashable.com/author/adam-rosenberg/" - } - }, - "image": { - "item_id": "1402935436", - "src": "http://i.amz.mshcdn.com/i-V5cS6_sDqFABaVR0hVSBJqG_w=/950x534/https%3A%2F%2Fblueprint-api-production.s3.amazonaws.com%2Fuploads%2Fcard%2Fimage%2F199899%2Fleslie_jones_war_dogs.jpg", - "width": "0", - "height": "0" - }, - "images": { - "1": { - "item_id": "1402935436", - "image_id": "1", - "src": "http://i.amz.mshcdn.com/i-V5cS6_sDqFABaVR0hVSBJqG_w=/950x534/https%3A%2F%2Fblueprint-api-production.s3.amazonaws.com%2Fuploads%2Fcard%2Fimage%2F199899%2Fleslie_jones_war_dogs.jpg", - "width": "0", - "height": "0", - "credit": "Image: Steve Eichner/NameFace/Sipa USA", - "caption": "" - } - }, - "userId": 1 -} -JSON; - - $user = new User(); - $entry = new Entry($user); - - $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') - ->disableOriginalConstructor() - ->getMock(); - - $userRepository - ->expects($this->once()) - ->method('find') - // userId from the body json above - ->with(1) - ->willReturn($user); - - $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') - ->disableOriginalConstructor() - ->getMock(); - - $import - ->expects($this->once()) - ->method('setUser') - ->with($user); - - $import - ->expects($this->once()) - ->method('parseEntry') - ->with(json_decode($body, true)) - ->willReturn($entry); - - $consumer = new EntryConsumer( - $em, - $userRepository, - $import - ); - - $message = new AMQPMessage($body); - - $consumer->execute($message); - } - - public function testMessageWithBadUser() - { - $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') - ->disableOriginalConstructor() - ->getMock(); - - $em - ->expects($this->never()) - ->method('flush'); - - $em - ->expects($this->never()) - ->method('clear'); - - $body = '{ "userId": 123 }'; - - $user = new User(); - $entry = new Entry($user); - - $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') - ->disableOriginalConstructor() - ->getMock(); - - $userRepository - ->expects($this->once()) - ->method('find') - // userId from the body json above - ->with(123) - ->willReturn(null); - - $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') - ->disableOriginalConstructor() - ->getMock(); - - $consumer = new EntryConsumer( - $em, - $userRepository, - $import - ); - - $message = new AMQPMessage($body); - - $consumer->execute($message); - } - - public function testMessageWithEntryProcessed() - { - $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') - ->disableOriginalConstructor() - ->getMock(); - - $em - ->expects($this->never()) - ->method('flush'); - - $em - ->expects($this->never()) - ->method('clear'); - - $body = '{ "userId": 123 }'; - - $user = new User(); - - $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') - ->disableOriginalConstructor() - ->getMock(); - - $userRepository - ->expects($this->once()) - ->method('find') - // userId from the body json above - ->with(123) - ->willReturn($user); - - $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') - ->disableOriginalConstructor() - ->getMock(); - - $import - ->expects($this->once()) - ->method('setUser') - ->with($user); - - $import - ->expects($this->once()) - ->method('parseEntry') - ->with(json_decode($body, true)) - ->willReturn(null); - - $consumer = new EntryConsumer( - $em, - $userRepository, - $import - ); - - $message = new AMQPMessage($body); - - $consumer->execute($message); - } -} diff --git a/tests/Wallabag/ImportBundle/Consumer/AMPQEntryConsumerTest.php b/tests/Wallabag/ImportBundle/Consumer/AMPQEntryConsumerTest.php new file mode 100644 index 00000000..b13ade1d --- /dev/null +++ b/tests/Wallabag/ImportBundle/Consumer/AMPQEntryConsumerTest.php @@ -0,0 +1,225 @@ +getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $em + ->expects($this->once()) + ->method('flush'); + + $em + ->expects($this->exactly(2)) + ->method('clear'); + + $body = <<<'JSON' +{ + "item_id": "1402935436", + "resolved_id": "1402935436", + "given_url": "http://mashable.com/2016/09/04/leslie-jones-back-on-twitter-after-hack/?utm_campaign=Mash-Prod-RSS-Feedburner-All-Partial&utm_cid=Mash-Prod-RSS-Feedburner-All-Partial", + "given_title": "Leslie Jones is back on Twitter and her comeback tweet rules", + "favorite": "0", + "status": "0", + "time_added": "1473020899", + "time_updated": "1473020899", + "time_read": "0", + "time_favorited": "0", + "sort_id": 0, + "resolved_title": "Leslie Jones is back on Twitter and her comeback tweet rules", + "resolved_url": "http://mashable.com/2016/09/04/leslie-jones-back-on-twitter-after-hack/?utm_campaign=Mash-Prod-RSS-Feedburner-All-Partial&utm_cid=Mash-Prod-RSS-Feedburner-All-Partial", + "excerpt": "Leslie Jones is back to communicating with her adoring public on Twitter after cowardly hacker-trolls drove her away, probably to compensate for their own failings. It all started with a mic drop ...", + "is_article": "1", + "is_index": "0", + "has_video": "0", + "has_image": "1", + "word_count": "200", + "tags": { + "ifttt": { + "item_id": "1402935436", + "tag": "ifttt" + }, + "mashable": { + "item_id": "1402935436", + "tag": "mashable" + } + }, + "authors": { + "2484273": { + "item_id": "1402935436", + "author_id": "2484273", + "name": "Adam Rosenberg", + "url": "http://mashable.com/author/adam-rosenberg/" + } + }, + "image": { + "item_id": "1402935436", + "src": "http://i.amz.mshcdn.com/i-V5cS6_sDqFABaVR0hVSBJqG_w=/950x534/https%3A%2F%2Fblueprint-api-production.s3.amazonaws.com%2Fuploads%2Fcard%2Fimage%2F199899%2Fleslie_jones_war_dogs.jpg", + "width": "0", + "height": "0" + }, + "images": { + "1": { + "item_id": "1402935436", + "image_id": "1", + "src": "http://i.amz.mshcdn.com/i-V5cS6_sDqFABaVR0hVSBJqG_w=/950x534/https%3A%2F%2Fblueprint-api-production.s3.amazonaws.com%2Fuploads%2Fcard%2Fimage%2F199899%2Fleslie_jones_war_dogs.jpg", + "width": "0", + "height": "0", + "credit": "Image: Steve Eichner/NameFace/Sipa USA", + "caption": "" + } + }, + "userId": 1 +} +JSON; + + $user = new User(); + $entry = new Entry($user); + + $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') + ->disableOriginalConstructor() + ->getMock(); + + $userRepository + ->expects($this->once()) + ->method('find') + // userId from the body json above + ->with(1) + ->willReturn($user); + + $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') + ->disableOriginalConstructor() + ->getMock(); + + $import + ->expects($this->once()) + ->method('setUser') + ->with($user); + + $import + ->expects($this->once()) + ->method('parseEntry') + ->with(json_decode($body, true)) + ->willReturn($entry); + + $consumer = new AMPQEntryConsumer( + $em, + $userRepository, + $import + ); + + $message = new AMQPMessage($body); + + $consumer->execute($message); + } + + public function testMessageWithBadUser() + { + $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $em + ->expects($this->never()) + ->method('flush'); + + $em + ->expects($this->never()) + ->method('clear'); + + $body = '{ "userId": 123 }'; + + $user = new User(); + $entry = new Entry($user); + + $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') + ->disableOriginalConstructor() + ->getMock(); + + $userRepository + ->expects($this->once()) + ->method('find') + // userId from the body json above + ->with(123) + ->willReturn(null); + + $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') + ->disableOriginalConstructor() + ->getMock(); + + $consumer = new AMPQEntryConsumer( + $em, + $userRepository, + $import + ); + + $message = new AMQPMessage($body); + + $consumer->execute($message); + } + + public function testMessageWithEntryProcessed() + { + $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $em + ->expects($this->never()) + ->method('flush'); + + $em + ->expects($this->never()) + ->method('clear'); + + $body = '{ "userId": 123 }'; + + $user = new User(); + + $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') + ->disableOriginalConstructor() + ->getMock(); + + $userRepository + ->expects($this->once()) + ->method('find') + // userId from the body json above + ->with(123) + ->willReturn($user); + + $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') + ->disableOriginalConstructor() + ->getMock(); + + $import + ->expects($this->once()) + ->method('setUser') + ->with($user); + + $import + ->expects($this->once()) + ->method('parseEntry') + ->with(json_decode($body, true)) + ->willReturn(null); + + $consumer = new AMPQEntryConsumer( + $em, + $userRepository, + $import + ); + + $message = new AMQPMessage($body); + + $consumer->execute($message); + } +} diff --git a/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php b/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php new file mode 100644 index 00000000..0ce7ce49 --- /dev/null +++ b/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php @@ -0,0 +1,224 @@ +getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $em + ->expects($this->once()) + ->method('flush'); + + $em + ->expects($this->exactly(2)) + ->method('clear'); + + $body = <<<'JSON' +{ + "item_id": "1402935436", + "resolved_id": "1402935436", + "given_url": "http://mashable.com/2016/09/04/leslie-jones-back-on-twitter-after-hack/?utm_campaign=Mash-Prod-RSS-Feedburner-All-Partial&utm_cid=Mash-Prod-RSS-Feedburner-All-Partial", + "given_title": "Leslie Jones is back on Twitter and her comeback tweet rules", + "favorite": "0", + "status": "0", + "time_added": "1473020899", + "time_updated": "1473020899", + "time_read": "0", + "time_favorited": "0", + "sort_id": 0, + "resolved_title": "Leslie Jones is back on Twitter and her comeback tweet rules", + "resolved_url": "http://mashable.com/2016/09/04/leslie-jones-back-on-twitter-after-hack/?utm_campaign=Mash-Prod-RSS-Feedburner-All-Partial&utm_cid=Mash-Prod-RSS-Feedburner-All-Partial", + "excerpt": "Leslie Jones is back to communicating with her adoring public on Twitter after cowardly hacker-trolls drove her away, probably to compensate for their own failings. It all started with a mic drop ...", + "is_article": "1", + "is_index": "0", + "has_video": "0", + "has_image": "1", + "word_count": "200", + "tags": { + "ifttt": { + "item_id": "1402935436", + "tag": "ifttt" + }, + "mashable": { + "item_id": "1402935436", + "tag": "mashable" + } + }, + "authors": { + "2484273": { + "item_id": "1402935436", + "author_id": "2484273", + "name": "Adam Rosenberg", + "url": "http://mashable.com/author/adam-rosenberg/" + } + }, + "image": { + "item_id": "1402935436", + "src": "http://i.amz.mshcdn.com/i-V5cS6_sDqFABaVR0hVSBJqG_w=/950x534/https%3A%2F%2Fblueprint-api-production.s3.amazonaws.com%2Fuploads%2Fcard%2Fimage%2F199899%2Fleslie_jones_war_dogs.jpg", + "width": "0", + "height": "0" + }, + "images": { + "1": { + "item_id": "1402935436", + "image_id": "1", + "src": "http://i.amz.mshcdn.com/i-V5cS6_sDqFABaVR0hVSBJqG_w=/950x534/https%3A%2F%2Fblueprint-api-production.s3.amazonaws.com%2Fuploads%2Fcard%2Fimage%2F199899%2Fleslie_jones_war_dogs.jpg", + "width": "0", + "height": "0", + "credit": "Image: Steve Eichner/NameFace/Sipa USA", + "caption": "" + } + }, + "userId": 1 +} +JSON; + + $user = new User(); + $entry = new Entry($user); + + $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') + ->disableOriginalConstructor() + ->getMock(); + + $userRepository + ->expects($this->once()) + ->method('find') + // userId from the body json above + ->with(1) + ->willReturn($user); + + $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') + ->disableOriginalConstructor() + ->getMock(); + + $import + ->expects($this->once()) + ->method('setUser') + ->with($user); + + $import + ->expects($this->once()) + ->method('parseEntry') + ->with(json_decode($body, true)) + ->willReturn($entry); + + $consumer = new RedisEntryConsumer( + $em, + $userRepository, + $import + ); + + $res = $consumer->manage($body); + + $this->assertTrue($res); + } + + public function testMessageWithBadUser() + { + $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $em + ->expects($this->never()) + ->method('flush'); + + $em + ->expects($this->never()) + ->method('clear'); + + $body = '{ "userId": 123 }'; + + $user = new User(); + $entry = new Entry($user); + + $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') + ->disableOriginalConstructor() + ->getMock(); + + $userRepository + ->expects($this->once()) + ->method('find') + // userId from the body json above + ->with(123) + ->willReturn(null); + + $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') + ->disableOriginalConstructor() + ->getMock(); + + $consumer = new RedisEntryConsumer( + $em, + $userRepository, + $import + ); + + $res = $consumer->manage($body); + + $this->assertFalse($res); + } + + public function testMessageWithEntryProcessed() + { + $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $em + ->expects($this->never()) + ->method('flush'); + + $em + ->expects($this->never()) + ->method('clear'); + + $body = '{ "userId": 123 }'; + + $user = new User(); + + $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') + ->disableOriginalConstructor() + ->getMock(); + + $userRepository + ->expects($this->once()) + ->method('find') + // userId from the body json above + ->with(123) + ->willReturn($user); + + $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') + ->disableOriginalConstructor() + ->getMock(); + + $import + ->expects($this->once()) + ->method('setUser') + ->with($user); + + $import + ->expects($this->once()) + ->method('parseEntry') + ->with(json_decode($body, true)) + ->willReturn(null); + + $consumer = new RedisEntryConsumer( + $em, + $userRepository, + $import + ); + + $res = $consumer->manage($body); + + $this->assertFalse($res); + } +} diff --git a/tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php b/tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php index 098cf356..35673261 100644 --- a/tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php @@ -22,14 +22,29 @@ class PocketControllerTest extends WallabagCoreTestCase $this->logInAs('admin'); $client = $this->getClient(); - $client->getContainer()->get('craue_config')->set('rabbitmq', 1); + $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 1); $crawler = $client->request('GET', '/import/pocket'); $this->assertEquals(200, $client->getResponse()->getStatusCode()); $this->assertEquals(1, $crawler->filter('button[type=submit]')->count()); - $client->getContainer()->get('craue_config')->set('rabbitmq', 0); + $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0); + } + + public function testImportPocketWithRedisEnabled() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $client->getContainer()->get('craue_config')->set('import_with_redis', 1); + + $crawler = $client->request('GET', '/import/pocket'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('button[type=submit]')->count()); + + $client->getContainer()->get('craue_config')->set('import_with_redis', 0); } public function testImportPocketAuthBadToken() diff --git a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php index e12a723d..69635382 100644 --- a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php @@ -24,7 +24,7 @@ class ReadabilityControllerTest extends WallabagCoreTestCase $this->logInAs('admin'); $client = $this->getClient(); - $client->getContainer()->get('craue_config')->set('rabbitmq', 1); + $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 1); $crawler = $client->request('GET', '/import/readability'); @@ -32,7 +32,23 @@ class ReadabilityControllerTest extends WallabagCoreTestCase $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); - $client->getContainer()->get('craue_config')->set('rabbitmq', 0); + $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0); + } + + public function testImportReadabilityWithRedisEnabled() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $client->getContainer()->get('craue_config')->set('import_with_redis', 1); + + $crawler = $client->request('GET', '/import/readability'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + + $client->getContainer()->get('craue_config')->set('import_with_redis', 0); } public function testImportReadabilityWithFile() diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php index 96556717..933ddd6c 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php @@ -24,7 +24,7 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase $this->logInAs('admin'); $client = $this->getClient(); - $client->getContainer()->get('craue_config')->set('rabbitmq', 1); + $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 1); $crawler = $client->request('GET', '/import/wallabag-v1'); @@ -32,7 +32,23 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); - $client->getContainer()->get('craue_config')->set('rabbitmq', 0); + $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0); + } + + public function testImportWallabagWithRedisEnabled() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $client->getContainer()->get('craue_config')->set('import_with_redis', 1); + + $crawler = $client->request('GET', '/import/wallabag-v1'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + + $client->getContainer()->get('craue_config')->set('import_with_redis', 0); } public function testImportWallabagWithFile() diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php index 250d0d3e..36e5221d 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php @@ -24,7 +24,7 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase $this->logInAs('admin'); $client = $this->getClient(); - $client->getContainer()->get('craue_config')->set('rabbitmq', 1); + $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 1); $crawler = $client->request('GET', '/import/wallabag-v2'); @@ -32,7 +32,23 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); - $client->getContainer()->get('craue_config')->set('rabbitmq', 0); + $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0); + } + + public function testImportWallabagWithRedisEnabled() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $client->getContainer()->get('craue_config')->set('import_with_redis', 1); + + $crawler = $client->request('GET', '/import/wallabag-v2'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + + $client->getContainer()->get('craue_config')->set('import_with_redis', 0); } public function testImportWallabagWithFile() diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index 1750e3a1..425fa321 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php @@ -9,8 +9,11 @@ use GuzzleHttp\Client; use GuzzleHttp\Subscriber\Mock; use GuzzleHttp\Message\Response; use GuzzleHttp\Stream\Stream; +use Wallabag\ImportBundle\Redis\Producer; use Monolog\Logger; use Monolog\Handler\TestHandler; +use Simpleue\Queue\RedisQueue; +use M6Web\Component\RedisMock\RedisMockFactory; class PocketImportTest extends \PHPUnit_Framework_TestCase { @@ -442,7 +445,7 @@ JSON; ->with(json_encode($bodyAsArray)); $pocketImport->setClient($client); - $pocketImport->setRabbitmqProducer($producer); + $pocketImport->setProducer($producer); $pocketImport->authorize('wunderbar_code'); $res = $pocketImport->setMarkAsRead(true)->import(); @@ -451,6 +454,87 @@ JSON; $this->assertEquals(['skipped' => 0, 'imported' => 1], $pocketImport->getSummary()); } + /** + * Will sample results from https://getpocket.com/developer/docs/v3/retrieve. + */ + public function testImportWithRedis() + { + $client = new Client(); + + $body = <<<'JSON' +{ + "item_id": "229279689", + "resolved_id": "229279689", + "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", + "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", + "favorite": "1", + "status": "1", + "time_added": "1473020899", + "time_updated": "1473020899", + "time_read": "0", + "time_favorited": "0", + "sort_id": 0, + "resolved_title": "The Massive Ryder Cup Preview", + "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", + "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", + "is_article": "1", + "has_video": "0", + "has_image": "0", + "word_count": "3197" +} +JSON; + + $mock = new Mock([ + new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['access_token' => 'wunderbar_token']))), + new Response(200, ['Content-Type' => 'application/json'], Stream::factory(' + { + "status": 1, + "list": { + "229279690": '.$body.' + } + } + ')), + ]); + + $client->getEmitter()->attach($mock); + + $pocketImport = $this->getPocketImport(); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->never()) + ->method('findByUrlAndUserId'); + + $this->em + ->expects($this->never()) + ->method('getRepository'); + + $entry = new Entry($this->user); + + $this->contentProxy + ->expects($this->never()) + ->method('updateEntry'); + + $factory = new RedisMockFactory(); + $redisMock = $factory->getAdapter('Predis\Client', true); + + $queue = new RedisQueue($redisMock, 'pocket'); + $producer = new Producer($queue); + + $pocketImport->setClient($client); + $pocketImport->setProducer($producer); + $pocketImport->authorize('wunderbar_code'); + + $res = $pocketImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 1], $pocketImport->getSummary()); + + $this->assertNotEmpty($redisMock->lpop('pocket')); + } + public function testImportBadResponse() { $client = new Client(); diff --git a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php index 69a66d6a..0981eedb 100644 --- a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php @@ -5,8 +5,11 @@ namespace Tests\Wallabag\ImportBundle\Import; use Wallabag\ImportBundle\Import\ReadabilityImport; use Wallabag\UserBundle\Entity\User; use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\ImportBundle\Redis\Producer; use Monolog\Logger; use Monolog\Handler\TestHandler; +use Simpleue\Queue\RedisQueue; +use M6Web\Component\RedisMock\RedisMockFactory; class ReadabilityImportTest extends \PHPUnit_Framework_TestCase { @@ -152,7 +155,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase ->expects($this->exactly(2)) ->method('publish'); - $readabilityImport->setRabbitmqProducer($producer); + $readabilityImport->setProducer($producer); $res = $readabilityImport->setMarkAsRead(true)->import(); @@ -160,6 +163,46 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $this->assertEquals(['skipped' => 0, 'imported' => 2], $readabilityImport->getSummary()); } + public function testImportWithRedis() + { + $readabilityImport = $this->getReadabilityImport(); + $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->never()) + ->method('findByUrlAndUserId'); + + $this->em + ->expects($this->never()) + ->method('getRepository'); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->never()) + ->method('updateEntry'); + + $factory = new RedisMockFactory(); + $redisMock = $factory->getAdapter('Predis\Client', true); + + $queue = new RedisQueue($redisMock, 'readability'); + $producer = new Producer($queue); + + $readabilityImport->setProducer($producer); + + $res = $readabilityImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 2], $readabilityImport->getSummary()); + + $this->assertNotEmpty($redisMock->lpop('readability')); + } + public function testImportBadFile() { $readabilityImport = $this->getReadabilityImport(); diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php index ada5493e..b43682cd 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php @@ -5,8 +5,11 @@ namespace Tests\Wallabag\ImportBundle\Import; use Wallabag\ImportBundle\Import\WallabagV1Import; use Wallabag\UserBundle\Entity\User; use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\ImportBundle\Redis\Producer; use Monolog\Logger; use Monolog\Handler\TestHandler; +use Simpleue\Queue\RedisQueue; +use M6Web\Component\RedisMock\RedisMockFactory; class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase { @@ -152,7 +155,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase ->expects($this->exactly(4)) ->method('publish'); - $wallabagV1Import->setRabbitmqProducer($producer); + $wallabagV1Import->setProducer($producer); $res = $wallabagV1Import->setMarkAsRead(true)->import(); @@ -160,6 +163,46 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $this->assertEquals(['skipped' => 0, 'imported' => 4], $wallabagV1Import->getSummary()); } + public function testImportWithRedis() + { + $wallabagV1Import = $this->getWallabagV1Import(); + $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->never()) + ->method('findByUrlAndUserId'); + + $this->em + ->expects($this->never()) + ->method('getRepository'); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->never()) + ->method('updateEntry'); + + $factory = new RedisMockFactory(); + $redisMock = $factory->getAdapter('Predis\Client', true); + + $queue = new RedisQueue($redisMock, 'wallabag_v1'); + $producer = new Producer($queue); + + $wallabagV1Import->setProducer($producer); + + $res = $wallabagV1Import->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 4], $wallabagV1Import->getSummary()); + + $this->assertNotEmpty($redisMock->lpop('wallabag_v1')); + } + public function testImportBadFile() { $wallabagV1Import = $this->getWallabagV1Import(); diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php index 51f0aada..18998b35 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php @@ -5,8 +5,11 @@ namespace Tests\Wallabag\ImportBundle\Import; use Wallabag\ImportBundle\Import\WallabagV2Import; use Wallabag\UserBundle\Entity\User; use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\ImportBundle\Redis\Producer; use Monolog\Logger; use Monolog\Handler\TestHandler; +use Simpleue\Queue\RedisQueue; +use M6Web\Component\RedisMock\RedisMockFactory; class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase { @@ -144,7 +147,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase ->expects($this->exactly(24)) ->method('publish'); - $wallabagV2Import->setRabbitmqProducer($producer); + $wallabagV2Import->setProducer($producer); $res = $wallabagV2Import->setMarkAsRead(true)->import(); @@ -152,6 +155,42 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $this->assertEquals(['skipped' => 0, 'imported' => 24], $wallabagV2Import->getSummary()); } + public function testImportWithRedis() + { + $wallabagV2Import = $this->getWallabagV2Import(); + $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->never()) + ->method('findByUrlAndUserId'); + + $this->em + ->expects($this->never()) + ->method('getRepository'); + + $this->contentProxy + ->expects($this->never()) + ->method('updateEntry'); + + $factory = new RedisMockFactory(); + $redisMock = $factory->getAdapter('Predis\Client', true); + + $queue = new RedisQueue($redisMock, 'wallabag_v2'); + $producer = new Producer($queue); + + $wallabagV2Import->setProducer($producer); + + $res = $wallabagV2Import->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 24], $wallabagV2Import->getSummary()); + + $this->assertNotEmpty($redisMock->lpop('wallabag_v2')); + } + public function testImportBadFile() { $wallabagV1Import = $this->getWallabagV2Import(); -- cgit v1.2.3 From 7230e4c39f84e5aca97f439953adfd265b8d9ba4 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 11 Sep 2016 18:19:41 +0200 Subject: Enable Redis on Travis Add generated files from `composer up` Add more articles for Readability tests --- .../ImportBundle/Import/ReadabilityImportTest.php | 20 +-- .../ImportBundle/fixtures/readability.json | 167 ++++++++++++++++++++- 2 files changed, 169 insertions(+), 18 deletions(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php index 0981eedb..67917154 100644 --- a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php @@ -61,9 +61,9 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); - $entryRepo->expects($this->exactly(2)) + $entryRepo->expects($this->exactly(24)) ->method('findByUrlAndUserId') - ->will($this->onConsecutiveCalls(false, true)); + ->willReturn(false); $this->em ->expects($this->any()) @@ -75,14 +75,14 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase ->getMock(); $this->contentProxy - ->expects($this->exactly(1)) + ->expects($this->exactly(24)) ->method('updateEntry') ->willReturn($entry); $res = $readabilityImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 1, 'imported' => 1], $readabilityImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 24], $readabilityImport->getSummary()); } public function testImportAndMarkAllAsRead() @@ -96,7 +96,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $entryRepo->expects($this->exactly(2)) ->method('findByUrlAndUserId') - ->will($this->onConsecutiveCalls(false, false)); + ->will($this->onConsecutiveCalls(false, true)); $this->em ->expects($this->any()) @@ -104,7 +104,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase ->willReturn($entryRepo); $this->contentProxy - ->expects($this->exactly(2)) + ->expects($this->exactly(1)) ->method('updateEntry') ->willReturn(new Entry($this->user)); @@ -120,7 +120,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 2], $readabilityImport->getSummary()); + $this->assertEquals(['skipped' => 1, 'imported' => 1], $readabilityImport->getSummary()); } public function testImportWithRabbit() @@ -152,7 +152,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase ->getMock(); $producer - ->expects($this->exactly(2)) + ->expects($this->exactly(24)) ->method('publish'); $readabilityImport->setProducer($producer); @@ -160,7 +160,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $res = $readabilityImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 2], $readabilityImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 24], $readabilityImport->getSummary()); } public function testImportWithRedis() @@ -198,7 +198,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $res = $readabilityImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 2], $readabilityImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 24], $readabilityImport->getSummary()); $this->assertNotEmpty($redisMock->lpop('readability')); } diff --git a/tests/Wallabag/ImportBundle/fixtures/readability.json b/tests/Wallabag/ImportBundle/fixtures/readability.json index 34379905..32f6fa53 100644 --- a/tests/Wallabag/ImportBundle/fixtures/readability.json +++ b/tests/Wallabag/ImportBundle/fixtures/readability.json @@ -11,14 +11,165 @@ "archive": false }, { - "article__excerpt": "TL;DR: Re-use your DOM elements and remove the ones that are far away from the viewport. Use placeholders to account for delayed data. Here’s a demo and the code for the infinite…", - "favorite": false, - "date_archived": "2016-08-26T12:21:54", - "article__url": "https://developers.google.com/web/updates/2016/07/infinite-scroller?imm_mid=0e6839&cmp=em-webops-na-na-newsltr_20160805", - "date_added": "2016-08-06T05:35:26", - "date_favorited": null, - "article__title": "Complexities of an infinite scroller | Web Updates", - "archive": true + "article__title": "Réfugiés: l'UE va créer 100 000 places d'accueil dans les Balkans", + "article__url": "http://www.liberation.fr/planete/2015/10/26/refugies-l-ue-va-creer-100-000-places-d-accueil-dans-les-balkans_1408867", + "archive": false, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": false + }, + { + "article__title": "No title found", + "article__url": "http://news.nationalgeographic.com/2016/02/160211-albatrosses-mothers-babies-animals-science/&sf20739758=1", + "archive": false, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": true + }, + { + "archive": 0, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "Échecs", + "article__url": "https://fr.wikipedia.org/wiki/Échecs" + }, + { + "archive": 0, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "90% des dossiers médicaux des Coréens du sud vendus à des entreprises privées - ZATAZ", + "article__url": "http://www.zataz.com/90-des-dossiers-medicaux-des-coreens-du-sud-vendus-a-des-entreprises-privees/" + }, + { + "archive": 0, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "Mass Surveillance As Art", + "article__url": "https://www.nationaljournal.com/s/73311/mass-surveillance-art" + }, + { + "archive": 0, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "What David Cameron did to the pig, his party is now doing to the country", + "article__url": "http://www.newstatesman.com/2015/09/what-david-cameron-did-pig-his-party-now-doing-country" + }, + { + "archive": 1, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "CLICK HERE to support 2016 CES Winner, Revolutionary Auto-Tracking Robot", + "article__url": "https://www.indiegogo.com/projects/2016-ces-winner-revolutionary-auto-tracking-robot" + }, + { + "archive": 0, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 1, + "article__title": "No title found", + "article__url": "http://carnetdevol.shost.ca/wordpress/aide-memoire-sur-les-commandes-associees-a-systemd/" + }, + { + "archive": 1, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "Présentation d'Arduino - Tuto Arduino - Le blog d'Eskimon", + "article__url": "http://eskimon.fr/73-arduino-101-presentation" + }, + { + "archive": 1, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "Lenovo ThinkPad X1 Carbon Ultrabook Review", + "article__url": "http://www.notebookcheck.net/Lenovo-ThinkPad-X1-Carbon-Ultrabook-Review.138033.0.html" + }, + { + "archive": 0, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "Visitons le Château de Landsberg !", + "article__url": "http://autour-du-mont-sainte-odile.overblog.com/2016/01/visitons-le-chateau-de-landsberg.html" + }, + { + "archive": 1, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "Contrer les stéréotypes par les livres : “C'est dès l'enfance qu'ils se construisent”", + "article__url": "https://www.actualitte.com/article/monde-edition/contrer-les-stereotypes-par-les-livres-c-est-des-l-enfance-qu-ils-se-construisent/64058" + }, + { + "archive": 1, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "[ROM][6.0.1][Layers][N5] TipsyOS official builds {UBER TCs}", + "article__url": "http://forum.xda-developers.com/google-nexus-5/development/rom-tipsyos-official-builds-uber-tcs-t3325989" + }, + { + "archive": 0, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "Top 15 Podcasts All Web Developers Should Follow - Envato Tuts+ Code Article", + "article__url": "http://code.tutsplus.com/articles/top-15-podcasts-all-web-developers-should-follow--net-14461" + }, + { + "archive": 1, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "University of Mississippi", + "article__url": "http://olemiss.edu" + }, + { + "archive": 1, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "FinnChristiansen.de Jetzt Dank Let’s Encrypt Per HTTPS Erreichbar", + "article__url": "https://www.finnchristiansen.de/2015/12/06/finnchristiansen-de-jetzt-dank-lets-encrypt-per-https-erreichbar/" + }, + { + "archive": 1, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "Le développeur et l'ingénierie logicielle", + "article__url": "http://wemucs.com/le-developpeur-et-lingenierie-logicielle/" + }, + { + "archive": 1, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "The Role of Methylation in Gene Expression", + "article__url": "http://www.nature.com/scitable/topicpage/the-role-of-methylation-in-gene-expression-1070" + }, + { + "archive": 1, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "E-Mail-Adresse kostenlos, FreeMail, De-Mail & Nachrichten", + "article__url": "http://web.de" + }, + { + "archive": 1, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "OpenSSH Server on Arch Linux | DominicM test", + "article__url": "http://dominicm.com/openssh-server-arch-linux/" + }, + { + "archive": 1, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "Site Moved | Site Help", + "article__url": "http://g1.com/help/sitemoved.asp" + }, + { + "archive": 1, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "#Maroc : le stylo anti-pédophiles EAGLE d’AMESYS est moins bien configuré que les faux-lowers Twitter du roi Mohammed VI", + "article__url": "https://reflets.info/maroc-le-stylo-anti-pedophiles-eagle-damesys-est-moins-bien-configure-que-les-faux-lowers-twitter-du-roi-mohammed-vi/" + }, + { + "archive": 1, + "date_added": "2016-09-08T11:55:58+0200", + "favorite": 0, + "article__title": "Simple Cloud Infrastructure for Developers", + "article__url": "https://www.digitalocean.com/" } ], "recommendations": [] -- cgit v1.2.3 From 015c7a8359c950f9621b38b11c3973860a981da8 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 11 Sep 2016 20:24:04 +0200 Subject: Add more tests And ability to define how many messages can be hanle by the redis worker before stopping (usefull for tests) --- .../Command/RedisWorkerCommandTest.php | 74 ++++++++++++++++++++++ .../Consumer/RedisEntryConsumerTest.php | 1 + .../Controller/ReadabilityControllerTest.php | 17 +++++ .../Controller/WallabagV1ControllerTest.php | 17 +++++ .../Controller/WallabagV2ControllerTest.php | 17 +++++ 5 files changed, 126 insertions(+) create mode 100644 tests/Wallabag/ImportBundle/Command/RedisWorkerCommandTest.php (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ImportBundle/Command/RedisWorkerCommandTest.php b/tests/Wallabag/ImportBundle/Command/RedisWorkerCommandTest.php new file mode 100644 index 00000000..74952847 --- /dev/null +++ b/tests/Wallabag/ImportBundle/Command/RedisWorkerCommandTest.php @@ -0,0 +1,74 @@ +getClient()->getKernel()); + $application->add(new RedisWorkerCommand()); + + $command = $application->find('wallabag:import:redis-worker'); + + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + ]); + } + + /** + * @expectedException Symfony\Component\Config\Definition\Exception\Exception + * @expectedExceptionMessage No queue or consumer found for service name + */ + public function testRunRedisWorkerCommandWithBadService() + { + $application = new Application($this->getClient()->getKernel()); + $application->add(new RedisWorkerCommand()); + + $command = $application->find('wallabag:import:redis-worker'); + + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + 'serviceName' => 'YOMONSERVICE', + ]); + } + + public function testRunRedisWorkerCommand() + { + $application = new Application($this->getClient()->getKernel()); + $application->add(new RedisWorkerCommand()); + + $factory = new RedisMockFactory(); + $redisMock = $factory->getAdapter('Predis\Client', true); + + $application->getKernel()->getContainer()->set('wallabag_core.redis.client', $redisMock); + + // put a fake message in the queue so the worker will stop after reading that message + // instead of waiting for others + $redisMock->lpush('wallabag.import.readability', '{}'); + + $command = $application->find('wallabag:import:redis-worker'); + + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + 'serviceName' => 'readability', + '--maxIterations' => 1, + ]); + + $this->assertContains('Worker started at', $tester->getDisplay()); + $this->assertContains('Waiting for message', $tester->getDisplay()); + } +} diff --git a/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php b/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php index 0ce7ce49..5e8ee41d 100644 --- a/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php +++ b/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php @@ -220,5 +220,6 @@ JSON; $res = $consumer->manage($body); $this->assertFalse($res); + $this->assertFalse($consumer->isStopJob($body)); } } diff --git a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php index 69635382..fb835f62 100644 --- a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php @@ -51,6 +51,23 @@ class ReadabilityControllerTest extends WallabagCoreTestCase $client->getContainer()->get('craue_config')->set('import_with_redis', 0); } + public function testImportReadabilityBadFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/readability'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $data = [ + 'upload_import_file[file]' => '', + ]; + + $client->submit($form, $data); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + } + public function testImportReadabilityWithFile() { $this->logInAs('admin'); diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php index 933ddd6c..f1113365 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php @@ -51,6 +51,23 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase $client->getContainer()->get('craue_config')->set('import_with_redis', 0); } + public function testImportWallabagBadFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/wallabag-v1'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $data = [ + 'upload_import_file[file]' => '', + ]; + + $client->submit($form, $data); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + } + public function testImportWallabagWithFile() { $this->logInAs('admin'); diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php index 36e5221d..b20226ad 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php @@ -51,6 +51,23 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase $client->getContainer()->get('craue_config')->set('import_with_redis', 0); } + public function testImportWallabagBadFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/wallabag-v2'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $data = [ + 'upload_import_file[file]' => '', + ]; + + $client->submit($form, $data); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + } + public function testImportWallabagWithFile() { $this->logInAs('admin'); -- cgit v1.2.3 From ebf5e5087d2f79ece42a660ee7bddaa3ff3ebe1e Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 11 Sep 2016 21:40:08 +0200 Subject: Add tests on ImportCommand --- .../ImportBundle/Command/ImportCommandTest.php | 86 ++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 tests/Wallabag/ImportBundle/Command/ImportCommandTest.php (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php b/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php new file mode 100644 index 00000000..eb7fce79 --- /dev/null +++ b/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php @@ -0,0 +1,86 @@ +getClient()->getKernel()); + $application->add(new ImportCommand()); + + $command = $application->find('wallabag:import'); + + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + ]); + } + + /** + * @expectedException Symfony\Component\Config\Definition\Exception\Exception + * @expectedExceptionMessage not found + */ + public function testRunImportCommandWithoutFilepath() + { + $application = new Application($this->getClient()->getKernel()); + $application->add(new ImportCommand()); + + $command = $application->find('wallabag:import'); + + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + 'userId' => 1, + 'filepath' => 1, + ]); + } + + /** + * @expectedException Symfony\Component\Config\Definition\Exception\Exception + * @expectedExceptionMessage User with id + */ + public function testRunImportCommandWithoutUserId() + { + $application = new Application($this->getClient()->getKernel()); + $application->add(new ImportCommand()); + + $command = $application->find('wallabag:import'); + + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + 'userId' => 0, + 'filepath' => './', + ]); + } + + public function testRunImportCommand() + { + $application = new Application($this->getClient()->getKernel()); + $application->add(new ImportCommand()); + + $command = $application->find('wallabag:import'); + + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + 'userId' => 1, + 'filepath' => $application->getKernel()->getContainer()->getParameter('kernel.root_dir').'/../tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json', + '--importer' => 'v2', + ]); + + $this->assertContains('imported', $tester->getDisplay()); + $this->assertContains('already saved', $tester->getDisplay()); + } +} -- cgit v1.2.3 From 886d47973466b5516a633b0e6dd43269082f1676 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 11 Sep 2016 23:57:27 +0200 Subject: Fix tests --- tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php index b20226ad..ca20c85b 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php @@ -99,9 +99,9 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase $this->getLoggedInUserId() ); - $this->assertEmpty($content->getMimetype()); - $this->assertEmpty($content->getPreviewPicture()); - $this->assertEmpty($content->getLanguage()); + $this->assertNotEmpty($content->getMimetype()); + $this->assertNotEmpty($content->getPreviewPicture()); + $this->assertNotEmpty($content->getLanguage()); $this->assertEquals(0, count($content->getTags())); $content = $client->getContainer() -- cgit v1.2.3 From c80cc01afa315dcfa38b2a01c5b05d4516659c24 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 13 Sep 2016 21:09:05 +0200 Subject: Change flash message for queued articles --- tests/Wallabag/ImportBundle/Import/PocketImportTest.php | 10 +++++----- tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php | 8 ++++---- tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php | 8 ++++---- tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php | 12 ++++++------ 4 files changed, 19 insertions(+), 19 deletions(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index 425fa321..a3f68892 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php @@ -270,7 +270,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase $res = $pocketImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 1, 'imported' => 1], $pocketImport->getSummary()); + $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $pocketImport->getSummary()); } /** @@ -365,7 +365,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase $res = $pocketImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 2], $pocketImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 2, 'queued' => 0], $pocketImport->getSummary()); } /** @@ -451,7 +451,7 @@ JSON; $res = $pocketImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 1], $pocketImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $pocketImport->getSummary()); } /** @@ -530,7 +530,7 @@ JSON; $res = $pocketImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 1], $pocketImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $pocketImport->getSummary()); $this->assertNotEmpty($redisMock->lpop('pocket')); } @@ -607,6 +607,6 @@ JSON; $res = $pocketImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 1, 'imported' => 0], $pocketImport->getSummary()); + $this->assertEquals(['skipped' => 1, 'imported' => 0, 'queued' => 0], $pocketImport->getSummary()); } } diff --git a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php index 67917154..d98cd486 100644 --- a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php @@ -82,7 +82,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $res = $readabilityImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 24], $readabilityImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 24, 'queued' => 0], $readabilityImport->getSummary()); } public function testImportAndMarkAllAsRead() @@ -120,7 +120,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $this->assertTrue($res); - $this->assertEquals(['skipped' => 1, 'imported' => 1], $readabilityImport->getSummary()); + $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $readabilityImport->getSummary()); } public function testImportWithRabbit() @@ -160,7 +160,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $res = $readabilityImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 24], $readabilityImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 24], $readabilityImport->getSummary()); } public function testImportWithRedis() @@ -198,7 +198,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase $res = $readabilityImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 24], $readabilityImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 24], $readabilityImport->getSummary()); $this->assertNotEmpty($redisMock->lpop('readability')); } diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php index b43682cd..5ab4ad00 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php @@ -82,7 +82,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV1Import->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 1, 'imported' => 3], $wallabagV1Import->getSummary()); + $this->assertEquals(['skipped' => 1, 'imported' => 3, 'queued' => 0], $wallabagV1Import->getSummary()); } public function testImportAndMarkAllAsRead() @@ -120,7 +120,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 3], $wallabagV1Import->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 3, 'queued' => 0], $wallabagV1Import->getSummary()); } public function testImportWithRabbit() @@ -160,7 +160,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV1Import->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 4], $wallabagV1Import->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $wallabagV1Import->getSummary()); } public function testImportWithRedis() @@ -198,7 +198,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV1Import->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 4], $wallabagV1Import->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $wallabagV1Import->getSummary()); $this->assertNotEmpty($redisMock->lpop('wallabag_v1')); } diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php index 18998b35..b4017f72 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php @@ -78,7 +78,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV2Import->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 22, 'imported' => 2], $wallabagV2Import->getSummary()); + $this->assertEquals(['skipped' => 22, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); } public function testImportAndMarkAllAsRead() @@ -116,7 +116,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 2], $wallabagV2Import->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); } public function testImportWithRabbit() @@ -152,7 +152,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV2Import->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 24], $wallabagV2Import->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 24], $wallabagV2Import->getSummary()); } public function testImportWithRedis() @@ -186,7 +186,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV2Import->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 24], $wallabagV2Import->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 24], $wallabagV2Import->getSummary()); $this->assertNotEmpty($redisMock->lpop('wallabag_v2')); } @@ -227,7 +227,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV2Import->import(); $this->assertFalse($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0], $wallabagV2Import->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 0], $wallabagV2Import->getSummary()); } public function testImportWithExceptionFromGraby() @@ -256,6 +256,6 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV2Import->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 24, 'imported' => 0], $wallabagV2Import->getSummary()); + $this->assertEquals(['skipped' => 24, 'imported' => 0, 'queued' => 0], $wallabagV2Import->getSummary()); } } -- cgit v1.2.3 From 47d7c682a453a4831c07db926d22461f310642c6 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 13 Sep 2016 22:27:27 +0200 Subject: =?UTF-8?q?Add=20more=20=E2=80=9Creal=E2=80=9D=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/ReadabilityControllerTest.php | 39 ++++++++++++++++------ .../Controller/WallabagV1ControllerTest.php | 39 ++++++++++++++++------ .../Controller/WallabagV2ControllerTest.php | 39 ++++++++++++++++------ 3 files changed, 87 insertions(+), 30 deletions(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php index fb835f62..7b88d891 100644 --- a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php @@ -35,37 +35,56 @@ class ReadabilityControllerTest extends WallabagCoreTestCase $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0); } - public function testImportReadabilityWithRedisEnabled() + public function testImportReadabilityBadFile() { $this->logInAs('admin'); $client = $this->getClient(); - $client->getContainer()->get('craue_config')->set('import_with_redis', 1); - $crawler = $client->request('GET', '/import/readability'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); - $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + $data = [ + 'upload_import_file[file]' => '', + ]; - $client->getContainer()->get('craue_config')->set('import_with_redis', 0); + $client->submit($form, $data); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); } - public function testImportReadabilityBadFile() + public function testImportReadabilityWithRedisEnabled() { $this->logInAs('admin'); $client = $this->getClient(); + $client->getContainer()->get('craue_config')->set('import_with_redis', 1); + $crawler = $client->request('GET', '/import/readability'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + $file = new UploadedFile(__DIR__.'/../fixtures/readability.json', 'readability.json'); + $data = [ - 'upload_import_file[file]' => '', + 'upload_import_file[file]' => $file, ]; $client->submit($form, $data); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + + $this->assertNotEmpty($client->getContainer()->get('wallabag_core.redis.client')->lpop('wallabag.import.readability')); + + $client->getContainer()->get('craue_config')->set('import_with_redis', 0); } public function testImportReadabilityWithFile() diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php index f1113365..98e85d45 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php @@ -35,37 +35,56 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0); } - public function testImportWallabagWithRedisEnabled() + public function testImportWallabagBadFile() { $this->logInAs('admin'); $client = $this->getClient(); - $client->getContainer()->get('craue_config')->set('import_with_redis', 1); - $crawler = $client->request('GET', '/import/wallabag-v1'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); - $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + $data = [ + 'upload_import_file[file]' => '', + ]; - $client->getContainer()->get('craue_config')->set('import_with_redis', 0); + $client->submit($form, $data); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); } - public function testImportWallabagBadFile() + public function testImportWallabagWithRedisEnabled() { $this->logInAs('admin'); $client = $this->getClient(); + $client->getContainer()->get('craue_config')->set('import_with_redis', 1); + $crawler = $client->request('GET', '/import/wallabag-v1'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + $file = new UploadedFile(__DIR__.'/../fixtures/wallabag-v1.json', 'wallabag-v1.json'); + $data = [ - 'upload_import_file[file]' => '', + 'upload_import_file[file]' => $file, ]; $client->submit($form, $data); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + + $this->assertNotEmpty($client->getContainer()->get('wallabag_core.redis.client')->lpop('wallabag.import.wallabag_v1')); + + $client->getContainer()->get('craue_config')->set('import_with_redis', 0); } public function testImportWallabagWithFile() diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php index ca20c85b..74d61f9a 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php @@ -35,37 +35,56 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0); } - public function testImportWallabagWithRedisEnabled() + public function testImportWallabagBadFile() { $this->logInAs('admin'); $client = $this->getClient(); - $client->getContainer()->get('craue_config')->set('import_with_redis', 1); - $crawler = $client->request('GET', '/import/wallabag-v2'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); - $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + $data = [ + 'upload_import_file[file]' => '', + ]; - $client->getContainer()->get('craue_config')->set('import_with_redis', 0); + $client->submit($form, $data); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); } - public function testImportWallabagBadFile() + public function testImportWallabagWithRedisEnabled() { $this->logInAs('admin'); $client = $this->getClient(); + $client->getContainer()->get('craue_config')->set('import_with_redis', 1); + $crawler = $client->request('GET', '/import/wallabag-v2'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + $file = new UploadedFile(__DIR__.'/../fixtures/wallabag-v2.json', 'wallabag-v2.json'); + $data = [ - 'upload_import_file[file]' => '', + 'upload_import_file[file]' => $file, ]; $client->submit($form, $data); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + + $this->assertNotEmpty($client->getContainer()->get('wallabag_core.redis.client')->lpop('wallabag.import.wallabag_v2')); + + $client->getContainer()->get('craue_config')->set('import_with_redis', 0); } public function testImportWallabagWithFile() -- cgit v1.2.3 From ac87e0db2ac5db90f1b0639a2d31c7098b4eaa20 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 14 Sep 2016 10:17:22 +0200 Subject: AMPQ -> AMQP --- .../Consumer/AMPQEntryConsumerTest.php | 225 --------------------- .../Consumer/AMQPEntryConsumerTest.php | 225 +++++++++++++++++++++ 2 files changed, 225 insertions(+), 225 deletions(-) delete mode 100644 tests/Wallabag/ImportBundle/Consumer/AMPQEntryConsumerTest.php create mode 100644 tests/Wallabag/ImportBundle/Consumer/AMQPEntryConsumerTest.php (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ImportBundle/Consumer/AMPQEntryConsumerTest.php b/tests/Wallabag/ImportBundle/Consumer/AMPQEntryConsumerTest.php deleted file mode 100644 index b13ade1d..00000000 --- a/tests/Wallabag/ImportBundle/Consumer/AMPQEntryConsumerTest.php +++ /dev/null @@ -1,225 +0,0 @@ -getMockBuilder('Doctrine\ORM\EntityManager') - ->disableOriginalConstructor() - ->getMock(); - - $em - ->expects($this->once()) - ->method('flush'); - - $em - ->expects($this->exactly(2)) - ->method('clear'); - - $body = <<<'JSON' -{ - "item_id": "1402935436", - "resolved_id": "1402935436", - "given_url": "http://mashable.com/2016/09/04/leslie-jones-back-on-twitter-after-hack/?utm_campaign=Mash-Prod-RSS-Feedburner-All-Partial&utm_cid=Mash-Prod-RSS-Feedburner-All-Partial", - "given_title": "Leslie Jones is back on Twitter and her comeback tweet rules", - "favorite": "0", - "status": "0", - "time_added": "1473020899", - "time_updated": "1473020899", - "time_read": "0", - "time_favorited": "0", - "sort_id": 0, - "resolved_title": "Leslie Jones is back on Twitter and her comeback tweet rules", - "resolved_url": "http://mashable.com/2016/09/04/leslie-jones-back-on-twitter-after-hack/?utm_campaign=Mash-Prod-RSS-Feedburner-All-Partial&utm_cid=Mash-Prod-RSS-Feedburner-All-Partial", - "excerpt": "Leslie Jones is back to communicating with her adoring public on Twitter after cowardly hacker-trolls drove her away, probably to compensate for their own failings. It all started with a mic drop ...", - "is_article": "1", - "is_index": "0", - "has_video": "0", - "has_image": "1", - "word_count": "200", - "tags": { - "ifttt": { - "item_id": "1402935436", - "tag": "ifttt" - }, - "mashable": { - "item_id": "1402935436", - "tag": "mashable" - } - }, - "authors": { - "2484273": { - "item_id": "1402935436", - "author_id": "2484273", - "name": "Adam Rosenberg", - "url": "http://mashable.com/author/adam-rosenberg/" - } - }, - "image": { - "item_id": "1402935436", - "src": "http://i.amz.mshcdn.com/i-V5cS6_sDqFABaVR0hVSBJqG_w=/950x534/https%3A%2F%2Fblueprint-api-production.s3.amazonaws.com%2Fuploads%2Fcard%2Fimage%2F199899%2Fleslie_jones_war_dogs.jpg", - "width": "0", - "height": "0" - }, - "images": { - "1": { - "item_id": "1402935436", - "image_id": "1", - "src": "http://i.amz.mshcdn.com/i-V5cS6_sDqFABaVR0hVSBJqG_w=/950x534/https%3A%2F%2Fblueprint-api-production.s3.amazonaws.com%2Fuploads%2Fcard%2Fimage%2F199899%2Fleslie_jones_war_dogs.jpg", - "width": "0", - "height": "0", - "credit": "Image: Steve Eichner/NameFace/Sipa USA", - "caption": "" - } - }, - "userId": 1 -} -JSON; - - $user = new User(); - $entry = new Entry($user); - - $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') - ->disableOriginalConstructor() - ->getMock(); - - $userRepository - ->expects($this->once()) - ->method('find') - // userId from the body json above - ->with(1) - ->willReturn($user); - - $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') - ->disableOriginalConstructor() - ->getMock(); - - $import - ->expects($this->once()) - ->method('setUser') - ->with($user); - - $import - ->expects($this->once()) - ->method('parseEntry') - ->with(json_decode($body, true)) - ->willReturn($entry); - - $consumer = new AMPQEntryConsumer( - $em, - $userRepository, - $import - ); - - $message = new AMQPMessage($body); - - $consumer->execute($message); - } - - public function testMessageWithBadUser() - { - $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') - ->disableOriginalConstructor() - ->getMock(); - - $em - ->expects($this->never()) - ->method('flush'); - - $em - ->expects($this->never()) - ->method('clear'); - - $body = '{ "userId": 123 }'; - - $user = new User(); - $entry = new Entry($user); - - $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') - ->disableOriginalConstructor() - ->getMock(); - - $userRepository - ->expects($this->once()) - ->method('find') - // userId from the body json above - ->with(123) - ->willReturn(null); - - $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') - ->disableOriginalConstructor() - ->getMock(); - - $consumer = new AMPQEntryConsumer( - $em, - $userRepository, - $import - ); - - $message = new AMQPMessage($body); - - $consumer->execute($message); - } - - public function testMessageWithEntryProcessed() - { - $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') - ->disableOriginalConstructor() - ->getMock(); - - $em - ->expects($this->never()) - ->method('flush'); - - $em - ->expects($this->never()) - ->method('clear'); - - $body = '{ "userId": 123 }'; - - $user = new User(); - - $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') - ->disableOriginalConstructor() - ->getMock(); - - $userRepository - ->expects($this->once()) - ->method('find') - // userId from the body json above - ->with(123) - ->willReturn($user); - - $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') - ->disableOriginalConstructor() - ->getMock(); - - $import - ->expects($this->once()) - ->method('setUser') - ->with($user); - - $import - ->expects($this->once()) - ->method('parseEntry') - ->with(json_decode($body, true)) - ->willReturn(null); - - $consumer = new AMPQEntryConsumer( - $em, - $userRepository, - $import - ); - - $message = new AMQPMessage($body); - - $consumer->execute($message); - } -} diff --git a/tests/Wallabag/ImportBundle/Consumer/AMQPEntryConsumerTest.php b/tests/Wallabag/ImportBundle/Consumer/AMQPEntryConsumerTest.php new file mode 100644 index 00000000..a3263771 --- /dev/null +++ b/tests/Wallabag/ImportBundle/Consumer/AMQPEntryConsumerTest.php @@ -0,0 +1,225 @@ +getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $em + ->expects($this->once()) + ->method('flush'); + + $em + ->expects($this->exactly(2)) + ->method('clear'); + + $body = <<<'JSON' +{ + "item_id": "1402935436", + "resolved_id": "1402935436", + "given_url": "http://mashable.com/2016/09/04/leslie-jones-back-on-twitter-after-hack/?utm_campaign=Mash-Prod-RSS-Feedburner-All-Partial&utm_cid=Mash-Prod-RSS-Feedburner-All-Partial", + "given_title": "Leslie Jones is back on Twitter and her comeback tweet rules", + "favorite": "0", + "status": "0", + "time_added": "1473020899", + "time_updated": "1473020899", + "time_read": "0", + "time_favorited": "0", + "sort_id": 0, + "resolved_title": "Leslie Jones is back on Twitter and her comeback tweet rules", + "resolved_url": "http://mashable.com/2016/09/04/leslie-jones-back-on-twitter-after-hack/?utm_campaign=Mash-Prod-RSS-Feedburner-All-Partial&utm_cid=Mash-Prod-RSS-Feedburner-All-Partial", + "excerpt": "Leslie Jones is back to communicating with her adoring public on Twitter after cowardly hacker-trolls drove her away, probably to compensate for their own failings. It all started with a mic drop ...", + "is_article": "1", + "is_index": "0", + "has_video": "0", + "has_image": "1", + "word_count": "200", + "tags": { + "ifttt": { + "item_id": "1402935436", + "tag": "ifttt" + }, + "mashable": { + "item_id": "1402935436", + "tag": "mashable" + } + }, + "authors": { + "2484273": { + "item_id": "1402935436", + "author_id": "2484273", + "name": "Adam Rosenberg", + "url": "http://mashable.com/author/adam-rosenberg/" + } + }, + "image": { + "item_id": "1402935436", + "src": "http://i.amz.mshcdn.com/i-V5cS6_sDqFABaVR0hVSBJqG_w=/950x534/https%3A%2F%2Fblueprint-api-production.s3.amazonaws.com%2Fuploads%2Fcard%2Fimage%2F199899%2Fleslie_jones_war_dogs.jpg", + "width": "0", + "height": "0" + }, + "images": { + "1": { + "item_id": "1402935436", + "image_id": "1", + "src": "http://i.amz.mshcdn.com/i-V5cS6_sDqFABaVR0hVSBJqG_w=/950x534/https%3A%2F%2Fblueprint-api-production.s3.amazonaws.com%2Fuploads%2Fcard%2Fimage%2F199899%2Fleslie_jones_war_dogs.jpg", + "width": "0", + "height": "0", + "credit": "Image: Steve Eichner/NameFace/Sipa USA", + "caption": "" + } + }, + "userId": 1 +} +JSON; + + $user = new User(); + $entry = new Entry($user); + + $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') + ->disableOriginalConstructor() + ->getMock(); + + $userRepository + ->expects($this->once()) + ->method('find') + // userId from the body json above + ->with(1) + ->willReturn($user); + + $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') + ->disableOriginalConstructor() + ->getMock(); + + $import + ->expects($this->once()) + ->method('setUser') + ->with($user); + + $import + ->expects($this->once()) + ->method('parseEntry') + ->with(json_decode($body, true)) + ->willReturn($entry); + + $consumer = new AMQPEntryConsumer( + $em, + $userRepository, + $import + ); + + $message = new AMQPMessage($body); + + $consumer->execute($message); + } + + public function testMessageWithBadUser() + { + $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $em + ->expects($this->never()) + ->method('flush'); + + $em + ->expects($this->never()) + ->method('clear'); + + $body = '{ "userId": 123 }'; + + $user = new User(); + $entry = new Entry($user); + + $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') + ->disableOriginalConstructor() + ->getMock(); + + $userRepository + ->expects($this->once()) + ->method('find') + // userId from the body json above + ->with(123) + ->willReturn(null); + + $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') + ->disableOriginalConstructor() + ->getMock(); + + $consumer = new AMQPEntryConsumer( + $em, + $userRepository, + $import + ); + + $message = new AMQPMessage($body); + + $consumer->execute($message); + } + + public function testMessageWithEntryProcessed() + { + $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $em + ->expects($this->never()) + ->method('flush'); + + $em + ->expects($this->never()) + ->method('clear'); + + $body = '{ "userId": 123 }'; + + $user = new User(); + + $userRepository = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') + ->disableOriginalConstructor() + ->getMock(); + + $userRepository + ->expects($this->once()) + ->method('find') + // userId from the body json above + ->with(123) + ->willReturn($user); + + $import = $this->getMockBuilder('Wallabag\ImportBundle\Import\AbstractImport') + ->disableOriginalConstructor() + ->getMock(); + + $import + ->expects($this->once()) + ->method('setUser') + ->with($user); + + $import + ->expects($this->once()) + ->method('parseEntry') + ->with(json_decode($body, true)) + ->willReturn(null); + + $consumer = new AMQPEntryConsumer( + $em, + $userRepository, + $import + ); + + $message = new AMQPMessage($body); + + $consumer->execute($message); + } +} -- cgit v1.2.3 From ebe0787e093f4f2934430033015d6ebad1c64dca Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 16 Sep 2016 22:22:25 +0200 Subject: Moved Pocket token to user config --- .../Wallabag/ImportBundle/Import/PocketImportTest.php | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index a3f68892..48fbbfb6 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php @@ -4,6 +4,7 @@ namespace Tests\Wallabag\ImportBundle\Import; use Wallabag\UserBundle\Entity\User; use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\CoreBundle\Entity\Config; use Wallabag\ImportBundle\Import\PocketImport; use GuzzleHttp\Client; use GuzzleHttp\Subscriber\Mock; @@ -27,6 +28,11 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase { $this->user = new User(); + $config = new Config($this->user); + $config->setPocketConsumerKey('xxx'); + + $this->user->setConfig($config); + $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') ->disableOriginalConstructor() ->getMock(); @@ -35,19 +41,9 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); - $config = $this->getMockBuilder('Craue\ConfigBundle\Util\Config') - ->disableOriginalConstructor() - ->getMock(); - - $config->expects($this->any()) - ->method('get') - ->with('pocket_consumer_key') - ->willReturn($consumerKey); - $pocket = new PocketImport( $this->em, - $this->contentProxy, - $config + $this->contentProxy ); $pocket->setUser($this->user); -- cgit v1.2.3 From 59b97fae996d8307b9d957d210d46200f6d206bf Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 17 Sep 2016 07:40:56 +0200 Subject: Avoid losing entry when fetching fail MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of just say “Failed to save entry” we’ll save the entry at all cost and try to fetch content. If fetching content failed, the entry will still be saved at least, but without content. --- tests/Wallabag/ImportBundle/Import/PocketImportTest.php | 4 +++- tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index 48fbbfb6..952521a2 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php @@ -566,6 +566,8 @@ JSON; "status": 1, "list": { "229279689": { + "status": "1", + "favorite": "1", "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview" } } @@ -603,6 +605,6 @@ JSON; $res = $pocketImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 1, 'imported' => 0, 'queued' => 0], $pocketImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 1, 'queued' => 0], $pocketImport->getSummary()); } } diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php index b4017f72..12bd6bdd 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php @@ -256,6 +256,6 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase $res = $wallabagV2Import->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 24, 'imported' => 0, 'queued' => 0], $wallabagV2Import->getSummary()); + $this->assertEquals(['skipped' => 22, 'imported' => 2, 'queued' => 0], $wallabagV2Import->getSummary()); } } -- cgit v1.2.3 From 0e0102b6fcd17266f39dd63a808740d01ab9bd8a Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 24 Sep 2016 19:57:59 +0200 Subject: =?UTF-8?q?Avoid=20failing=20test=20for=20user=20who=20didn?= =?UTF-8?q?=E2=80=99t=20install=20Redis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Wallabag/CoreBundle/WallabagCoreTestCase.php | 15 +++++++++++++++ .../ImportBundle/Controller/PocketControllerTest.php | 1 + .../ImportBundle/Controller/ReadabilityControllerTest.php | 1 + .../ImportBundle/Controller/WallabagV1ControllerTest.php | 1 + .../ImportBundle/Controller/WallabagV2ControllerTest.php | 1 + 5 files changed, 19 insertions(+) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php index c0055888..75b7ee0b 100644 --- a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php +++ b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php @@ -80,4 +80,19 @@ abstract class WallabagCoreTestCase extends WebTestCase throw new \RuntimeException('No logged in User.'); } + + /** + * Check if Redis is installed. + * If not, mark test as skip + */ + protected function checkRedis() + { + try { + $this->client->getContainer()->get('wallabag_core.redis.client')->connect(); + } catch (\Exception $e) { + $this->markTestSkipped( + 'Redis is not installed/activated' + ); + } + } } diff --git a/tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php b/tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php index 35673261..7d6a300f 100644 --- a/tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php @@ -34,6 +34,7 @@ class PocketControllerTest extends WallabagCoreTestCase public function testImportPocketWithRedisEnabled() { + $this->checkRedis(); $this->logInAs('admin'); $client = $this->getClient(); diff --git a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php index 7b88d891..87ecb9d3 100644 --- a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php @@ -54,6 +54,7 @@ class ReadabilityControllerTest extends WallabagCoreTestCase public function testImportReadabilityWithRedisEnabled() { + $this->checkRedis(); $this->logInAs('admin'); $client = $this->getClient(); diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php index 98e85d45..3497c4b8 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php @@ -54,6 +54,7 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase public function testImportWallabagWithRedisEnabled() { + $this->checkRedis(); $this->logInAs('admin'); $client = $this->getClient(); diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php index 74d61f9a..27d2d52b 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php @@ -54,6 +54,7 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase public function testImportWallabagWithRedisEnabled() { + $this->checkRedis(); $this->logInAs('admin'); $client = $this->getClient(); -- cgit v1.2.3 From 401135852c6b25c8d5ab97beaefb02d1bd023ec9 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 25 Sep 2016 11:26:15 +0200 Subject: Use scheduled entity insertions to avoid tag duplicate Using `getScheduledEntityInsertions()` we can retrieve not yet flushed but already persisted entities and then avoid tags duplication on import. --- .../CoreBundle/Helper/ContentProxyTest.php | 23 ++++++++++++++++++++++ .../ImportBundle/Import/PocketImportTest.php | 14 +++++++++++++ .../ImportBundle/Import/WallabagV1ImportTest.php | 14 +++++++++++++ .../ImportBundle/Import/WallabagV2ImportTest.php | 14 +++++++++++++ 4 files changed, 65 insertions(+) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index 7abb0737..5d772602 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php @@ -296,6 +296,29 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $this->assertEquals('tag2', $entry->getTags()[1]->getLabel()); } + public function testAssignTagsNotFlushed() + { + $graby = $this->getMockBuilder('Graby\Graby') + ->disableOriginalConstructor() + ->getMock(); + + $tagRepo = $this->getTagRepositoryMock(); + $tagRepo->expects($this->never()) + ->method('__call'); + + $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger()); + + $tagEntity = new Tag(); + $tagEntity->setLabel('tag1'); + + $entry = new Entry(new User()); + + $proxy->assignTagsToEntry($entry, 'tag1', [$tagEntity]); + + $this->assertCount(1, $entry->getTags()); + $this->assertEquals('tag1', $entry->getTags()[0]->getLabel()); + } + private function getTaggerMock() { return $this->getMockBuilder('Wallabag\CoreBundle\Helper\RuleBasedTagger') diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index 952521a2..9ec7935c 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php @@ -41,6 +41,20 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); + $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork') + ->disableOriginalConstructor() + ->getMock(); + + $this->em + ->expects($this->any()) + ->method('getUnitOfWork') + ->willReturn($this->uow); + + $this->uow + ->expects($this->any()) + ->method('getScheduledEntityInsertions') + ->willReturn([]); + $pocket = new PocketImport( $this->em, $this->contentProxy diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php index 5ab4ad00..82dc4c7e 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php @@ -26,6 +26,20 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); + $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork') + ->disableOriginalConstructor() + ->getMock(); + + $this->em + ->expects($this->any()) + ->method('getUnitOfWork') + ->willReturn($this->uow); + + $this->uow + ->expects($this->any()) + ->method('getScheduledEntityInsertions') + ->willReturn([]); + $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') ->disableOriginalConstructor() ->getMock(); diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php index 12bd6bdd..bea89efb 100644 --- a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php @@ -26,6 +26,20 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); + $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork') + ->disableOriginalConstructor() + ->getMock(); + + $this->em + ->expects($this->any()) + ->method('getUnitOfWork') + ->willReturn($this->uow); + + $this->uow + ->expects($this->any()) + ->method('getScheduledEntityInsertions') + ->willReturn([]); + $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') ->disableOriginalConstructor() ->getMock(); -- cgit v1.2.3 From ae669126e718ede5dbf76929215d8514cd960976 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Tue, 12 Jul 2016 13:51:05 +0200 Subject: Import Firefox & Chrome bookmarks into wallabag --- .../Controller/BrowserControllerTest.php | 94 ++++++++++++++++++++++ tests/Wallabag/ImportBundle/fixtures/Bookmarks | 61 ++++++++++++++ 2 files changed, 155 insertions(+) create mode 100644 tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php create mode 100644 tests/Wallabag/ImportBundle/fixtures/Bookmarks (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php b/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php new file mode 100644 index 00000000..8016227c --- /dev/null +++ b/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php @@ -0,0 +1,94 @@ +logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/browser'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + } + + public function testImportWallabagWithFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/browser'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/Bookmarks', 'Bookmarks'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId( + 'http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html', + $this->getLoggedInUserId() + ); + + $this->assertNotEmpty($content->getMimetype()); + $this->assertNotEmpty($content->getPreviewPicture()); + $this->assertNotEmpty($content->getLanguage()); + $this->assertEquals(0, count($content->getTags())); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId( + 'http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java', + $this->getLoggedInUserId() + ); + + $this->assertNotEmpty($content->getMimetype()); + $this->assertNotEmpty($content->getPreviewPicture()); + $this->assertEmpty($content->getLanguage()); + } + + public function testImportWallabagWithEmptyFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/browser'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.failed', $body[0]); + } +} diff --git a/tests/Wallabag/ImportBundle/fixtures/Bookmarks b/tests/Wallabag/ImportBundle/fixtures/Bookmarks new file mode 100644 index 00000000..8b78b8a4 --- /dev/null +++ b/tests/Wallabag/ImportBundle/fixtures/Bookmarks @@ -0,0 +1,61 @@ +{ + "checksum": "ef1e30cddf64cb94c63d7835640165be", + "roots": { + "bookmark_bar": { + "children": [ { + "date_added": "13112787540531997", + "id": "7", + "name": "Terrorisme: les sombres prédictions du directeur de la DGSI", + "type": "url", + "url": "http://www.lefigaro.fr/actualite-france/2016/07/12/01016-20160712ARTFIG00016-terrorisme-les-sombres-perspectives-de-patrick-calvar-directeur-de-la-dgsi.php" + } ], + "date_added": "13112787380480144", + "date_modified": "13112787542724942", + "id": "1", + "name": "Bookmarks bar", + "type": "folder" + }, + "other": { + "children": [ { + "date_added": "13112787503900822", + "id": "6", + "name": "Parser for Exported Bookmarks HTML file of Google Chrome and Mozilla in Java - Stack Overflow", + "type": "url", + "url": "http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java" + }, { + "children": [ { + "date_added": "13112787564443378", + "id": "9", + "name": "Orange offre un meilleur réseau mobile que Bouygues et SFR, Free derrière - L'Express L'Expansion", + "type": "url", + "url": "http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html" + } ], + "date_added": "13112787556763735", + "date_modified": "13112794390493325", + "id": "8", + "name": "test", + "type": "folder" + }, { + "date_added": "13112794390493325", + "id": "12", + "name": "JSON Formatter & Validator", + "type": "url", + "url": "https://jsonformatter.curiousconcept.com/" + } ], + "date_added": "13112787380480151", + "date_modified": "13112794393509988", + "id": "2", + "name": "Other bookmarks", + "type": "folder" + }, + "synced": { + "children": [ ], + "date_added": "13112787380480155", + "date_modified": "0", + "id": "3", + "name": "Mobile bookmarks", + "type": "folder" + } + }, + "version": 1 +} -- cgit v1.2.3 From efe659ab84df5db23d95203c0cef8c43ed0914e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 2 Sep 2016 13:53:45 +0200 Subject: Add Chrome path for Mac OS --- tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php index d869cdf9..23a7c877 100644 --- a/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php @@ -24,6 +24,6 @@ class ImportControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/import/'); $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->assertEquals(4, $crawler->filter('blockquote')->count()); + $this->assertEquals(5, $crawler->filter('blockquote')->count()); } } -- cgit v1.2.3 From 06d13ddfbc6dad568bb28d5c33daab9e54dc6669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 2 Sep 2016 15:21:07 +0200 Subject: Indentation and renamed fixtures file --- .../Controller/BrowserControllerTest.php | 2 +- tests/Wallabag/ImportBundle/fixtures/Bookmarks | 61 ---------------------- .../Wallabag/ImportBundle/fixtures/bookmarks.json | 61 ++++++++++++++++++++++ 3 files changed, 62 insertions(+), 62 deletions(-) delete mode 100644 tests/Wallabag/ImportBundle/fixtures/Bookmarks create mode 100644 tests/Wallabag/ImportBundle/fixtures/bookmarks.json (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php b/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php index 8016227c..46c831f8 100644 --- a/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php @@ -27,7 +27,7 @@ class BrowserControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/import/browser'); $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); - $file = new UploadedFile(__DIR__.'/../fixtures/Bookmarks', 'Bookmarks'); + $file = new UploadedFile(__DIR__.'/../fixtures/bookmarks.json', 'Bookmarks'); $data = [ 'upload_import_file[file]' => $file, diff --git a/tests/Wallabag/ImportBundle/fixtures/Bookmarks b/tests/Wallabag/ImportBundle/fixtures/Bookmarks deleted file mode 100644 index 8b78b8a4..00000000 --- a/tests/Wallabag/ImportBundle/fixtures/Bookmarks +++ /dev/null @@ -1,61 +0,0 @@ -{ - "checksum": "ef1e30cddf64cb94c63d7835640165be", - "roots": { - "bookmark_bar": { - "children": [ { - "date_added": "13112787540531997", - "id": "7", - "name": "Terrorisme: les sombres prédictions du directeur de la DGSI", - "type": "url", - "url": "http://www.lefigaro.fr/actualite-france/2016/07/12/01016-20160712ARTFIG00016-terrorisme-les-sombres-perspectives-de-patrick-calvar-directeur-de-la-dgsi.php" - } ], - "date_added": "13112787380480144", - "date_modified": "13112787542724942", - "id": "1", - "name": "Bookmarks bar", - "type": "folder" - }, - "other": { - "children": [ { - "date_added": "13112787503900822", - "id": "6", - "name": "Parser for Exported Bookmarks HTML file of Google Chrome and Mozilla in Java - Stack Overflow", - "type": "url", - "url": "http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java" - }, { - "children": [ { - "date_added": "13112787564443378", - "id": "9", - "name": "Orange offre un meilleur réseau mobile que Bouygues et SFR, Free derrière - L'Express L'Expansion", - "type": "url", - "url": "http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html" - } ], - "date_added": "13112787556763735", - "date_modified": "13112794390493325", - "id": "8", - "name": "test", - "type": "folder" - }, { - "date_added": "13112794390493325", - "id": "12", - "name": "JSON Formatter & Validator", - "type": "url", - "url": "https://jsonformatter.curiousconcept.com/" - } ], - "date_added": "13112787380480151", - "date_modified": "13112794393509988", - "id": "2", - "name": "Other bookmarks", - "type": "folder" - }, - "synced": { - "children": [ ], - "date_added": "13112787380480155", - "date_modified": "0", - "id": "3", - "name": "Mobile bookmarks", - "type": "folder" - } - }, - "version": 1 -} diff --git a/tests/Wallabag/ImportBundle/fixtures/bookmarks.json b/tests/Wallabag/ImportBundle/fixtures/bookmarks.json new file mode 100644 index 00000000..8b78b8a4 --- /dev/null +++ b/tests/Wallabag/ImportBundle/fixtures/bookmarks.json @@ -0,0 +1,61 @@ +{ + "checksum": "ef1e30cddf64cb94c63d7835640165be", + "roots": { + "bookmark_bar": { + "children": [ { + "date_added": "13112787540531997", + "id": "7", + "name": "Terrorisme: les sombres prédictions du directeur de la DGSI", + "type": "url", + "url": "http://www.lefigaro.fr/actualite-france/2016/07/12/01016-20160712ARTFIG00016-terrorisme-les-sombres-perspectives-de-patrick-calvar-directeur-de-la-dgsi.php" + } ], + "date_added": "13112787380480144", + "date_modified": "13112787542724942", + "id": "1", + "name": "Bookmarks bar", + "type": "folder" + }, + "other": { + "children": [ { + "date_added": "13112787503900822", + "id": "6", + "name": "Parser for Exported Bookmarks HTML file of Google Chrome and Mozilla in Java - Stack Overflow", + "type": "url", + "url": "http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java" + }, { + "children": [ { + "date_added": "13112787564443378", + "id": "9", + "name": "Orange offre un meilleur réseau mobile que Bouygues et SFR, Free derrière - L'Express L'Expansion", + "type": "url", + "url": "http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html" + } ], + "date_added": "13112787556763735", + "date_modified": "13112794390493325", + "id": "8", + "name": "test", + "type": "folder" + }, { + "date_added": "13112794390493325", + "id": "12", + "name": "JSON Formatter & Validator", + "type": "url", + "url": "https://jsonformatter.curiousconcept.com/" + } ], + "date_added": "13112787380480151", + "date_modified": "13112794393509988", + "id": "2", + "name": "Other bookmarks", + "type": "folder" + }, + "synced": { + "children": [ ], + "date_added": "13112787380480155", + "date_modified": "0", + "id": "3", + "name": "Mobile bookmarks", + "type": "folder" + } + }, + "version": 1 +} -- cgit v1.2.3 From f7c55b38122cc593c2b58bb6425fca9d243b055e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 20 Sep 2016 16:45:13 +0200 Subject: Added tests for Chrome bookmarks import --- .../ImportBundle/Command/ImportCommandTest.php | 1 - .../Controller/BrowserControllerTest.php | 41 ++++++++++++++- .../Wallabag/ImportBundle/fixtures/bookmarks.json | 61 ---------------------- .../ImportBundle/fixtures/chrome-bookmarks | 36 +++++++++++++ .../ImportBundle/fixtures/firefox-bookmarks.json | 61 ++++++++++++++++++++++ 5 files changed, 136 insertions(+), 64 deletions(-) delete mode 100644 tests/Wallabag/ImportBundle/fixtures/bookmarks.json create mode 100644 tests/Wallabag/ImportBundle/fixtures/chrome-bookmarks create mode 100644 tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php b/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php index eb7fce79..7be1eb18 100644 --- a/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php +++ b/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php @@ -6,7 +6,6 @@ use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Tester\CommandTester; use Wallabag\ImportBundle\Command\ImportCommand; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; -use M6Web\Component\RedisMock\RedisMockFactory; class ImportCommandTest extends WallabagCoreTestCase { diff --git a/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php b/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php index 46c831f8..b686fcd9 100644 --- a/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php @@ -19,7 +19,7 @@ class BrowserControllerTest extends WallabagCoreTestCase $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); } - public function testImportWallabagWithFile() + public function testImportWallabagWithFirefoxFile() { $this->logInAs('admin'); $client = $this->getClient(); @@ -27,7 +27,7 @@ class BrowserControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/import/browser'); $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); - $file = new UploadedFile(__DIR__.'/../fixtures/bookmarks.json', 'Bookmarks'); + $file = new UploadedFile(__DIR__.'/../fixtures/firefox-bookmarks.json', 'Bookmarks'); $data = [ 'upload_import_file[file]' => $file, @@ -68,6 +68,43 @@ class BrowserControllerTest extends WallabagCoreTestCase $this->assertEmpty($content->getLanguage()); } + public function testImportWallabagWithChromeFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/browser'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/chrome-bookmarks', 'Bookmarks'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId( + 'http://www.usinenouvelle.com/article/la-multiplication-des-chefs-de-projet-est-une-catastrophe-manageriale-majeure-affirme-le-sociologue-francois-dupuy.N307730', + $this->getLoggedInUserId() + ); + + $this->assertNotEmpty($content->getMimetype()); + $this->assertNotEmpty($content->getPreviewPicture()); + $this->assertNotEmpty($content->getLanguage()); + $this->assertEquals(0, count($content->getTags())); + } + public function testImportWallabagWithEmptyFile() { $this->logInAs('admin'); diff --git a/tests/Wallabag/ImportBundle/fixtures/bookmarks.json b/tests/Wallabag/ImportBundle/fixtures/bookmarks.json deleted file mode 100644 index 8b78b8a4..00000000 --- a/tests/Wallabag/ImportBundle/fixtures/bookmarks.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "checksum": "ef1e30cddf64cb94c63d7835640165be", - "roots": { - "bookmark_bar": { - "children": [ { - "date_added": "13112787540531997", - "id": "7", - "name": "Terrorisme: les sombres prédictions du directeur de la DGSI", - "type": "url", - "url": "http://www.lefigaro.fr/actualite-france/2016/07/12/01016-20160712ARTFIG00016-terrorisme-les-sombres-perspectives-de-patrick-calvar-directeur-de-la-dgsi.php" - } ], - "date_added": "13112787380480144", - "date_modified": "13112787542724942", - "id": "1", - "name": "Bookmarks bar", - "type": "folder" - }, - "other": { - "children": [ { - "date_added": "13112787503900822", - "id": "6", - "name": "Parser for Exported Bookmarks HTML file of Google Chrome and Mozilla in Java - Stack Overflow", - "type": "url", - "url": "http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java" - }, { - "children": [ { - "date_added": "13112787564443378", - "id": "9", - "name": "Orange offre un meilleur réseau mobile que Bouygues et SFR, Free derrière - L'Express L'Expansion", - "type": "url", - "url": "http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html" - } ], - "date_added": "13112787556763735", - "date_modified": "13112794390493325", - "id": "8", - "name": "test", - "type": "folder" - }, { - "date_added": "13112794390493325", - "id": "12", - "name": "JSON Formatter & Validator", - "type": "url", - "url": "https://jsonformatter.curiousconcept.com/" - } ], - "date_added": "13112787380480151", - "date_modified": "13112794393509988", - "id": "2", - "name": "Other bookmarks", - "type": "folder" - }, - "synced": { - "children": [ ], - "date_added": "13112787380480155", - "date_modified": "0", - "id": "3", - "name": "Mobile bookmarks", - "type": "folder" - } - }, - "version": 1 -} diff --git a/tests/Wallabag/ImportBundle/fixtures/chrome-bookmarks b/tests/Wallabag/ImportBundle/fixtures/chrome-bookmarks new file mode 100644 index 00000000..0478eb41 --- /dev/null +++ b/tests/Wallabag/ImportBundle/fixtures/chrome-bookmarks @@ -0,0 +1,36 @@ +{ + "checksum": "f3aa0e9c0edad632a246f7e98ec64918", + "roots": { + "bookmark_bar": { + "children": [ { + "date_added": "13118850929335823", + "id": "6", + "name": "\"La multiplication des chefs de projet est une catastrophe managériale majeure\", affirme le sociologue François Dupuy - Ressources humaines", + "type": "url", + "url": "http://www.usinenouvelle.com/article/la-multiplication-des-chefs-de-projet-est-une-catastrophe-manageriale-majeure-affirme-le-sociologue-francois-dupuy.N307730" + } ], + "date_added": "13118829474385693", + "date_modified": "13118850929335823", + "id": "1", + "name": "Barre de favoris", + "type": "folder" + }, + "other": { + "children": [ ], + "date_added": "13118829474385701", + "date_modified": "0", + "id": "2", + "name": "Autres favoris", + "type": "folder" + }, + "synced": { + "children": [ ], + "date_added": "13118829474385702", + "date_modified": "0", + "id": "3", + "name": "Favoris sur mobile", + "type": "folder" + } + }, + "version": 1 +} diff --git a/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json b/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json new file mode 100644 index 00000000..8b78b8a4 --- /dev/null +++ b/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json @@ -0,0 +1,61 @@ +{ + "checksum": "ef1e30cddf64cb94c63d7835640165be", + "roots": { + "bookmark_bar": { + "children": [ { + "date_added": "13112787540531997", + "id": "7", + "name": "Terrorisme: les sombres prédictions du directeur de la DGSI", + "type": "url", + "url": "http://www.lefigaro.fr/actualite-france/2016/07/12/01016-20160712ARTFIG00016-terrorisme-les-sombres-perspectives-de-patrick-calvar-directeur-de-la-dgsi.php" + } ], + "date_added": "13112787380480144", + "date_modified": "13112787542724942", + "id": "1", + "name": "Bookmarks bar", + "type": "folder" + }, + "other": { + "children": [ { + "date_added": "13112787503900822", + "id": "6", + "name": "Parser for Exported Bookmarks HTML file of Google Chrome and Mozilla in Java - Stack Overflow", + "type": "url", + "url": "http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java" + }, { + "children": [ { + "date_added": "13112787564443378", + "id": "9", + "name": "Orange offre un meilleur réseau mobile que Bouygues et SFR, Free derrière - L'Express L'Expansion", + "type": "url", + "url": "http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html" + } ], + "date_added": "13112787556763735", + "date_modified": "13112794390493325", + "id": "8", + "name": "test", + "type": "folder" + }, { + "date_added": "13112794390493325", + "id": "12", + "name": "JSON Formatter & Validator", + "type": "url", + "url": "https://jsonformatter.curiousconcept.com/" + } ], + "date_added": "13112787380480151", + "date_modified": "13112794393509988", + "id": "2", + "name": "Other bookmarks", + "type": "folder" + }, + "synced": { + "children": [ ], + "date_added": "13112787380480155", + "date_modified": "0", + "id": "3", + "name": "Mobile bookmarks", + "type": "folder" + } + }, + "version": 1 +} -- cgit v1.2.3 From 59201088b4fc13fd361238396f630dabd9bd1990 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 21 Sep 2016 17:47:47 +0200 Subject: bring chrome and firefox as separate imports --- .../Controller/BrowserControllerTest.php | 131 ------------ .../Controller/ChromeControllerTest.php | 149 +++++++++++++ .../Controller/FirefoxControllerTest.php | 161 ++++++++++++++ .../Controller/ImportControllerTest.php | 2 +- .../Controller/ReadabilityControllerTest.php | 1 - .../ImportBundle/Import/ChromeImportTest.php | 233 +++++++++++++++++++++ .../ImportBundle/Import/FirefoxImportTest.php | 233 +++++++++++++++++++++ 7 files changed, 777 insertions(+), 133 deletions(-) delete mode 100644 tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php create mode 100644 tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php create mode 100644 tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php create mode 100644 tests/Wallabag/ImportBundle/Import/ChromeImportTest.php create mode 100644 tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php b/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php deleted file mode 100644 index b686fcd9..00000000 --- a/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php +++ /dev/null @@ -1,131 +0,0 @@ -logInAs('admin'); - $client = $this->getClient(); - - $crawler = $client->request('GET', '/import/browser'); - - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); - $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); - } - - public function testImportWallabagWithFirefoxFile() - { - $this->logInAs('admin'); - $client = $this->getClient(); - - $crawler = $client->request('GET', '/import/browser'); - $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); - - $file = new UploadedFile(__DIR__.'/../fixtures/firefox-bookmarks.json', 'Bookmarks'); - - $data = [ - 'upload_import_file[file]' => $file, - ]; - - $client->submit($form, $data); - - $this->assertEquals(302, $client->getResponse()->getStatusCode()); - - $crawler = $client->followRedirect(); - - $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); - $this->assertContains('flashes.import.notice.summary', $body[0]); - - $content = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId( - 'http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html', - $this->getLoggedInUserId() - ); - - $this->assertNotEmpty($content->getMimetype()); - $this->assertNotEmpty($content->getPreviewPicture()); - $this->assertNotEmpty($content->getLanguage()); - $this->assertEquals(0, count($content->getTags())); - - $content = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId( - 'http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java', - $this->getLoggedInUserId() - ); - - $this->assertNotEmpty($content->getMimetype()); - $this->assertNotEmpty($content->getPreviewPicture()); - $this->assertEmpty($content->getLanguage()); - } - - public function testImportWallabagWithChromeFile() - { - $this->logInAs('admin'); - $client = $this->getClient(); - - $crawler = $client->request('GET', '/import/browser'); - $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); - - $file = new UploadedFile(__DIR__.'/../fixtures/chrome-bookmarks', 'Bookmarks'); - - $data = [ - 'upload_import_file[file]' => $file, - ]; - - $client->submit($form, $data); - - $this->assertEquals(302, $client->getResponse()->getStatusCode()); - - $crawler = $client->followRedirect(); - - $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); - $this->assertContains('flashes.import.notice.summary', $body[0]); - - $content = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId( - 'http://www.usinenouvelle.com/article/la-multiplication-des-chefs-de-projet-est-une-catastrophe-manageriale-majeure-affirme-le-sociologue-francois-dupuy.N307730', - $this->getLoggedInUserId() - ); - - $this->assertNotEmpty($content->getMimetype()); - $this->assertNotEmpty($content->getPreviewPicture()); - $this->assertNotEmpty($content->getLanguage()); - $this->assertEquals(0, count($content->getTags())); - } - - public function testImportWallabagWithEmptyFile() - { - $this->logInAs('admin'); - $client = $this->getClient(); - - $crawler = $client->request('GET', '/import/browser'); - $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); - - $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt'); - - $data = [ - 'upload_import_file[file]' => $file, - ]; - - $client->submit($form, $data); - - $this->assertEquals(302, $client->getResponse()->getStatusCode()); - - $crawler = $client->followRedirect(); - - $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); - $this->assertContains('flashes.import.notice.failed', $body[0]); - } -} diff --git a/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php new file mode 100644 index 00000000..448e559f --- /dev/null +++ b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php @@ -0,0 +1,149 @@ +logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/chrome'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + } + + public function testImportChromeWithRabbitEnabled() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 1); + + $crawler = $client->request('GET', '/import/chrome'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + + $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0); + } + + public function testImportChromeBadFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/chrome'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $data = [ + 'upload_import_file[file]' => '', + ]; + + $client->submit($form, $data); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + } + + public function testImportChromeWithRedisEnabled() + { + $this->logInAs('admin'); + $client = $this->getClient(); + $client->getContainer()->get('craue_config')->set('import_with_redis', 1); + + $crawler = $client->request('GET', '/import/chrome'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/chrome-bookmarks', 'Bookmarks'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + + $this->assertNotEmpty($client->getContainer()->get('wallabag_core.redis.client')->lpop('wallabag.import.chrome')); + + $client->getContainer()->get('craue_config')->set('import_with_redis', 0); + } + + public function testImportWallabagWithChromeFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/chrome'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/chrome-bookmarks', 'Bookmarks'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId( + 'http://www.usinenouvelle.com/article/la-multiplication-des-chefs-de-projet-est-une-catastrophe-manageriale-majeure-affirme-le-sociologue-francois-dupuy.N307730', + $this->getLoggedInUserId() + ); + + $this->assertEmpty($content->getMimetype()); + $this->assertNotEmpty($content->getPreviewPicture()); + $this->assertNotEmpty($content->getLanguage()); + $this->assertEquals(0, count($content->getTags())); + } + + public function testImportWallabagWithEmptyFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/chrome'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.failed', $body[0]); + } +} diff --git a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php new file mode 100644 index 00000000..2de0aa09 --- /dev/null +++ b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php @@ -0,0 +1,161 @@ +logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/firefox'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + } + + public function testImportFirefoxWithRabbitEnabled() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 1); + + $crawler = $client->request('GET', '/import/firefox'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + + $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0); + } + + public function testImportFirefoxBadFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/firefox'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $data = [ + 'upload_import_file[file]' => '', + ]; + + $client->submit($form, $data); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + } + + public function testImportFirefoxWithRedisEnabled() + { + $this->logInAs('admin'); + $client = $this->getClient(); + $client->getContainer()->get('craue_config')->set('import_with_redis', 1); + + $crawler = $client->request('GET', '/import/firefox'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/firefox-bookmarks.json', 'Bookmarks'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + + $this->assertNotEmpty($client->getContainer()->get('wallabag_core.redis.client')->lpop('wallabag.import.firefox')); + + $client->getContainer()->get('craue_config')->set('import_with_redis', 0); + } + + public function testImportWallabagWithFirefoxFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/firefox'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/firefox-bookmarks.json', 'Bookmarks'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId( + 'http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html', + $this->getLoggedInUserId() + ); + + $this->assertNotEmpty($content->getMimetype()); + $this->assertNotEmpty($content->getPreviewPicture()); + $this->assertNotEmpty($content->getLanguage()); + $this->assertEquals(0, count($content->getTags())); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId( + 'http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java', + $this->getLoggedInUserId() + ); + + $this->assertNotEmpty($content->getMimetype()); + $this->assertNotEmpty($content->getPreviewPicture()); + $this->assertEmpty($content->getLanguage()); + } + + public function testImportWallabagWithEmptyFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/firefox'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.failed', $body[0]); + } +} diff --git a/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php index 23a7c877..b6783a56 100644 --- a/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php @@ -24,6 +24,6 @@ class ImportControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/import/'); $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->assertEquals(5, $crawler->filter('blockquote')->count()); + $this->assertEquals(6, $crawler->filter('blockquote')->count()); } } diff --git a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php index 87ecb9d3..916dd297 100644 --- a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php @@ -57,7 +57,6 @@ class ReadabilityControllerTest extends WallabagCoreTestCase $this->checkRedis(); $this->logInAs('admin'); $client = $this->getClient(); - $client->getContainer()->get('craue_config')->set('import_with_redis', 1); $crawler = $client->request('GET', '/import/readability'); diff --git a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php new file mode 100644 index 00000000..f781a4d2 --- /dev/null +++ b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php @@ -0,0 +1,233 @@ +user = new User(); + + $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') + ->disableOriginalConstructor() + ->getMock(); + + $wallabag = new ChromeImport($this->em, $this->contentProxy); + + $this->logHandler = new TestHandler(); + $logger = new Logger('test', [$this->logHandler]); + $wallabag->setLogger($logger); + + if (false === $unsetUser) { + $wallabag->setUser($this->user); + } + + return $wallabag; + } + + public function testInit() + { + $chromeImport = $this->getChromeImport(); + + $this->assertEquals('Chrome', $chromeImport->getName()); + $this->assertNotEmpty($chromeImport->getUrl()); + $this->assertEquals('import.chrome.description', $chromeImport->getDescription()); + } + + public function testImport() + { + $chromeImport = $this->getChromeImport(); + $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->exactly(4)) + ->method('findByUrlAndUserId') + ->willReturn(false); + + $this->em + ->expects($this->any()) + ->method('getRepository') + ->willReturn($entryRepo); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->exactly(4)) + ->method('updateEntry') + ->willReturn($entry); + + $res = $chromeImport->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 4, 'queued' => 0], $chromeImport->getSummary()); + } + + public function testImportAndMarkAllAsRead() + { + $chromeImport = $this->getChromeImport(); + $chromeImport->setFilepath(__DIR__.'/../fixtures/readability-read.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->exactly(2)) + ->method('findByUrlAndUserId') + ->will($this->onConsecutiveCalls(false, true)); + + $this->em + ->expects($this->any()) + ->method('getRepository') + ->willReturn($entryRepo); + + $this->contentProxy + ->expects($this->exactly(1)) + ->method('updateEntry') + ->willReturn(new Entry($this->user)); + + // check that every entry persisted are archived + $this->em + ->expects($this->any()) + ->method('persist') + ->with($this->callback(function ($persistedEntry) { + return $persistedEntry->isArchived(); + })); + + $res = $chromeImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + + $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary()); + } + + public function testImportWithRabbit() + { + $chromeImport = $this->getChromeImport(); + $chromeImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->never()) + ->method('findByUrlAndUserId'); + + $this->em + ->expects($this->never()) + ->method('getRepository'); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->never()) + ->method('updateEntry'); + + $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') + ->disableOriginalConstructor() + ->getMock(); + + $producer + ->expects($this->exactly(4)) + ->method('publish'); + + $chromeImport->setProducer($producer); + + $res = $readabilityImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $chromeImport->getSummary()); + } + + public function testImportWithRedis() + { + $chromeImport = $this->getReadabilityImport(); + $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->never()) + ->method('findByUrlAndUserId'); + + $this->em + ->expects($this->never()) + ->method('getRepository'); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->never()) + ->method('updateEntry'); + + $factory = new RedisMockFactory(); + $redisMock = $factory->getAdapter('Predis\Client', true); + + $queue = new RedisQueue($redisMock, 'chrome'); + $producer = new Producer($queue); + + $chromeImport->setProducer($producer); + + $res = $chromeImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $chromeImport->getSummary()); + + $this->assertNotEmpty($redisMock->lpop('chrome')); + } + + public function testImportBadFile() + { + $chromeImport = $this->getChromeImport(); + $chromeImport->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx'); + + $res = $chromeImport->import(); + + $this->assertFalse($res); + + $records = $this->logHandler->getRecords(); + $this->assertContains('ChromeImport: unable to read file', $records[0]['message']); + $this->assertEquals('ERROR', $records[0]['level_name']); + } + + public function testImportUserNotDefined() + { + $chromeImport = $this->getChromeImport(true); + $chromeImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + + $res = $chromeImport->import(); + + $this->assertFalse($res); + + $records = $this->logHandler->getRecords(); + $this->assertContains('ChromeImport: user is not defined', $records[0]['message']); + $this->assertEquals('ERROR', $records[0]['level_name']); + } +} diff --git a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php new file mode 100644 index 00000000..0b4a28b4 --- /dev/null +++ b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php @@ -0,0 +1,233 @@ +user = new User(); + + $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') + ->disableOriginalConstructor() + ->getMock(); + + $wallabag = new FirefoxImport($this->em, $this->contentProxy); + + $this->logHandler = new TestHandler(); + $logger = new Logger('test', [$this->logHandler]); + $wallabag->setLogger($logger); + + if (false === $unsetUser) { + $wallabag->setUser($this->user); + } + + return $wallabag; + } + + public function testInit() + { + $firefoxImport = $this->getFirefoxImport(); + + $this->assertEquals('Firefox', $firefoxImport->getName()); + $this->assertNotEmpty($firefoxImport->getUrl()); + $this->assertEquals('import.firefox.description', $firefoxImport->getDescription()); + } + + public function testImport() + { + $firefoxImport = $this->getFirefoxImport(); + $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->exactly(4)) + ->method('findByUrlAndUserId') + ->willReturn(false); + + $this->em + ->expects($this->any()) + ->method('getRepository') + ->willReturn($entryRepo); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->exactly(4)) + ->method('updateEntry') + ->willReturn($entry); + + $res = $firefoxImport->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 4, 'queued' => 0], $firefoxImport->getSummary()); + } + + public function testImportAndMarkAllAsRead() + { + $firefoxImport = $this->getFirefoxImport(); + $firefoxImport->setFilepath(__DIR__.'/../fixtures/readability-read.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->exactly(2)) + ->method('findByUrlAndUserId') + ->will($this->onConsecutiveCalls(false, true)); + + $this->em + ->expects($this->any()) + ->method('getRepository') + ->willReturn($entryRepo); + + $this->contentProxy + ->expects($this->exactly(1)) + ->method('updateEntry') + ->willReturn(new Entry($this->user)); + + // check that every entry persisted are archived + $this->em + ->expects($this->any()) + ->method('persist') + ->with($this->callback(function ($persistedEntry) { + return $persistedEntry->isArchived(); + })); + + $res = $firefoxImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + + $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary()); + } + + public function testImportWithRabbit() + { + $firefoxImport = $this->getFirefoxImport(); + $firefoxImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->never()) + ->method('findByUrlAndUserId'); + + $this->em + ->expects($this->never()) + ->method('getRepository'); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->never()) + ->method('updateEntry'); + + $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') + ->disableOriginalConstructor() + ->getMock(); + + $producer + ->expects($this->exactly(4)) + ->method('publish'); + + $firefoxImport->setProducer($producer); + + $res = $readabilityImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $firefoxImport->getSummary()); + } + + public function testImportWithRedis() + { + $firefoxImport = $this->getReadabilityImport(); + $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->never()) + ->method('findByUrlAndUserId'); + + $this->em + ->expects($this->never()) + ->method('getRepository'); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->never()) + ->method('updateEntry'); + + $factory = new RedisMockFactory(); + $redisMock = $factory->getAdapter('Predis\Client', true); + + $queue = new RedisQueue($redisMock, 'firefox'); + $producer = new Producer($queue); + + $firefoxImport->setProducer($producer); + + $res = $firefoxImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $firefoxImport->getSummary()); + + $this->assertNotEmpty($redisMock->lpop('firefox')); + } + + public function testImportBadFile() + { + $firefoxImport = $this->getFirefoxImport(); + $firefoxImport->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx'); + + $res = $firefoxImport->import(); + + $this->assertFalse($res); + + $records = $this->logHandler->getRecords(); + $this->assertContains('FirefoxImport: unable to read file', $records[0]['message']); + $this->assertEquals('ERROR', $records[0]['level_name']); + } + + public function testImportUserNotDefined() + { + $firefoxImport = $this->getFirefoxImport(true); + $firefoxImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + + $res = $firefoxImport->import(); + + $this->assertFalse($res); + + $records = $this->logHandler->getRecords(); + $this->assertContains('FirefoxImport: user is not defined', $records[0]['message']); + $this->assertEquals('ERROR', $records[0]['level_name']); + } +} -- cgit v1.2.3 From 64b1229b2d711e6b2f0e60de482802d9e86b912f Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 21 Sep 2016 19:24:19 +0200 Subject: fix tests --- .../Controller/ChromeControllerTest.php | 1 - .../ImportBundle/Import/ChromeImportTest.php | 30 +++++++++++----------- .../ImportBundle/Import/FirefoxImportTest.php | 24 ++++++++--------- 3 files changed, 27 insertions(+), 28 deletions(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php index 448e559f..8890c5b1 100644 --- a/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php @@ -117,7 +117,6 @@ class ChromeControllerTest extends WallabagCoreTestCase $this->getLoggedInUserId() ); - $this->assertEmpty($content->getMimetype()); $this->assertNotEmpty($content->getPreviewPicture()); $this->assertNotEmpty($content->getLanguage()); $this->assertEquals(0, count($content->getTags())); diff --git a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php index f781a4d2..1e52615c 100644 --- a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php @@ -61,7 +61,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); - $entryRepo->expects($this->exactly(4)) + $entryRepo->expects($this->exactly(1)) ->method('findByUrlAndUserId') ->willReturn(false); @@ -75,26 +75,26 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase ->getMock(); $this->contentProxy - ->expects($this->exactly(4)) + ->expects($this->exactly(1)) ->method('updateEntry') ->willReturn($entry); $res = $chromeImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 4, 'queued' => 0], $chromeImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary()); } public function testImportAndMarkAllAsRead() { $chromeImport = $this->getChromeImport(); - $chromeImport->setFilepath(__DIR__.'/../fixtures/readability-read.json'); + $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() ->getMock(); - $entryRepo->expects($this->exactly(2)) + $entryRepo->expects($this->exactly(1)) ->method('findByUrlAndUserId') ->will($this->onConsecutiveCalls(false, true)); @@ -120,13 +120,13 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $this->assertTrue($res); - $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary()); } public function testImportWithRabbit() { $chromeImport = $this->getChromeImport(); - $chromeImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -152,20 +152,20 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase ->getMock(); $producer - ->expects($this->exactly(4)) + ->expects($this->exactly(1)) ->method('publish'); $chromeImport->setProducer($producer); - $res = $readabilityImport->setMarkAsRead(true)->import(); + $res = $chromeImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $chromeImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $chromeImport->getSummary()); } public function testImportWithRedis() { - $chromeImport = $this->getReadabilityImport(); + $chromeImport = $this->getChromeImport(); $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') @@ -198,7 +198,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $res = $chromeImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $chromeImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $chromeImport->getSummary()); $this->assertNotEmpty($redisMock->lpop('chrome')); } @@ -213,21 +213,21 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $this->assertFalse($res); $records = $this->logHandler->getRecords(); - $this->assertContains('ChromeImport: unable to read file', $records[0]['message']); + $this->assertContains('Wallabag Browser Import: unable to read file', $records[0]['message']); $this->assertEquals('ERROR', $records[0]['level_name']); } public function testImportUserNotDefined() { $chromeImport = $this->getChromeImport(true); - $chromeImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); $res = $chromeImport->import(); $this->assertFalse($res); $records = $this->logHandler->getRecords(); - $this->assertContains('ChromeImport: user is not defined', $records[0]['message']); + $this->assertContains('Wallabag Browser Import: user is not defined', $records[0]['message']); $this->assertEquals('ERROR', $records[0]['level_name']); } } diff --git a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php index 0b4a28b4..e8f0f3c7 100644 --- a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php @@ -88,13 +88,13 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase public function testImportAndMarkAllAsRead() { $firefoxImport = $this->getFirefoxImport(); - $firefoxImport->setFilepath(__DIR__.'/../fixtures/readability-read.json'); + $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() ->getMock(); - $entryRepo->expects($this->exactly(2)) + $entryRepo->expects($this->exactly(4)) ->method('findByUrlAndUserId') ->will($this->onConsecutiveCalls(false, true)); @@ -120,13 +120,13 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase $this->assertTrue($res); - $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary()); + $this->assertEquals(['skipped' => 3, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary()); } public function testImportWithRabbit() { $firefoxImport = $this->getFirefoxImport(); - $firefoxImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -152,20 +152,20 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase ->getMock(); $producer - ->expects($this->exactly(4)) + ->expects($this->exactly(1)) ->method('publish'); $firefoxImport->setProducer($producer); - $res = $readabilityImport->setMarkAsRead(true)->import(); + $res = $firefoxImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $firefoxImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $firefoxImport->getSummary()); } public function testImportWithRedis() { - $firefoxImport = $this->getReadabilityImport(); + $firefoxImport = $this->getFirefoxImport(); $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') @@ -198,7 +198,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase $res = $firefoxImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $firefoxImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $firefoxImport->getSummary()); $this->assertNotEmpty($redisMock->lpop('firefox')); } @@ -213,21 +213,21 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase $this->assertFalse($res); $records = $this->logHandler->getRecords(); - $this->assertContains('FirefoxImport: unable to read file', $records[0]['message']); + $this->assertContains('Wallabag Browser Import: unable to read file', $records[0]['message']); $this->assertEquals('ERROR', $records[0]['level_name']); } public function testImportUserNotDefined() { $firefoxImport = $this->getFirefoxImport(true); - $firefoxImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); $res = $firefoxImport->import(); $this->assertFalse($res); $records = $this->logHandler->getRecords(); - $this->assertContains('FirefoxImport: user is not defined', $records[0]['message']); + $this->assertContains('Wallabag Browser Import: user is not defined', $records[0]['message']); $this->assertEquals('ERROR', $records[0]['level_name']); } } -- cgit v1.2.3 From f0fd82d039f491d1057ed194084ee40d4327011e Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 25 Sep 2016 14:21:12 +0200 Subject: Fix bad parameter for tests --- tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php index ee5b2ab7..101c20eb 100644 --- a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php @@ -80,7 +80,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase public function testGetStarredEntries() { - $this->client->request('GET', '/api/entries', ['star' => 1, 'sort' => 'updated']); + $this->client->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated']); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); -- cgit v1.2.3 From 27acc6ddb8b0a1549a3f015171621e3056ef65d2 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 25 Sep 2016 15:29:40 +0200 Subject: Fix bad date format in Browser import --- tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php | 4 ++++ tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php | 4 ++++ 2 files changed, 8 insertions(+) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php index 8890c5b1..23c80bec 100644 --- a/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php @@ -120,6 +120,10 @@ class ChromeControllerTest extends WallabagCoreTestCase $this->assertNotEmpty($content->getPreviewPicture()); $this->assertNotEmpty($content->getLanguage()); $this->assertEquals(0, count($content->getTags())); + + $createdAt = $content->getCreatedAt(); + $this->assertEquals('2011', $createdAt->format('Y')); + $this->assertEquals('07', $createdAt->format('m')); } public function testImportWallabagWithEmptyFile() diff --git a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php index 2de0aa09..10fbc225 100644 --- a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php @@ -133,6 +133,10 @@ class FirefoxControllerTest extends WallabagCoreTestCase $this->assertNotEmpty($content->getMimetype()); $this->assertNotEmpty($content->getPreviewPicture()); $this->assertEmpty($content->getLanguage()); + + $createdAt = $content->getCreatedAt(); + $this->assertEquals('2011', $createdAt->format('Y')); + $this->assertEquals('07', $createdAt->format('m')); } public function testImportWallabagWithEmptyFile() -- cgit v1.2.3 From 12d93e6896f2d99b6329b7979ee7b6d11e457c3a Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 25 Sep 2016 22:24:07 +0200 Subject: Update Firefox file With real data, the previous looks more than a Chrome converted file. Also, fix date conversion (hope so). --- .../Controller/FirefoxControllerTest.php | 4 +- .../ImportBundle/Import/FirefoxImportTest.php | 10 +- .../ImportBundle/fixtures/firefox-bookmarks.json | 119 +++++++++++---------- 3 files changed, 67 insertions(+), 66 deletions(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php index 10fbc225..dea5b79c 100644 --- a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php @@ -135,8 +135,8 @@ class FirefoxControllerTest extends WallabagCoreTestCase $this->assertEmpty($content->getLanguage()); $createdAt = $content->getCreatedAt(); - $this->assertEquals('2011', $createdAt->format('Y')); - $this->assertEquals('07', $createdAt->format('m')); + $this->assertEquals('2013', $createdAt->format('Y')); + $this->assertEquals('12', $createdAt->format('m')); } public function testImportWallabagWithEmptyFile() diff --git a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php index e8f0f3c7..007dda6a 100644 --- a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php @@ -61,7 +61,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); - $entryRepo->expects($this->exactly(4)) + $entryRepo->expects($this->exactly(2)) ->method('findByUrlAndUserId') ->willReturn(false); @@ -75,14 +75,14 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase ->getMock(); $this->contentProxy - ->expects($this->exactly(4)) + ->expects($this->exactly(2)) ->method('updateEntry') ->willReturn($entry); $res = $firefoxImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 4, 'queued' => 0], $firefoxImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 2, 'queued' => 0], $firefoxImport->getSummary()); } public function testImportAndMarkAllAsRead() @@ -94,7 +94,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); - $entryRepo->expects($this->exactly(4)) + $entryRepo->expects($this->exactly(2)) ->method('findByUrlAndUserId') ->will($this->onConsecutiveCalls(false, true)); @@ -120,7 +120,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase $this->assertTrue($res); - $this->assertEquals(['skipped' => 3, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary()); + $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary()); } public function testImportWithRabbit() diff --git a/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json b/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json index 8b78b8a4..ee06a16c 100644 --- a/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json +++ b/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json @@ -1,61 +1,62 @@ { - "checksum": "ef1e30cddf64cb94c63d7835640165be", - "roots": { - "bookmark_bar": { - "children": [ { - "date_added": "13112787540531997", - "id": "7", - "name": "Terrorisme: les sombres prédictions du directeur de la DGSI", - "type": "url", - "url": "http://www.lefigaro.fr/actualite-france/2016/07/12/01016-20160712ARTFIG00016-terrorisme-les-sombres-perspectives-de-patrick-calvar-directeur-de-la-dgsi.php" - } ], - "date_added": "13112787380480144", - "date_modified": "13112787542724942", - "id": "1", - "name": "Bookmarks bar", - "type": "folder" - }, - "other": { - "children": [ { - "date_added": "13112787503900822", - "id": "6", - "name": "Parser for Exported Bookmarks HTML file of Google Chrome and Mozilla in Java - Stack Overflow", - "type": "url", - "url": "http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java" - }, { - "children": [ { - "date_added": "13112787564443378", - "id": "9", - "name": "Orange offre un meilleur réseau mobile que Bouygues et SFR, Free derrière - L'Express L'Expansion", - "type": "url", - "url": "http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html" - } ], - "date_added": "13112787556763735", - "date_modified": "13112794390493325", - "id": "8", - "name": "test", - "type": "folder" - }, { - "date_added": "13112794390493325", - "id": "12", - "name": "JSON Formatter & Validator", - "type": "url", - "url": "https://jsonformatter.curiousconcept.com/" - } ], - "date_added": "13112787380480151", - "date_modified": "13112794393509988", - "id": "2", - "name": "Other bookmarks", - "type": "folder" - }, - "synced": { - "children": [ ], - "date_added": "13112787380480155", - "date_modified": "0", - "id": "3", - "name": "Mobile bookmarks", - "type": "folder" - } - }, - "version": 1 + "guid": "root________", + "title": "", + "index": 0, + "dateAdded": 1388166091504000, + "lastModified": 1472897622350000, + "id": 1, + "type": "text/x-moz-place-container", + "root": "placesRoot", + "children": [ + { + "guid": "toolbar_____", + "title": "Barre personnelle", + "index": 1, + "dateAdded": 1388166091504000, + "lastModified": 1472897622263000, + "id": 3, + "annos": [ + { + "name": "bookmarkProperties/description", + "flags": 0, + "expires": 4, + "value": "Ajoutez des marque-pages dans ce dossier pour les voir apparaître sur votre barre personnelle" + } + ], + "type": "text/x-moz-place-container", + "root": "toolbarFolder", + "children": [ + { + "guid": "tard77lzbC5H", + "title": "Orange offre un meilleur réseau mobile que Bouygues et SFR, Free derrière - L'Express L'Expansion", + "index": 1, + "dateAdded": 1388166091644000, + "lastModified": 1388166091644000, + "id": 4, + "type": "text/x-moz-place", + "uri": "http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html" + }, + { + "guid": "E385l9vZ_LVn", + "title": "Parser for Exported Bookmarks HTML file of Google Chrome and Mozilla in Java", + "index": 1, + "dateAdded": 1388166091544000, + "lastModified": 1388166091545000, + "id": 5, + "type": "text/x-moz-place", + "uri": "http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java" + } + ] + }, + { + "guid": "unfiled_____", + "title": "Autres marque-pages", + "index": 3, + "dateAdded": 1388166091504000, + "lastModified": 1388166091542000, + "id": 6, + "type": "text/x-moz-place-container", + "root": "unfiledBookmarksFolder" + } + ] } -- cgit v1.2.3 From fefef9d41b4d1bd9efbd49011159bae70bf67528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 26 Sep 2016 13:40:10 +0200 Subject: Added tags for Firefox import --- tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php | 2 +- tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php index dea5b79c..98f13d72 100644 --- a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php @@ -120,7 +120,7 @@ class FirefoxControllerTest extends WallabagCoreTestCase $this->assertNotEmpty($content->getMimetype()); $this->assertNotEmpty($content->getPreviewPicture()); $this->assertNotEmpty($content->getLanguage()); - $this->assertEquals(0, count($content->getTags())); + $this->assertEquals(2, count($content->getTags())); $content = $client->getContainer() ->get('doctrine.orm.entity_manager') diff --git a/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json b/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json index ee06a16c..406b5697 100644 --- a/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json +++ b/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json @@ -32,6 +32,7 @@ "index": 1, "dateAdded": 1388166091644000, "lastModified": 1388166091644000, + "tags":"test,tag", "id": 4, "type": "text/x-moz-place", "uri": "http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html" -- cgit v1.2.3 From ff1a5362f7254d686864ea53994da6c517b3d3e8 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 27 Sep 2016 07:57:53 +0200 Subject: Add Instapaper import Also update ImportController with latest import (chrome, firefox & instapaper). --- .../Controller/ImportControllerTest.php | 2 +- .../ImportBundle/Import/InstapaperImportTest.php | 233 +++++++++++++++++++++ .../ImportBundle/fixtures/instapaper-export.csv | 4 + 3 files changed, 238 insertions(+), 1 deletion(-) create mode 100644 tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php create mode 100644 tests/Wallabag/ImportBundle/fixtures/instapaper-export.csv (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php index b6783a56..0bc40bdd 100644 --- a/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php @@ -24,6 +24,6 @@ class ImportControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/import/'); $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->assertEquals(6, $crawler->filter('blockquote')->count()); + $this->assertEquals(7, $crawler->filter('blockquote')->count()); } } diff --git a/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php b/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php new file mode 100644 index 00000000..75900bd7 --- /dev/null +++ b/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php @@ -0,0 +1,233 @@ +user = new User(); + + $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') + ->disableOriginalConstructor() + ->getMock(); + + $import = new InstapaperImport($this->em, $this->contentProxy); + + $this->logHandler = new TestHandler(); + $logger = new Logger('test', [$this->logHandler]); + $import->setLogger($logger); + + if (false === $unsetUser) { + $import->setUser($this->user); + } + + return $import; + } + + public function testInit() + { + $instapaperImport = $this->getInstapaperImport(); + + $this->assertEquals('Instapaper', $instapaperImport->getName()); + $this->assertNotEmpty($instapaperImport->getUrl()); + $this->assertEquals('import.instapaper.description', $instapaperImport->getDescription()); + } + + public function testImport() + { + $instapaperImport = $this->getInstapaperImport(); + $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->exactly(3)) + ->method('findByUrlAndUserId') + ->willReturn(false); + + $this->em + ->expects($this->any()) + ->method('getRepository') + ->willReturn($entryRepo); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->exactly(3)) + ->method('updateEntry') + ->willReturn($entry); + + $res = $instapaperImport->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 3, 'queued' => 0], $instapaperImport->getSummary()); + } + + public function testImportAndMarkAllAsRead() + { + $instapaperImport = $this->getInstapaperImport(); + $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->exactly(3)) + ->method('findByUrlAndUserId') + ->will($this->onConsecutiveCalls(false, true, true)); + + $this->em + ->expects($this->any()) + ->method('getRepository') + ->willReturn($entryRepo); + + $this->contentProxy + ->expects($this->once()) + ->method('updateEntry') + ->willReturn(new Entry($this->user)); + + // check that every entry persisted are archived + $this->em + ->expects($this->once()) + ->method('persist') + ->with($this->callback(function ($persistedEntry) { + return $persistedEntry->isArchived(); + })); + + $res = $instapaperImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + + $this->assertEquals(['skipped' => 2, 'imported' => 1, 'queued' => 0], $instapaperImport->getSummary()); + } + + public function testImportWithRabbit() + { + $instapaperImport = $this->getInstapaperImport(); + $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->never()) + ->method('findByUrlAndUserId'); + + $this->em + ->expects($this->never()) + ->method('getRepository'); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->never()) + ->method('updateEntry'); + + $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') + ->disableOriginalConstructor() + ->getMock(); + + $producer + ->expects($this->exactly(3)) + ->method('publish'); + + $instapaperImport->setProducer($producer); + + $res = $instapaperImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 3], $instapaperImport->getSummary()); + } + + public function testImportWithRedis() + { + $instapaperImport = $this->getInstapaperImport(); + $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->never()) + ->method('findByUrlAndUserId'); + + $this->em + ->expects($this->never()) + ->method('getRepository'); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->never()) + ->method('updateEntry'); + + $factory = new RedisMockFactory(); + $redisMock = $factory->getAdapter('Predis\Client', true); + + $queue = new RedisQueue($redisMock, 'instapaper'); + $producer = new Producer($queue); + + $instapaperImport->setProducer($producer); + + $res = $instapaperImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 3], $instapaperImport->getSummary()); + + $this->assertNotEmpty($redisMock->lpop('instapaper')); + } + + public function testImportBadFile() + { + $instapaperImport = $this->getInstapaperImport(); + $instapaperImport->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx'); + + $res = $instapaperImport->import(); + + $this->assertFalse($res); + + $records = $this->logHandler->getRecords(); + $this->assertContains('InstapaperImport: unable to read file', $records[0]['message']); + $this->assertEquals('ERROR', $records[0]['level_name']); + } + + public function testImportUserNotDefined() + { + $instapaperImport = $this->getInstapaperImport(true); + $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); + + $res = $instapaperImport->import(); + + $this->assertFalse($res); + + $records = $this->logHandler->getRecords(); + $this->assertContains('InstapaperImport: user is not defined', $records[0]['message']); + $this->assertEquals('ERROR', $records[0]['level_name']); + } +} diff --git a/tests/Wallabag/ImportBundle/fixtures/instapaper-export.csv b/tests/Wallabag/ImportBundle/fixtures/instapaper-export.csv new file mode 100644 index 00000000..28a4c8e6 --- /dev/null +++ b/tests/Wallabag/ImportBundle/fixtures/instapaper-export.csv @@ -0,0 +1,4 @@ +URL,Title,Selection,Folder +http://www.liberation.fr/societe/2012/12/06/baumettes-un-tour-en-cellule_865551,Baumettes : un tour en cellule,,Unread +https://redditblog.com/2016/09/20/amp-and-reactredux/,AMP and React+Redux: Why Not?,,Archive +https://medium.com/@the_minh/why-foursquare-swarm-is-still-my-favourite-social-network-e38228493e6c,Why Foursquare / Swarm is still my favourite social network,,Starred -- cgit v1.2.3 From c7ea9b41f32f222fef6a59734ea0b1176bfa1f41 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 27 Sep 2016 17:01:14 +0200 Subject: Add controller test for Instapaper --- .../Controller/InstapaperControllerTest.php | 196 +++++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100644 tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php b/tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php new file mode 100644 index 00000000..9df08e75 --- /dev/null +++ b/tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php @@ -0,0 +1,196 @@ +logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/instapaper'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + } + + public function testImportInstapaperWithRabbitEnabled() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 1); + + $crawler = $client->request('GET', '/import/instapaper'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + + $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0); + } + + public function testImportInstapaperBadFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/instapaper'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $data = [ + 'upload_import_file[file]' => '', + ]; + + $client->submit($form, $data); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + } + + public function testImportInstapaperWithRedisEnabled() + { + $this->checkRedis(); + $this->logInAs('admin'); + $client = $this->getClient(); + $client->getContainer()->get('craue_config')->set('import_with_redis', 1); + + $crawler = $client->request('GET', '/import/instapaper'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/instapaper-export.csv', 'instapaper.csv'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + + $this->assertNotEmpty($client->getContainer()->get('wallabag_core.redis.client')->lpop('wallabag.import.instapaper')); + + $client->getContainer()->get('craue_config')->set('import_with_redis', 0); + } + + public function testImportInstapaperWithFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/instapaper'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/instapaper-export.csv', 'instapaper.csv'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId( + 'http://www.liberation.fr/societe/2012/12/06/baumettes-un-tour-en-cellule_865551', + $this->getLoggedInUserId() + ); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + + $this->assertNotEmpty($content->getMimetype()); + $this->assertNotEmpty($content->getPreviewPicture()); + $this->assertNotEmpty($content->getLanguage()); + $this->assertEquals(0, count($content->getTags())); + $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); + } + + public function testImportInstapaperWithFileAndMarkAllAsRead() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/instapaper'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/instapaper-export.csv', 'instapaper-read.csv'); + + $data = [ + 'upload_import_file[file]' => $file, + 'upload_import_file[mark_as_read]' => 1, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $content1 = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId( + 'https://redditblog.com/2016/09/20/amp-and-reactredux/', + $this->getLoggedInUserId() + ); + + $this->assertTrue($content1->isArchived()); + + $content2 = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId( + 'https://medium.com/@the_minh/why-foursquare-swarm-is-still-my-favourite-social-network-e38228493e6c', + $this->getLoggedInUserId() + ); + + $this->assertTrue($content2->isArchived()); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + } + + public function testImportInstapaperWithEmptyFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/instapaper'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.failed', $body[0]); + } +} -- cgit v1.2.3 From 084fb0d303efc6edd0bfbf43d96b6cbe48acb2b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Wed, 28 Sep 2016 10:02:31 +0200 Subject: Some fixes about upgrade from 2.0.x -> 2.1.0 --- tests/Wallabag/CoreBundle/Controller/TagControllerTest.php | 4 ++-- tests/Wallabag/CoreBundle/WallabagCoreTestCase.php | 2 +- tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index 71652760..2c32393f 100644 --- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php @@ -47,7 +47,7 @@ class TagControllerTest extends WallabagCoreTestCase $this->assertEquals(1, count($entry->getTags())); - # tag already exists and already assigned + // tag already exists and already assigned $client->submit($form, $data); $this->assertEquals(302, $client->getResponse()->getStatusCode()); @@ -58,7 +58,7 @@ class TagControllerTest extends WallabagCoreTestCase $this->assertEquals(1, count($newEntry->getTags())); - # tag already exists but still not assigned to this entry + // tag already exists but still not assigned to this entry $data = [ 'tag[label]' => 'foo', ]; diff --git a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php index 75b7ee0b..4f103921 100644 --- a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php +++ b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php @@ -83,7 +83,7 @@ abstract class WallabagCoreTestCase extends WebTestCase /** * Check if Redis is installed. - * If not, mark test as skip + * If not, mark test as skip. */ protected function checkRedis() { diff --git a/tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php b/tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php index f670c925..441d6519 100644 --- a/tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php +++ b/tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php @@ -37,7 +37,7 @@ class AuthCodeMailerTest extends \PHPUnit_Framework_TestCase ); $this->mailer = new \Swift_Mailer($transport); - $twigTemplate = << Date: Fri, 30 Sep 2016 21:01:36 +0200 Subject: Create user config in one place Using a listener, user config is now created when a user: - is created from the command line - register (with or without email confirmation) - is created from the config panel --- .../RegistrationConfirmedListenerTest.php | 91 --------------------- .../EventListener/CreateConfigListenerTest.php | 93 ++++++++++++++++++++++ 2 files changed, 93 insertions(+), 91 deletions(-) delete mode 100644 tests/Wallabag/CoreBundle/EventListener/RegistrationConfirmedListenerTest.php create mode 100644 tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/CoreBundle/EventListener/RegistrationConfirmedListenerTest.php b/tests/Wallabag/CoreBundle/EventListener/RegistrationConfirmedListenerTest.php deleted file mode 100644 index e45722fa..00000000 --- a/tests/Wallabag/CoreBundle/EventListener/RegistrationConfirmedListenerTest.php +++ /dev/null @@ -1,91 +0,0 @@ -em = $this->getMockBuilder('Doctrine\ORM\EntityManager') - ->disableOriginalConstructor() - ->getMock(); - - $this->listener = new RegistrationConfirmedListener( - $this->em, - 'baggy', - 20, - 50, - 'fr' - ); - - $this->dispatcher = new EventDispatcher(); - $this->dispatcher->addSubscriber($this->listener); - - $this->request = Request::create('/'); - $this->response = Response::create(); - } - - public function testWithInvalidUser() - { - $user = new User(); - $user->setEnabled(false); - - $event = new FilterUserResponseEvent( - $user, - $this->request, - $this->response - ); - - $this->em->expects($this->never())->method('persist'); - $this->em->expects($this->never())->method('flush'); - - $this->dispatcher->dispatch( - FOSUserEvents::REGISTRATION_CONFIRMED, - $event - ); - } - - public function testWithValidUser() - { - $user = new User(); - $user->setEnabled(true); - - $event = new FilterUserResponseEvent( - $user, - $this->request, - $this->response - ); - - $config = new Config($user); - $config->setTheme('baggy'); - $config->setItemsPerPage(20); - $config->setRssLimit(50); - $config->setLanguage('fr'); - - $this->em->expects($this->once()) - ->method('persist') - ->will($this->returnValue($config)); - $this->em->expects($this->once()) - ->method('flush'); - - $this->dispatcher->dispatch( - FOSUserEvents::REGISTRATION_CONFIRMED, - $event - ); - } -} diff --git a/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php b/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php new file mode 100644 index 00000000..0cebd3e4 --- /dev/null +++ b/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php @@ -0,0 +1,93 @@ +em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $this->listener = new CreateConfigListener( + $this->em, + 'baggy', + 20, + 50, + 'fr', + 1 + ); + + $this->dispatcher = new EventDispatcher(); + $this->dispatcher->addSubscriber($this->listener); + + $this->request = Request::create('/'); + $this->response = Response::create(); + } + + public function testWithInvalidUser() + { + $user = new User(); + $user->setEnabled(false); + + $event = new FilterUserResponseEvent( + $user, + $this->request, + $this->response + ); + + $this->em->expects($this->never())->method('persist'); + $this->em->expects($this->never())->method('flush'); + + $this->dispatcher->dispatch( + FOSUserEvents::REGISTRATION_COMPLETED, + $event + ); + } + + public function testWithValidUser() + { + $user = new User(); + $user->setEnabled(true); + + $event = new FilterUserResponseEvent( + $user, + $this->request, + $this->response + ); + + $config = new Config($user); + $config->setTheme('baggy'); + $config->setItemsPerPage(20); + $config->setRssLimit(50); + $config->setLanguage('fr'); + $config->setReadingSpeed(1); + + $this->em->expects($this->once()) + ->method('persist') + ->will($this->returnValue($config)); + $this->em->expects($this->once()) + ->method('flush'); + + $this->dispatcher->dispatch( + FOSUserEvents::REGISTRATION_COMPLETED, + $event + ); + } +} -- cgit v1.2.3 From 40e219622a2c416ab36cb39b26a5e1354e4438cc Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 1 Oct 2016 14:51:54 +0200 Subject: Customize errors templates All error goes to the same template which only display the error message and the status code. --- .../CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php b/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php index e29b58b5..2e6fccfb 100644 --- a/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php +++ b/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php @@ -125,16 +125,14 @@ class UsernameRssTokenConverterTest extends \PHPUnit_Framework_TestCase $this->assertTrue($converter->supports($params)); } - /** - * @expectedException InvalidArgumentException - * @expectedExceptionMessage Route attribute is missing - */ public function testApplyEmptyRequest() { $params = new ParamConverter([]); $converter = new UsernameRssTokenConverter(); - $converter->apply(new Request(), $params); + $res = $converter->apply(new Request(), $params); + + $this->assertFalse($res); } /** -- cgit v1.2.3 From 1264029cd413a4e29642a219e2647d886f0de0d6 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 1 Oct 2016 15:58:26 +0200 Subject: Add simple stats in footer --- .../Wallabag/CoreBundle/Twig/WallabagExtensionTest.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php index 8ec2a75a..b1c8c946 100644 --- a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php +++ b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php @@ -8,7 +8,23 @@ class WallabagExtensionTest extends \PHPUnit_Framework_TestCase { public function testRemoveWww() { - $extension = new WallabagExtension(); + $entryRepository = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $tagRepository = $this->getMockBuilder('Wallabag\CoreBundle\Repository\TagRepository') + ->disableOriginalConstructor() + ->getMock(); + + $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface') + ->disableOriginalConstructor() + ->getMock(); + + $translator = $this->getMockBuilder('Symfony\Component\Translation\TranslatorInterface') + ->disableOriginalConstructor() + ->getMock(); + + $extension = new WallabagExtension($entryRepository, $tagRepository, $tokenStorage, 0, $translator); $this->assertEquals('lemonde.fr', $extension->removeWww('www.lemonde.fr')); $this->assertEquals('lemonde.fr', $extension->removeWww('lemonde.fr')); -- cgit v1.2.3 From bf3dc999e7b25888460faff2251f75e4a79491c4 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 1 Oct 2016 16:47:48 +0200 Subject: Add ability to edit a tagging rule --- .../CoreBundle/Controller/ConfigControllerTest.php | 61 +++++++++++++++++----- 1 file changed, 48 insertions(+), 13 deletions(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index 7193f9b0..bb3ea9e2 100644 --- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php @@ -56,8 +56,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $crawler = $client->followRedirect(); - $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); - $this->assertContains('flashes.config.notice.config_saved', $alert[0]); + $this->assertContains('flashes.config.notice.config_saved', $crawler->filter('body')->extract(['_text'])[0]); } public function testChangeReadingSpeed() @@ -213,8 +212,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $crawler = $client->followRedirect(); - $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); - $this->assertContains('flashes.config.notice.password_updated', $alert[0]); + $this->assertContains('flashes.config.notice.password_updated', $crawler->filter('body')->extract(['_text'])[0]); } public function dataForUserFailed() @@ -382,8 +380,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $crawler = $client->followRedirect(); - $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); - $this->assertContains('flashes.config.notice.user_added', $alert[0]); + $this->assertContains('flashes.config.notice.user_added', $crawler->filter('body')->extract(['_text'])[0]); $em = $client->getContainer()->get('doctrine.orm.entity_manager'); $user = $em @@ -474,8 +471,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $crawler = $client->followRedirect(); - $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); - $this->assertContains('flashes.config.notice.rss_updated', $alert[0]); + $this->assertContains('flashes.config.notice.rss_updated', $crawler->filter('body')->extract(['_text'])[0]); } public function dataForRssFailed() @@ -540,8 +536,32 @@ class ConfigControllerTest extends WallabagCoreTestCase $crawler = $client->followRedirect(); - $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); - $this->assertContains('flashes.config.notice.tagging_rules_updated', $alert[0]); + $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]); + + $editLink = $crawler->filter('.mode_edit')->last()->link(); + + $crawler = $client->click($editLink); + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertContains('?tagging-rule=', $client->getResponse()->headers->get('location')); + + $crawler = $client->followRedirect(); + + $form = $crawler->filter('button[id=tagging_rule_save]')->form(); + + $data = [ + 'tagging_rule[rule]' => 'readingTime <= 30', + 'tagging_rule[tags]' => 'short reading', + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]); + + $this->assertContains('readingTime <= 30', $crawler->filter('body')->extract(['_text'])[0]); $deleteLink = $crawler->filter('.delete')->last()->link(); @@ -549,8 +569,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $this->assertEquals(302, $client->getResponse()->getStatusCode()); $crawler = $client->followRedirect(); - $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); - $this->assertContains('flashes.config.notice.tagging_rules_deleted', $alert[0]); + $this->assertContains('flashes.config.notice.tagging_rules_deleted', $crawler->filter('body')->extract(['_text'])[0]); } public function dataForTaggingRuleFailed() @@ -613,7 +632,23 @@ class ConfigControllerTest extends WallabagCoreTestCase ->getRepository('WallabagCoreBundle:TaggingRule') ->findAll()[0]; - $crawler = $client->request('GET', '/tagging-rule/delete/'.$rule->getId()); + $crawler = $client->request('GET', '/tagging-rule/edit/'.$rule->getId()); + + $this->assertEquals(403, $client->getResponse()->getStatusCode()); + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('You can not access this tagging rule', $body[0]); + } + + public function testEditingTaggingRuleFromAnOtherUser() + { + $this->logInAs('bob'); + $client = $this->getClient(); + + $rule = $client->getContainer()->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:TaggingRule') + ->findAll()[0]; + + $crawler = $client->request('GET', '/tagging-rule/edit/'.$rule->getId()); $this->assertEquals(403, $client->getResponse()->getStatusCode()); $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); -- cgit v1.2.3 From 6273fefd5d945de1d871815a652f5a716e12e820 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 1 Oct 2016 17:15:28 +0200 Subject: Add an exists endpoint in API It should allow third party to check if an url was already saved by a user --- .../ApiBundle/Controller/WallabagRestControllerTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php index 101c20eb..e582e5f9 100644 --- a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php @@ -684,4 +684,15 @@ class WallabagRestControllerTest extends WallabagApiTestCase $this->assertEquals(true, $content['is_starred']); } + + public function testGetEntriesExists() + { + $this->client->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2'); + + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertEquals(true, $content['exists']); + } } -- cgit v1.2.3 From 55551e332c2fe3e502b32eba92b63a967afcc0ef Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 1 Oct 2016 17:26:36 +0200 Subject: =?UTF-8?q?Add=20test=20when=20url=20doesn=E2=80=99t=20exist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApiBundle/Controller/WallabagRestControllerTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php index e582e5f9..9b5760bc 100644 --- a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php @@ -695,4 +695,15 @@ class WallabagRestControllerTest extends WallabagApiTestCase $this->assertEquals(true, $content['exists']); } + + public function testGetEntriesExistsWhichDoesNotExists() + { + $this->client->request('GET', '/api/entries/exists?url=http://google.com/entry2'); + + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertEquals(false, $content['exists']); + } } -- cgit v1.2.3 From 19ca0b2f355a657dd296bfa782473ffd45280572 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 1 Oct 2016 17:57:38 +0200 Subject: Avoid duplicate url with accents --- .../CoreBundle/Controller/EntryControllerTest.php | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index a74c17d9..ebcf3f5a 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -160,6 +160,41 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); } + public function testPostNewOkUrlExistWithAccent() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $url = 'http://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing'; + + $crawler = $client->request('GET', '/new'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $form = $crawler->filter('form[name=entry]')->form(); + + $data = [ + 'entry[url]' => $url, + ]; + + $client->submit($form, $data); + + $crawler = $client->request('GET', '/new'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $form = $crawler->filter('form[name=entry]')->form(); + + $data = [ + 'entry[url]' => $url, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); + } + /** * This test will require an internet connection. */ -- cgit v1.2.3 From d6d3fb6e4c92ec8d71b3f8c6d91e0f8ab80f795b Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 2 Oct 2016 01:34:52 +0200 Subject: Remove additional entry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After the test is done, cleanup what we’ve done --- tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index ebcf3f5a..9942b2a0 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -193,6 +193,15 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertEquals(302, $client->getResponse()->getStatusCode()); $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); + + $em = $client->getContainer() + ->get('doctrine.orm.entity_manager'); + $entry = $em + ->getRepository('WallabagCoreBundle:Entry') + ->findOneByUrl(urldecode($url)); + + $em->remove($entry); + $em->flush(); } /** -- cgit v1.2.3 From 24ad330be6be01af05091fe044183e95b4a0ebd8 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 2 Oct 2016 01:47:10 +0200 Subject: Update test --- tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index a74c17d9..053aa679 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -29,7 +29,7 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertEquals(200, $client->getResponse()->getStatusCode()); $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); - $this->assertContains('quickstart.intro.paragraph_1', $body[0]); + $this->assertContains('quickstart.intro.title', $body[0]); // Test if quickstart is disabled when user has 1 entry $crawler = $client->request('GET', '/new'); -- cgit v1.2.3 From 152fcccd4489378a8ed9391e3e191df4aeba6435 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 30 Sep 2016 20:09:06 +0200 Subject: Add users management UI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - remove the “add a user” from the config page - add a CRUD on user - fix some missing translations (+ bad indentation) --- .../UserBundle/Controller/ManageControllerTest.php | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 tests/Wallabag/UserBundle/Controller/ManageControllerTest.php (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php b/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php new file mode 100644 index 00000000..247eb6ba --- /dev/null +++ b/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php @@ -0,0 +1,71 @@ +getClient(); + + $client->request('GET', '/users/'); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertContains('login', $client->getResponse()->headers->get('location')); + } + + public function testCompleteScenario() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + // Create a new user in the database + $crawler = $client->request('GET', '/users/'); + $this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /users/"); + $crawler = $client->click($crawler->selectLink('user.list.create_new_one')->link()); + + // Fill in the form and submit it + $form = $crawler->selectButton('user.form.save')->form(array( + 'new_user[username]' => 'test_user', + 'new_user[email]' => 'test@test.io', + 'new_user[plainPassword][first]' => 'test', + 'new_user[plainPassword][second]' => 'test', + )); + + $client->submit($form); + $client->followRedirect(); + $crawler = $client->request('GET', '/users/'); + + // Check data in the show view + $this->assertGreaterThan(0, $crawler->filter('td:contains("test_user")')->count(), 'Missing element td:contains("test_user")'); + + // Edit the user + $crawler = $client->click($crawler->selectLink('user.list.edit_action')->last()->link()); + + $form = $crawler->selectButton('user.form.save')->form(array( + 'user[name]' => 'Foo User', + 'user[username]' => 'test_user', + 'user[email]' => 'test@test.io', + 'user[enabled]' => true, + 'user[locked]' => false, + )); + + $client->submit($form); + $crawler = $client->followRedirect(); + + // Check the element contains an attribute with value equals "Foo User" + $this->assertGreaterThan(0, $crawler->filter('[value="Foo User"]')->count(), 'Missing element [value="Foo User"]'); + + $crawler = $client->request('GET', '/users/'); + $crawler = $client->click($crawler->selectLink('user.list.edit_action')->last()->link()); + + // Delete the user + $client->submit($crawler->selectButton('user.form.delete')->form()); + $crawler = $client->followRedirect(); + + // Check the user has been delete on the list + $this->assertNotRegExp('/Foo User/', $client->getResponse()->getContent()); + } +} -- cgit v1.2.3 From eb4142e0afa5c83c9e301e38e57a72322be05e8c Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 2 Oct 2016 01:32:23 +0200 Subject: Remove NewUser test from Config --- .../CoreBundle/Controller/ConfigControllerTest.php | 114 --------------------- 1 file changed, 114 deletions(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index bb3ea9e2..1954c654 100644 --- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php @@ -28,7 +28,6 @@ class ConfigControllerTest extends WallabagCoreTestCase $this->assertCount(1, $crawler->filter('button[id=config_save]')); $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]')); $this->assertCount(1, $crawler->filter('button[id=update_user_save]')); - $this->assertCount(1, $crawler->filter('button[id=new_user_save]')); $this->assertCount(1, $crawler->filter('button[id=rss_config_save]')); } @@ -283,119 +282,6 @@ class ConfigControllerTest extends WallabagCoreTestCase $this->assertContains('flashes.config.notice.user_updated', $alert[0]); } - public function dataForNewUserFailed() - { - return [ - [ - [ - 'new_user[username]' => '', - 'new_user[plainPassword][first]' => '', - 'new_user[plainPassword][second]' => '', - 'new_user[email]' => '', - ], - 'fos_user.username.blank', - ], - [ - [ - 'new_user[username]' => 'a', - 'new_user[plainPassword][first]' => 'mypassword', - 'new_user[plainPassword][second]' => 'mypassword', - 'new_user[email]' => '', - ], - 'fos_user.username.short', - ], - [ - [ - 'new_user[username]' => 'wallace', - 'new_user[plainPassword][first]' => 'mypassword', - 'new_user[plainPassword][second]' => 'mypassword', - 'new_user[email]' => 'test', - ], - 'fos_user.email.invalid', - ], - [ - [ - 'new_user[username]' => 'admin', - 'new_user[plainPassword][first]' => 'wallacewallace', - 'new_user[plainPassword][second]' => 'wallacewallace', - 'new_user[email]' => 'wallace@wallace.me', - ], - 'fos_user.username.already_used', - ], - [ - [ - 'new_user[username]' => 'wallace', - 'new_user[plainPassword][first]' => 'mypassword1', - 'new_user[plainPassword][second]' => 'mypassword2', - 'new_user[email]' => 'wallace@wallace.me', - ], - 'validator.password_must_match', - ], - ]; - } - - /** - * @dataProvider dataForNewUserFailed - */ - public function testNewUserFailed($data, $expectedMessage) - { - $this->logInAs('admin'); - $client = $this->getClient(); - - $crawler = $client->request('GET', '/config'); - - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - - $form = $crawler->filter('button[id=new_user_save]')->form(); - - $crawler = $client->submit($form, $data); - - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - - $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); - $this->assertContains($expectedMessage, $alert[0]); - } - - public function testNewUserCreated() - { - $this->logInAs('admin'); - $client = $this->getClient(); - - $crawler = $client->request('GET', '/config'); - - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - - $form = $crawler->filter('button[id=new_user_save]')->form(); - - $data = [ - 'new_user[username]' => 'wallace', - 'new_user[plainPassword][first]' => 'wallace1', - 'new_user[plainPassword][second]' => 'wallace1', - 'new_user[email]' => 'wallace@wallace.me', - ]; - - $client->submit($form, $data); - - $this->assertEquals(302, $client->getResponse()->getStatusCode()); - - $crawler = $client->followRedirect(); - - $this->assertContains('flashes.config.notice.user_added', $crawler->filter('body')->extract(['_text'])[0]); - - $em = $client->getContainer()->get('doctrine.orm.entity_manager'); - $user = $em - ->getRepository('WallabagUserBundle:User') - ->findOneByUsername('wallace'); - - $this->assertTrue(false !== $user); - $this->assertTrue($user->isEnabled()); - $this->assertEquals('material', $user->getConfig()->getTheme()); - $this->assertEquals(12, $user->getConfig()->getItemsPerPage()); - $this->assertEquals(50, $user->getConfig()->getRssLimit()); - $this->assertEquals('en', $user->getConfig()->getLanguage()); - $this->assertEquals(1, $user->getConfig()->getReadingSpeed()); - } - public function testRssUpdateResetToken() { $this->logInAs('admin'); -- cgit v1.2.3 From ccc7faec094387681a59faa5ca79a86e33f06972 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 2 Oct 2016 13:21:45 +0200 Subject: Disabled delete button for the logged user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To avoid some bad things to happen… --- tests/Wallabag/UserBundle/Controller/ManageControllerTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php b/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php index 247eb6ba..19b824b8 100644 --- a/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php +++ b/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php @@ -68,4 +68,15 @@ class ManageControllerTest extends WallabagCoreTestCase // Check the user has been delete on the list $this->assertNotRegExp('/Foo User/', $client->getResponse()->getContent()); } + + public function testDeleteDisabledForLoggedUser() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/users/'.$this->getLoggedInUserId().'/edit'); + $disabled = $crawler->selectButton('user.form.delete')->extract('disabled'); + + $this->assertEquals('disabled', $disabled[0]); + } } -- cgit v1.2.3 From c3f8b428dd50578a6eba5f4673ea1c9edabd2512 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 2 Oct 2016 15:41:08 +0200 Subject: Fix parameters in API _links We forgot to pass them to the factory --- .../Controller/WallabagRestControllerTest.php | 100 ++++++++++++++++++++- 1 file changed, 99 insertions(+), 1 deletion(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php index 9b5760bc..fd72b8f2 100644 --- a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php @@ -78,6 +78,53 @@ class WallabagRestControllerTest extends WallabagApiTestCase ); } + public function testGetEntriesWithFullOptions() + { + $this->client->request('GET', '/api/entries', [ + 'archive' => 1, + 'starred' => 1, + 'sort' => 'updated', + 'order' => 'asc', + 'page' => 1, + 'perPage' => 2, + 'tags' => 'foo', + 'since' => 1443274283, + ]); + + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertGreaterThanOrEqual(1, count($content)); + $this->assertArrayHasKey('items', $content['_embedded']); + $this->assertGreaterThanOrEqual(0, $content['total']); + $this->assertEquals(1, $content['page']); + $this->assertEquals(2, $content['limit']); + $this->assertGreaterThanOrEqual(1, $content['pages']); + + $this->assertArrayHasKey('_links', $content); + $this->assertArrayHasKey('self', $content['_links']); + $this->assertArrayHasKey('first', $content['_links']); + $this->assertArrayHasKey('last', $content['_links']); + + foreach (['self', 'first', 'last'] as $link) { + $this->assertArrayHasKey('href', $content['_links'][$link]); + $this->assertContains('archive=1', $content['_links'][$link]['href']); + $this->assertContains('starred=1', $content['_links'][$link]['href']); + $this->assertContains('sort=updated', $content['_links'][$link]['href']); + $this->assertContains('order=asc', $content['_links'][$link]['href']); + $this->assertContains('tags=foo', $content['_links'][$link]['href']); + $this->assertContains('since=1443274283', $content['_links'][$link]['href']); + } + + $this->assertTrue( + $this->client->getResponse()->headers->contains( + 'Content-Type', + 'application/json' + ) + ); + } + public function testGetStarredEntries() { $this->client->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated']); @@ -92,6 +139,17 @@ class WallabagRestControllerTest extends WallabagApiTestCase $this->assertEquals(1, $content['page']); $this->assertGreaterThanOrEqual(1, $content['pages']); + $this->assertArrayHasKey('_links', $content); + $this->assertArrayHasKey('self', $content['_links']); + $this->assertArrayHasKey('first', $content['_links']); + $this->assertArrayHasKey('last', $content['_links']); + + foreach (['self', 'first', 'last'] as $link) { + $this->assertArrayHasKey('href', $content['_links'][$link]); + $this->assertContains('starred=1', $content['_links'][$link]['href']); + $this->assertContains('sort=updated', $content['_links'][$link]['href']); + } + $this->assertTrue( $this->client->getResponse()->headers->contains( 'Content-Type', @@ -114,6 +172,16 @@ class WallabagRestControllerTest extends WallabagApiTestCase $this->assertEquals(1, $content['page']); $this->assertGreaterThanOrEqual(1, $content['pages']); + $this->assertArrayHasKey('_links', $content); + $this->assertArrayHasKey('self', $content['_links']); + $this->assertArrayHasKey('first', $content['_links']); + $this->assertArrayHasKey('last', $content['_links']); + + foreach (['self', 'first', 'last'] as $link) { + $this->assertArrayHasKey('href', $content['_links'][$link]); + $this->assertContains('archive=1', $content['_links'][$link]['href']); + } + $this->assertTrue( $this->client->getResponse()->headers->contains( 'Content-Type', @@ -136,6 +204,16 @@ class WallabagRestControllerTest extends WallabagApiTestCase $this->assertEquals(1, $content['page']); $this->assertGreaterThanOrEqual(1, $content['pages']); + $this->assertArrayHasKey('_links', $content); + $this->assertArrayHasKey('self', $content['_links']); + $this->assertArrayHasKey('first', $content['_links']); + $this->assertArrayHasKey('last', $content['_links']); + + foreach (['self', 'first', 'last'] as $link) { + $this->assertArrayHasKey('href', $content['_links'][$link]); + $this->assertContains('tags='.urlencode('foo,bar'), $content['_links'][$link]['href']); + } + $this->assertTrue( $this->client->getResponse()->headers->contains( 'Content-Type', @@ -146,7 +224,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase public function testGetDatedEntries() { - $this->client->request('GET', '/api/entries', ['since' => 1]); + $this->client->request('GET', '/api/entries', ['since' => 1443274283]); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); @@ -158,6 +236,16 @@ class WallabagRestControllerTest extends WallabagApiTestCase $this->assertEquals(1, $content['page']); $this->assertGreaterThanOrEqual(1, $content['pages']); + $this->assertArrayHasKey('_links', $content); + $this->assertArrayHasKey('self', $content['_links']); + $this->assertArrayHasKey('first', $content['_links']); + $this->assertArrayHasKey('last', $content['_links']); + + foreach (['self', 'first', 'last'] as $link) { + $this->assertArrayHasKey('href', $content['_links'][$link]); + $this->assertContains('since=1443274283', $content['_links'][$link]['href']); + } + $this->assertTrue( $this->client->getResponse()->headers->contains( 'Content-Type', @@ -181,6 +269,16 @@ class WallabagRestControllerTest extends WallabagApiTestCase $this->assertEquals(1, $content['page']); $this->assertEquals(1, $content['pages']); + $this->assertArrayHasKey('_links', $content); + $this->assertArrayHasKey('self', $content['_links']); + $this->assertArrayHasKey('first', $content['_links']); + $this->assertArrayHasKey('last', $content['_links']); + + foreach (['self', 'first', 'last'] as $link) { + $this->assertArrayHasKey('href', $content['_links'][$link]); + $this->assertContains('since='.($future->getTimestamp() + 1000), $content['_links'][$link]['href']); + } + $this->assertTrue( $this->client->getResponse()->headers->contains( 'Content-Type', -- cgit v1.2.3 From 755ff9e835614fd66f67615aede950b38f8ab308 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 4 Oct 2016 10:42:45 +0200 Subject: Create config even if user is disabled When a user register itself AND the wallabag instance is configured to send a confirmation email, the user is disabled when the listener (which create the config) receive the event. There were a check (don't know why) if the user is enabled we create the config. But the user is disabled when confirmation email is actived. --- .../EventListener/CreateConfigListenerTest.php | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php b/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php index 0cebd3e4..a78b77bc 100644 --- a/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php +++ b/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php @@ -41,26 +41,6 @@ class CreateConfigListenerTest extends \PHPUnit_Framework_TestCase $this->response = Response::create(); } - public function testWithInvalidUser() - { - $user = new User(); - $user->setEnabled(false); - - $event = new FilterUserResponseEvent( - $user, - $this->request, - $this->response - ); - - $this->em->expects($this->never())->method('persist'); - $this->em->expects($this->never())->method('flush'); - - $this->dispatcher->dispatch( - FOSUserEvents::REGISTRATION_COMPLETED, - $event - ); - } - public function testWithValidUser() { $user = new User(); -- cgit v1.2.3 From 0b174d69d77770fab617661c284095bc61d30c10 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 5 Oct 2016 19:30:56 +0200 Subject: Fix typo & add test --- tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php index fd72b8f2..65b65290 100644 --- a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php @@ -804,4 +804,11 @@ class WallabagRestControllerTest extends WallabagApiTestCase $this->assertEquals(false, $content['exists']); } + + public function testGetEntriesExistsWithNoUrl() + { + $this->client->request('GET', '/api/entries/exists?url='); + + $this->assertEquals(403, $this->client->getResponse()->getStatusCode()); + } } -- cgit v1.2.3 From b0458874c85060c992aa1cb78dec91ee85082b74 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 2 Oct 2016 16:06:42 +0200 Subject: Fix relations export for Entry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tags & Annotations weren’t really well exported. This is now fixed (+ tests) --- .../CoreBundle/Controller/ExportControllerTest.php | 37 ++++++++++++++++------ 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php index 47b86117..9f35a448 100644 --- a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php @@ -146,7 +146,9 @@ class ExportControllerTest extends WallabagCoreTestCase ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') ->createQueryBuilder('e') + ->select('e, t') ->leftJoin('e.user', 'u') + ->leftJoin('e.tags', 't') ->where('u.username = :username')->setParameter('username', 'admin') ->andWhere('e.isArchived = true') ->getQuery() @@ -169,6 +171,18 @@ class ExportControllerTest extends WallabagCoreTestCase // +1 for title line $this->assertEquals(count($contentInDB) + 1, count($csv)); $this->assertEquals('Title;URL;Content;Tags;"MIME Type";Language;"Creation date"', $csv[0]); + $this->assertContains($contentInDB[0]['title'], $csv[1]); + $this->assertContains($contentInDB[0]['url'], $csv[1]); + $this->assertContains($contentInDB[0]['content'], $csv[1]); + $this->assertContains($contentInDB[0]['mimetype'], $csv[1]); + $this->assertContains($contentInDB[0]['language'], $csv[1]); + $this->assertContains($contentInDB[0]['createdAt']->format('d/m/Y h:i:s'), $csv[1]); + + $expectedTag = []; + foreach ($contentInDB[0]['tags'] as $tag) { + $expectedTag[] = $tag['label']; + } + $this->assertContains(implode(', ', $expectedTag), $csv[1]); } public function testJsonExport() @@ -176,29 +190,23 @@ class ExportControllerTest extends WallabagCoreTestCase $this->logInAs('admin'); $client = $this->getClient(); - // to be sure results are the same $contentInDB = $client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->createQueryBuilder('e') - ->leftJoin('e.user', 'u') - ->where('u.username = :username')->setParameter('username', 'admin') - ->getQuery() - ->getArrayResult(); + ->findOneByUsernameAndNotArchived('admin'); ob_start(); - $crawler = $client->request('GET', '/export/all.json'); + $crawler = $client->request('GET', '/export/'.$contentInDB->getId().'.json'); ob_end_clean(); $this->assertEquals(200, $client->getResponse()->getStatusCode()); $headers = $client->getResponse()->headers; $this->assertEquals('application/json', $headers->get('content-type')); - $this->assertEquals('attachment; filename="All articles.json"', $headers->get('content-disposition')); + $this->assertEquals('attachment; filename="'.$contentInDB->getTitle().'.json"', $headers->get('content-disposition')); $this->assertEquals('UTF-8', $headers->get('content-transfer-encoding')); $content = json_decode($client->getResponse()->getContent(), true); - $this->assertEquals(count($contentInDB), count($content)); $this->assertArrayHasKey('id', $content[0]); $this->assertArrayHasKey('title', $content[0]); $this->assertArrayHasKey('url', $content[0]); @@ -212,6 +220,17 @@ class ExportControllerTest extends WallabagCoreTestCase $this->assertArrayHasKey('tags', $content[0]); $this->assertArrayHasKey('created_at', $content[0]); $this->assertArrayHasKey('updated_at', $content[0]); + + $this->assertEquals($contentInDB->isArchived(), $content[0]['is_archived']); + $this->assertEquals($contentInDB->isStarred(), $content[0]['is_starred']); + $this->assertEquals($contentInDB->getTitle(), $content[0]['title']); + $this->assertEquals($contentInDB->getUrl(), $content[0]['url']); + $this->assertEquals([['text' => 'This is my annotation /o/', 'quote' => 'content']], $content[0]['annotations']); + $this->assertEquals($contentInDB->getMimetype(), $content[0]['mimetype']); + $this->assertEquals($contentInDB->getLanguage(), $content[0]['language']); + $this->assertEquals($contentInDB->getReadingtime(), $content[0]['reading_time']); + $this->assertEquals($contentInDB->getDomainname(), $content[0]['domain_name']); + $this->assertEquals(['foo', 'baz'], $content[0]['tags']); } public function testXmlExport() -- cgit v1.2.3 From 74e1f7433a5fc0a9bbf3942a22917e0dd1cc6923 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 2 Oct 2016 16:53:52 +0200 Subject: Fix tag test --- .../CoreBundle/Controller/ExportControllerTest.php | 2 +- .../CoreBundle/Controller/TagControllerTest.php | 26 +++++++++++++--------- 2 files changed, 16 insertions(+), 12 deletions(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php index 9f35a448..9ecd8bc4 100644 --- a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php @@ -193,7 +193,7 @@ class ExportControllerTest extends WallabagCoreTestCase $contentInDB = $client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneByUsernameAndNotArchived('admin'); + ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); ob_start(); $crawler = $client->request('GET', '/export/'.$contentInDB->getId().'.json'); diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index 2c32393f..86a6cca2 100644 --- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php @@ -26,7 +26,7 @@ class TagControllerTest extends WallabagCoreTestCase $entry = $client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneByUsernameAndNotArchived('admin'); + ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); $crawler = $client->request('GET', '/view/'.$entry->getId()); @@ -43,9 +43,9 @@ class TagControllerTest extends WallabagCoreTestCase $entry = $client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneByUsernameAndNotArchived('admin'); + ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); - $this->assertEquals(1, count($entry->getTags())); + $this->assertEquals(3, count($entry->getTags())); // tag already exists and already assigned $client->submit($form, $data); @@ -56,7 +56,7 @@ class TagControllerTest extends WallabagCoreTestCase ->getRepository('WallabagCoreBundle:Entry') ->find($entry->getId()); - $this->assertEquals(1, count($newEntry->getTags())); + $this->assertEquals(3, count($newEntry->getTags())); // tag already exists but still not assigned to this entry $data = [ @@ -71,7 +71,7 @@ class TagControllerTest extends WallabagCoreTestCase ->getRepository('WallabagCoreBundle:Entry') ->find($entry->getId()); - $this->assertEquals(2, count($newEntry->getTags())); + $this->assertEquals(3, count($newEntry->getTags())); } public function testAddMultipleTagToEntry() @@ -82,7 +82,7 @@ class TagControllerTest extends WallabagCoreTestCase $entry = $client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneByUsernameAndNotArchived('admin'); + ->findByUrlAndUserId('http://0.0.0.0/entry2', $this->getLoggedInUserId()); $crawler = $client->request('GET', '/view/'.$entry->getId()); @@ -101,9 +101,13 @@ class TagControllerTest extends WallabagCoreTestCase ->find($entry->getId()); $tags = $newEntry->getTags()->toArray(); + foreach ($tags as $key => $tag) { + $tags[$key] = $tag->getLabel(); + } + $this->assertGreaterThanOrEqual(2, count($tags)); - $this->assertNotEquals(false, array_search('foo2', $tags), 'Tag foo2 is assigned to the entry'); - $this->assertNotEquals(false, array_search('bar2', $tags), 'Tag bar2 is assigned to the entry'); + $this->assertNotFalse(array_search('foo2', $tags), 'Tag foo2 is assigned to the entry'); + $this->assertNotFalse(array_search('bar2', $tags), 'Tag bar2 is assigned to the entry'); } public function testRemoveTagFromEntry() @@ -114,7 +118,7 @@ class TagControllerTest extends WallabagCoreTestCase $entry = $client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneByUsernameAndNotArchived('admin'); + ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); $tag = $client->getContainer() ->get('doctrine.orm.entity_manager') @@ -140,7 +144,7 @@ class TagControllerTest extends WallabagCoreTestCase $entry = $client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneByUsernameAndNotArchived('admin'); + ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getLoggedInUserId()); $tag = $client->getContainer() ->get('doctrine.orm.entity_manager') @@ -160,6 +164,6 @@ class TagControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug()); $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->assertCount(0, $crawler->filter('div[class=entry]')); + $this->assertCount(1, $crawler->filter('div[class=entry]')); } } -- cgit v1.2.3 From 21d82c3c5d211ee3e30cf71d2de3ebac0d63da54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 7 Oct 2016 14:06:12 +0200 Subject: Added test for OpenGraph --- tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index c40e10a5..03267e76 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -753,7 +753,7 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertCount(2, $crawler->filter('div[class=entry]')); } - public function testCache() + public function testShareEntryPublicly() { $this->logInAs('admin'); $client = $this->getClient(); @@ -778,6 +778,9 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertContains('public', $client->getResponse()->headers->get('cache-control')); $this->assertContains('s-maxage=25200', $client->getResponse()->headers->get('cache-control')); $this->assertNotContains('no-cache', $client->getResponse()->headers->get('cache-control')); + $this->assertContains('og:title', $client->getResponse()->getContent()); + $this->assertContains('og:type', $client->getResponse()->getContent()); + $this->assertContains('og:url', $client->getResponse()->getContent()); // sharing is now disabled $client->getContainer()->get('craue_config')->set('share_public', 0); -- cgit v1.2.3 From 5e7786f3c4f279f78ff80df53480e21b50c3396b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 7 Oct 2016 14:56:26 +0200 Subject: Fixed two-factor checkbox display in user admin panel Fix #2380 --- tests/Wallabag/UserBundle/Controller/ManageControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php b/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php index 19b824b8..243a4459 100644 --- a/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php +++ b/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php @@ -23,7 +23,7 @@ class ManageControllerTest extends WallabagCoreTestCase // Create a new user in the database $crawler = $client->request('GET', '/users/'); - $this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /users/"); + $this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Unexpected HTTP status code for GET /users/'); $crawler = $client->click($crawler->selectLink('user.list.create_new_one')->link()); // Fill in the form and submit it -- cgit v1.2.3 From d5c45d5288f035ef36484b007cd6cc246fa65e19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 7 Oct 2016 15:21:31 +0200 Subject: Added default picture if preview picture is null --- tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 03267e76..d7bf03ba 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -781,6 +781,7 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertContains('og:title', $client->getResponse()->getContent()); $this->assertContains('og:type', $client->getResponse()->getContent()); $this->assertContains('og:url', $client->getResponse()->getContent()); + $this->assertContains('og:image', $client->getResponse()->getContent()); // sharing is now disabled $client->getContainer()->get('craue_config')->set('share_public', 0); -- cgit v1.2.3 From f0abc22d09d2e38d3dd408425821a89da3d21377 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 7 Oct 2016 20:37:01 +0200 Subject: Ability to check multiple urls in API --- .../ApiBundle/Controller/WallabagRestControllerTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php index 65b65290..4f16e70f 100644 --- a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php @@ -794,6 +794,22 @@ class WallabagRestControllerTest extends WallabagApiTestCase $this->assertEquals(true, $content['exists']); } + public function testGetEntriesExistsWithManyUrls() + { + $url1 = 'http://0.0.0.0/entry2'; + $url2 = 'http://0.0.0.0/entry10'; + $this->client->request('GET', '/api/entries/exists?urls[]='.$url1.'&urls[]='.$url2); + + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertArrayHasKey($url1, $content); + $this->assertArrayHasKey($url2, $content); + $this->assertEquals(true, $content[$url1]); + $this->assertEquals(false, $content[$url2]); + } + public function testGetEntriesExistsWhichDoesNotExists() { $this->client->request('GET', '/api/entries/exists?url=http://google.com/entry2'); -- cgit v1.2.3 From ac8cf632bb3a225c1b69d16e714ff60a2e988c89 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 7 Oct 2016 23:31:53 +0200 Subject: Ensure orphan tag are remove in API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the association between a tag and an entry is removed, if the tag doesn’t have other entries, we can remove it. Also add more tests for that part and ensure TagControllerTest is isolated from the rest of the test suite (finally!) --- .../Controller/WallabagRestControllerTest.php | 9 ++++++ .../CoreBundle/Controller/EntryControllerTest.php | 27 +++++++++--------- .../CoreBundle/Controller/TagControllerTest.php | 33 +++++++++++++++------- 3 files changed, 45 insertions(+), 24 deletions(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php index 65b65290..c797daf7 100644 --- a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php @@ -561,6 +561,8 @@ class WallabagRestControllerTest extends WallabagApiTestCase */ public function testDeleteUserTag($tag) { + $tagName = $tag['label']; + $this->client->request('DELETE', '/api/tags/'.$tag['id'].'.json'); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); @@ -577,6 +579,13 @@ class WallabagRestControllerTest extends WallabagApiTestCase ->findAllByTagId($this->user->getId(), $tag['id']); $this->assertCount(0, $entries); + + $tag = $this->client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Tag') + ->findOneByLabel($tagName); + + $this->assertNull($tag, $tagName.' was removed because it begun an orphan tag'); } public function testDeleteTagByLabel() diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index d7bf03ba..9b03a519 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -341,22 +341,23 @@ class EntryControllerTest extends WallabagCoreTestCase $this->logInAs('admin'); $client = $this->getClient(); - $content = $client->getContainer() - ->get('doctrine.orm.entity_manager') + $em = $client->getContainer() + ->get('doctrine.orm.entity_manager'); + + $content = $em ->getRepository('WallabagCoreBundle:Entry') ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); // empty content $content->setContent(''); - $client->getContainer()->get('doctrine.orm.entity_manager')->persist($content); - $client->getContainer()->get('doctrine.orm.entity_manager')->flush(); + $em->persist($content); + $em->flush(); $client->request('GET', '/reload/'.$content->getId()); $this->assertEquals(302, $client->getResponse()->getStatusCode()); - $content = $client->getContainer() - ->get('doctrine.orm.entity_manager') + $content = $em ->getRepository('WallabagCoreBundle:Entry') ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); @@ -486,9 +487,11 @@ class EntryControllerTest extends WallabagCoreTestCase $this->logInAs('admin'); $client = $this->getClient(); + $em = $client->getContainer() + ->get('doctrine.orm.entity_manager'); + // add a new content to be removed later - $user = $client->getContainer() - ->get('doctrine.orm.entity_manager') + $user = $em ->getRepository('WallabagUserBundle:User') ->findOneByUserName('admin'); @@ -502,12 +505,8 @@ class EntryControllerTest extends WallabagCoreTestCase $content->setArchived(true); $content->setLanguage('fr'); - $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->persist($content); - $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->flush(); + $em->persist($content); + $em->flush(); $client->request('GET', '/view/'.$content->getId()); $this->assertEquals(200, $client->getResponse()->getStatusCode()); diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index 86a6cca2..769ce66e 100644 --- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php @@ -3,6 +3,7 @@ namespace Tests\Wallabag\CoreBundle\Controller; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; +use Wallabag\CoreBundle\Entity\Tag; class TagControllerTest extends WallabagCoreTestCase { @@ -134,36 +135,48 @@ class TagControllerTest extends WallabagCoreTestCase $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); $this->assertEquals(404, $client->getResponse()->getStatusCode()); + + $tag = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Tag') + ->findOneByLabel($this->tagName); + + $this->assertNull($tag, $this->tagName.' was removed because it begun an orphan tag'); } public function testShowEntriesForTagAction() { $this->logInAs('admin'); $client = $this->getClient(); + $em = $client->getContainer() + ->get('doctrine.orm.entity_manager'); + + $tag = new Tag(); + $tag->setLabel($this->tagName); $entry = $client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getLoggedInUserId()); - $tag = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Tag') - ->findOneByEntryAndTagLabel($entry, 'foo'); - - $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug()); + $tag->addEntry($entry); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->assertCount(2, $crawler->filter('div[class=entry]')); + $em->persist($entry); + $em->persist($tag); + $em->flush(); $tag = $client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Tag') - ->findOneByLabel('baz'); + ->findOneByEntryAndTagLabel($entry, $this->tagName); $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug()); $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->assertCount(1, $crawler->filter('div[class=entry]')); + $this->assertCount(1, $crawler->filter('[id*="entry-"]')); + + $entry->removeTag($tag); + $em->remove($tag); + $em->flush(); } } -- cgit v1.2.3 From ee32248f43baef7e995c9e420cd00a137e626cf0 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 8 Oct 2016 00:02:22 +0200 Subject: Ensure access_token are removed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When we remove the client, we should ensure that access_token are also removed. To ensure that, I created a test that generated an access_token. So when we remove the client, this association should be cascaded and shouldn’t generate an error. Also I moved some Api related stuff to the ApiBundle (like the developer controler and ClientType form) --- .../Controller/DeveloperControllerTest.php | 104 +++++++++++++++++++++ .../Controller/DeveloperControllerTest.php | 78 ---------------- 2 files changed, 104 insertions(+), 78 deletions(-) create mode 100644 tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php delete mode 100644 tests/Wallabag/CoreBundle/Controller/DeveloperControllerTest.php (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php new file mode 100644 index 00000000..95befa9c --- /dev/null +++ b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php @@ -0,0 +1,104 @@ +logInAs('admin'); + $client = $this->getClient(); + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + $nbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); + + $crawler = $client->request('GET', '/developer/client/create'); + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $form = $crawler->filter('button[type=submit]')->form(); + + $data = [ + 'client[name]' => 'My app', + ]; + + $crawler = $client->submit($form, $data); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $newNbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); + $this->assertGreaterThan(count($nbClients), count($newNbClients)); + + $this->assertGreaterThan(1, $alert = $crawler->filter('.settings ul li strong')->extract(['_text'])); + $this->assertContains('My app', $alert[0]); + } + + /** + * @depends testCreateClient + */ + public function testCreateToken() + { + $client = $this->getClient(); + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + $apiClient = $em->getRepository('WallabagApiBundle:Client')->findOneByName('My app'); + + $client->request('POST', '/oauth/v2/token', [ + 'grant_type' => 'password', + 'client_id' => $apiClient->getPublicId(), + 'client_secret' => $apiClient->getSecret(), + 'username' => 'admin', + 'password' => 'mypassword', + ]); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $data = json_decode($client->getResponse()->getContent(), true); + $this->assertArrayHasKey('access_token', $data); + $this->assertArrayHasKey('expires_in', $data); + $this->assertArrayHasKey('token_type', $data); + $this->assertArrayHasKey('refresh_token', $data); + } + + public function testListingClient() + { + $this->logInAs('admin'); + $client = $this->getClient(); + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + $nbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); + + $crawler = $client->request('GET', '/developer'); + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(count($nbClients), $crawler->filter('ul[class=collapsible] li')->count()); + } + + public function testDeveloperHowto() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/developer/howto/first-app'); + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + } + + public function testRemoveClient() + { + $this->logInAs('admin'); + $client = $this->getClient(); + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + $nbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); + + $crawler = $client->request('GET', '/developer'); + + $link = $crawler + ->filter('div[class=collapsible-body] p a') + ->eq(0) + ->link() + ; + + $client->click($link); + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $newNbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); + $this->assertGreaterThan(count($newNbClients), count($nbClients)); + } +} diff --git a/tests/Wallabag/CoreBundle/Controller/DeveloperControllerTest.php b/tests/Wallabag/CoreBundle/Controller/DeveloperControllerTest.php deleted file mode 100644 index 97ed0d58..00000000 --- a/tests/Wallabag/CoreBundle/Controller/DeveloperControllerTest.php +++ /dev/null @@ -1,78 +0,0 @@ -logInAs('admin'); - $client = $this->getClient(); - $em = $client->getContainer()->get('doctrine.orm.entity_manager'); - $nbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); - - $crawler = $client->request('GET', '/developer/client/create'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - - $form = $crawler->filter('button[type=submit]')->form(); - - $data = [ - 'client[name]' => 'My app', - ]; - - $crawler = $client->submit($form, $data); - - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - - $newNbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); - $this->assertGreaterThan(count($nbClients), count($newNbClients)); - - $this->assertGreaterThan(1, $alert = $crawler->filter('.settings ul li strong')->extract(['_text'])); - $this->assertContains('My app', $alert[0]); - } - - public function testListingClient() - { - $this->logInAs('admin'); - $client = $this->getClient(); - $em = $client->getContainer()->get('doctrine.orm.entity_manager'); - $nbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); - - $crawler = $client->request('GET', '/developer'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->assertEquals(count($nbClients), $crawler->filter('ul[class=collapsible] li')->count()); - } - - public function testDeveloperHowto() - { - $this->logInAs('admin'); - $client = $this->getClient(); - - $crawler = $client->request('GET', '/developer/howto/first-app'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - } - - public function testRemoveClient() - { - $this->logInAs('admin'); - $client = $this->getClient(); - $em = $client->getContainer()->get('doctrine.orm.entity_manager'); - $nbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); - - $crawler = $client->request('GET', '/developer'); - - $link = $crawler - ->filter('div[class=collapsible-body] p a') - ->eq(0) - ->link() - ; - - $client->click($link); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); - - $newNbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); - $this->assertGreaterThan(count($newNbClients), count($nbClients)); - } -} -- cgit v1.2.3 From e40bed36077164cb6d83761a6554b6b88ad95097 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 10 Oct 2016 16:34:57 +0200 Subject: Avoid error when Redis isn't here in tests --- tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php | 1 + tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php | 1 + 2 files changed, 2 insertions(+) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php index 23c80bec..c0417bbe 100644 --- a/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php @@ -54,6 +54,7 @@ class ChromeControllerTest extends WallabagCoreTestCase public function testImportChromeWithRedisEnabled() { + $this->checkRedis(); $this->logInAs('admin'); $client = $this->getClient(); $client->getContainer()->get('craue_config')->set('import_with_redis', 1); diff --git a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php index 98f13d72..6154ae8d 100644 --- a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php @@ -54,6 +54,7 @@ class FirefoxControllerTest extends WallabagCoreTestCase public function testImportFirefoxWithRedisEnabled() { + $this->checkRedis(); $this->logInAs('admin'); $client = $this->getClient(); $client->getContainer()->get('craue_config')->set('import_with_redis', 1); -- cgit v1.2.3 From a0a4ce3135565d5d0e362da044e17ce8052bb272 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 11 Oct 2016 18:59:08 +0200 Subject: Lock deps for FOSUser MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We’ll wait until the final release will be out and other related project will be update to support it. Meanwhile we can safely lock to a previous version. --- tests/Wallabag/CoreBundle/WallabagCoreTestCase.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php index 4f103921..7bf4b43c 100644 --- a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php +++ b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php @@ -90,9 +90,7 @@ abstract class WallabagCoreTestCase extends WebTestCase try { $this->client->getContainer()->get('wallabag_core.redis.client')->connect(); } catch (\Exception $e) { - $this->markTestSkipped( - 'Redis is not installed/activated' - ); + $this->markTestSkipped('Redis is not installed/activated'); } } } -- cgit v1.2.3