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') 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 00f2368f7a99679aba7cd16e3d5cdbb072def562 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 15 Oct 2017 18:41:58 +0200 Subject: Add some tests for OriginUrl in EntryRestController Signed-off-by: Kevin Decherf --- .../Controller/EntryRestControllerTest.php | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 95c64501..ed104df3 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -36,6 +36,25 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); } + public function testGetOneEntryWithOriginUrl() + { + $entry = $this->client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneBy(['user' => 1, 'url' => 'http://0.0.0.0/entry2']); + + if (!$entry) { + $this->markTestSkipped('No content found in db.'); + } + + $this->client->request('GET', '/api/entries/' . $entry->getId() . '.json'); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertSame($entry->getOriginUrl(), $content['origin_url']); + } + public function testExportEntry() { $entry = $this->client->getContainer() @@ -531,6 +550,29 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertSame(1, $content['is_starred']); } + public function testPostEntryWithOriginUrl() + { + $this->client->request('POST', '/api/entries.json', [ + 'url' => 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', + 'tags' => 'google', + 'title' => 'New title for my article', + 'content' => 'my content', + 'language' => 'de', + 'published_at' => '2016-09-08T11:55:58+0200', + 'authors' => 'bob,helen', + 'public' => 1, + 'origin_url' => 'http://mysource.tld', + ]); + + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertGreaterThan(0, $content['id']); + $this->assertSame('http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', $content['url']); + $this->assertSame('http://mysource.tld', $content['origin_url']); + } + public function testPatchEntry() { $entry = $this->client->getContainer() @@ -607,6 +649,37 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertSame($previousLanguage, $content['language'], 'Ensure language has not moved'); } + public function testPatchEntryWithOriginUrl() + { + $entry = $this->client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneByUser(1); + + if (!$entry) { + $this->markTestSkipped('No content found in db.'); + } + + $previousContent = $entry->getContent(); + $previousLanguage = $entry->getLanguage(); + + $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [ + 'title' => 'Another awesome title just for profit', + 'origin_url' => 'https://myawesomesource.example.com', + ]); + + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertSame($entry->getId(), $content['id']); + $this->assertSame($entry->getUrl(), $content['url']); + $this->assertSame('https://myawesomesource.example.com', $content['origin_url']); + $this->assertEmpty($content['published_by'], 'Authors were not saved because of an array instead of a string'); + $this->assertSame($previousContent, $content['content'], 'Ensure content has not moved'); + $this->assertSame($previousLanguage, $content['language'], 'Ensure language has not moved'); + } + public function testGetTagsEntry() { $entry = $this->client->getContainer() -- 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') 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 65152fcb899e1d073847718e2f7847180fa26a40 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 19 Nov 2017 15:01:06 +0100 Subject: Improve EntryRestControllerTest for origin_url Ensure that origin_url is initially null Ensure patching entry with origin_url='' Ensure patching entry with origin_url=null Signed-off-by: Kevin Decherf --- .../Controller/EntryRestControllerTest.php | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index ed104df3..8f0effee 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -440,6 +440,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertSame('New title for my article', $content['title']); $this->assertSame(1, $content['user_id']); $this->assertCount(2, $content['tags']); + $this->assertNull($content['origin_url']); $this->assertSame('my content', $content['content']); $this->assertSame('de', $content['language']); $this->assertSame('2016-09-08T11:55:58+0200', $content['published_at']); @@ -680,6 +681,60 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertSame($previousLanguage, $content['language'], 'Ensure language has not moved'); } + public function testPatchEntryRemoveOriginUrl() + { + $entry = $this->client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneByUser(1); + + if (!$entry) { + $this->markTestSkipped('No content found in db.'); + } + + $previousContent = $entry->getContent(); + $previousLanguage = $entry->getLanguage(); + $previousTitle = $entry->getTitle(); + + $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [ + 'origin_url' => '', + ]); + + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertSame($entry->getId(), $content['id']); + $this->assertSame($entry->getUrl(), $content['url']); + $this->assertEmpty($content['origin_url']); + $this->assertEmpty($content['published_by'], 'Authors were not saved because of an array instead of a string'); + $this->assertSame($previousContent, $content['content'], 'Ensure content has not moved'); + $this->assertSame($previousLanguage, $content['language'], 'Ensure language has not moved'); + $this->assertSame($previousTitle, $content['title'], 'Ensure title has not moved'); + } + + public function testPatchEntryNullOriginUrl() + { + $entry = $this->client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneByUser(1); + + if (!$entry) { + $this->markTestSkipped('No content found in db.'); + } + + $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [ + 'origin_url' => null, + ]); + + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertNull($content['origin_url']); + } + public function testGetTagsEntry() { $entry = $this->client->getContainer() -- 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 --- .../Controller/EntryRestControllerTest.php | 34 +++++++++++----------- .../CoreBundle/Controller/EntryControllerTest.php | 2 +- .../CoreBundle/Twig/WallabagExtensionTest.php | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 8f0effee..65a3ccd9 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -712,28 +712,28 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertSame($previousLanguage, $content['language'], 'Ensure language has not moved'); $this->assertSame($previousTitle, $content['title'], 'Ensure title has not moved'); } - - public function testPatchEntryNullOriginUrl() - { - $entry = $this->client->getContainer() + + public function testPatchEntryNullOriginUrl() + { + $entry = $this->client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') ->findOneByUser(1); - - if (!$entry) { - $this->markTestSkipped('No content found in db.'); - } - - $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [ + + if (!$entry) { + $this->markTestSkipped('No content found in db.'); + } + + $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [ 'origin_url' => null, ]); - - $this->assertSame(200, $this->client->getResponse()->getStatusCode()); - - $content = json_decode($this->client->getResponse()->getContent(), true); - - $this->assertNull($content['origin_url']); - } + + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertNull($content['origin_url']); + } public function testGetTagsEntry() { 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