diff options
-rw-r--r-- | src/Wallabag/CoreBundle/Twig/WallabagExtension.php | 8 | ||||
-rw-r--r-- | tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php | 27 |
2 files changed, 35 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php index 351172c4..8992117e 100644 --- a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php +++ b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php | |||
@@ -28,6 +28,7 @@ class WallabagExtension extends \Twig_Extension implements \Twig_Extension_Globa | |||
28 | { | 28 | { |
29 | return [ | 29 | return [ |
30 | new \Twig_SimpleFilter('removeWww', [$this, 'removeWww']), | 30 | new \Twig_SimpleFilter('removeWww', [$this, 'removeWww']), |
31 | new \Twig_SimpleFilter('removeSchemeAndWww', [$this, 'removeSchemeAndWww']), | ||
31 | ]; | 32 | ]; |
32 | } | 33 | } |
33 | 34 | ||
@@ -45,6 +46,13 @@ class WallabagExtension extends \Twig_Extension implements \Twig_Extension_Globa | |||
45 | return preg_replace('/^www\./i', '', $url); | 46 | return preg_replace('/^www\./i', '', $url); |
46 | } | 47 | } |
47 | 48 | ||
49 | public function removeSchemeAndWww($url) | ||
50 | { | ||
51 | return $this->removeWww( | ||
52 | preg_replace('@^https?://@i', '', $url) | ||
53 | ); | ||
54 | } | ||
55 | |||
48 | /** | 56 | /** |
49 | * Return number of entries depending of the type (unread, archive, starred or all). | 57 | * Return number of entries depending of the type (unread, archive, starred or all). |
50 | * | 58 | * |
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 | |||
30 | $this->assertSame('lemonde.fr', $extension->removeWww('lemonde.fr')); | 30 | $this->assertSame('lemonde.fr', $extension->removeWww('lemonde.fr')); |
31 | $this->assertSame('gist.github.com', $extension->removeWww('gist.github.com')); | 31 | $this->assertSame('gist.github.com', $extension->removeWww('gist.github.com')); |
32 | } | 32 | } |
33 | |||
34 | public function testRemoveSchemeAndWww() | ||
35 | { | ||
36 | $entryRepository = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | ||
37 | ->disableOriginalConstructor() | ||
38 | ->getMock(); | ||
39 | |||
40 | $tagRepository = $this->getMockBuilder('Wallabag\CoreBundle\Repository\TagRepository') | ||
41 | ->disableOriginalConstructor() | ||
42 | ->getMock(); | ||
43 | |||
44 | $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface') | ||
45 | ->disableOriginalConstructor() | ||
46 | ->getMock(); | ||
47 | |||
48 | $translator = $this->getMockBuilder('Symfony\Component\Translation\TranslatorInterface') | ||
49 | ->disableOriginalConstructor() | ||
50 | ->getMock(); | ||
51 | |||
52 | $extension = new WallabagExtension($entryRepository, $tagRepository, $tokenStorage, 0, $translator); | ||
53 | |||
54 | $this->assertSame('lemonde.fr', $extension->removeSchemeAndWww('www.lemonde.fr')); | ||
55 | $this->assertSame('lemonde.fr', $extension->removeSchemeAndWww('http://lemonde.fr')); | ||
56 | $this->assertSame('lemonde.fr', $extension->removeSchemeAndWww('https://www.lemonde.fr')); | ||
57 | $this->assertSame('gist.github.com', $extension->removeSchemeAndWww('https://gist.github.com')); | ||
58 | $this->assertSame('ftp://gist.github.com', $extension->removeSchemeAndWww('ftp://gist.github.com')); | ||
59 | } | ||
33 | } | 60 | } |