From e50e45d6fa64aea8b6b96f60073fb36960322aa8 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sat, 9 Sep 2017 19:34:41 +0200 Subject: Twig: add removeSchemeAndWww filter This twig filter removes scheme (only http and https are supported) and pass the result to removeWww filter to also remove 'www.' at the beginning of an url. Signed-off-by: Kevin Decherf --- .../CoreBundle/Twig/WallabagExtensionTest.php | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php index ceec4b37..27989346 100644 --- a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php +++ b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php @@ -30,4 +30,31 @@ class WallabagExtensionTest extends \PHPUnit_Framework_TestCase $this->assertSame('lemonde.fr', $extension->removeWww('lemonde.fr')); $this->assertSame('gist.github.com', $extension->removeWww('gist.github.com')); } + + public function testRemoveSchemeAndWww() + { + $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->assertSame('lemonde.fr', $extension->removeSchemeAndWww('www.lemonde.fr')); + $this->assertSame('lemonde.fr', $extension->removeSchemeAndWww('http://lemonde.fr')); + $this->assertSame('lemonde.fr', $extension->removeSchemeAndWww('https://www.lemonde.fr')); + $this->assertSame('gist.github.com', $extension->removeSchemeAndWww('https://gist.github.com')); + $this->assertSame('ftp://gist.github.com', $extension->removeSchemeAndWww('ftp://gist.github.com')); + } } -- cgit v1.2.3 From 97444566db31c287103468ee64e2b234d223a354 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 19 Nov 2017 14:50:21 +0100 Subject: Update EntryControllerTest to handle origin_url Set an origin_url in testEditUpdate Test origin_url deletion in testEditRemoveOriginUrl Signed-off-by: Kevin Decherf --- .../CoreBundle/Controller/EntryControllerTest.php | 40 ++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 6e806553..e2fb8d78 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -475,6 +475,7 @@ class EntryControllerTest extends WallabagCoreTestCase $data = [ 'entry[title]' => 'My updated title hehe :)', + 'entry[origin_url]' => 'https://example.io', ]; $client->submit($form, $data); @@ -483,8 +484,43 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->followRedirect(); - $this->assertGreaterThan(1, $alert = $crawler->filter('div[id=article] h1')->extract(['_text'])); - $this->assertContains('My updated title hehe :)', $alert[0]); + $this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text'])); + $this->assertContains('My updated title hehe :)', $title[0]); + $this->assertGreaterThan(1, $stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text'])); + $this->assertContains('example.io', trim($stats[1])); + } + + public function testEditRemoveOriginUrl() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $entry = new Entry($this->getLoggedInUser()); + $entry->setUrl($this->url); + $this->getEntityManager()->persist($entry); + $this->getEntityManager()->flush(); + + $crawler = $client->request('GET', '/edit/' . $entry->getId()); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + $form = $crawler->filter('button[type=submit]')->form(); + + $data = [ + 'entry[title]' => 'My updated title hehe :)', + 'entry[origin_url]' => '', + ]; + + $client->submit($form, $data); + + $this->assertSame(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text'])); + $this->assertContains('My updated title hehe :)', $title[0]); + $this->assertSame(1, sizeof($stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']))); + $this->assertNotContains('example.io', trim($stats[0])); } public function testToggleArchive() -- cgit v1.2.3 From eae8138b33e4ed4a5d1a98daf77941ef691629de Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 19 Nov 2017 15:26:13 +0100 Subject: Fix phpcs Signed-off-by: Kevin Decherf --- tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | 2 +- tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index e2fb8d78..c6a523e3 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -519,7 +519,7 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text'])); $this->assertContains('My updated title hehe :)', $title[0]); - $this->assertSame(1, sizeof($stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']))); + $this->assertSame(1, count($stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']))); $this->assertNotContains('example.io', trim($stats[0])); } diff --git a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php index 27989346..82336060 100644 --- a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php +++ b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php @@ -50,7 +50,7 @@ class WallabagExtensionTest extends \PHPUnit_Framework_TestCase ->getMock(); $extension = new WallabagExtension($entryRepository, $tagRepository, $tokenStorage, 0, $translator); - + $this->assertSame('lemonde.fr', $extension->removeSchemeAndWww('www.lemonde.fr')); $this->assertSame('lemonde.fr', $extension->removeSchemeAndWww('http://lemonde.fr')); $this->assertSame('lemonde.fr', $extension->removeSchemeAndWww('https://www.lemonde.fr')); -- cgit v1.2.3