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/CoreBundle') 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/CoreBundle') 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/CoreBundle') 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 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/CoreBundle') 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/CoreBundle') 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/CoreBundle') 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/CoreBundle') 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/CoreBundle') 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 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 --- tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'tests/Wallabag/CoreBundle') 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); } } -- 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 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests/Wallabag/CoreBundle') 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' + ); + } + } } -- 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 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'tests/Wallabag/CoreBundle') 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') -- 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 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/Wallabag/CoreBundle') 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() { -- cgit v1.2.3 From ca17abce2d3963e266bee905ab084ddfa7e1ff18 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist 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 ---------------------- 1 file changed, 91 deletions(-) delete mode 100644 tests/Wallabag/CoreBundle/EventListener/RegistrationConfirmedListenerTest.php (limited to 'tests/Wallabag/CoreBundle') 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 - ); - } -} -- 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/CoreBundle') 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/CoreBundle') 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/CoreBundle') 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 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/CoreBundle') 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/CoreBundle') 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/CoreBundle') 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 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/CoreBundle') 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 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/CoreBundle') 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/CoreBundle') 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/CoreBundle') 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 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/CoreBundle') 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 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!) --- .../CoreBundle/Controller/EntryControllerTest.php | 27 +++++++++--------- .../CoreBundle/Controller/TagControllerTest.php | 33 +++++++++++++++------- 2 files changed, 36 insertions(+), 24 deletions(-) (limited to 'tests/Wallabag/CoreBundle') 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 | 78 ---------------------- 1 file changed, 78 deletions(-) delete mode 100644 tests/Wallabag/CoreBundle/Controller/DeveloperControllerTest.php (limited to 'tests/Wallabag/CoreBundle') 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 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/CoreBundle') 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