From 531c8d0a5c55fa93438e227a7d349235fbd31d28 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Tue, 13 Jun 2017 18:48:10 +0200 Subject: Changed RSS to Atom feed and improve paging --- .../CoreBundle/Controller/ConfigControllerTest.php | 32 +-- .../CoreBundle/Controller/FeedControllerTest.php | 228 +++++++++++++++++++++ .../CoreBundle/Controller/RssControllerTest.php | 221 -------------------- .../Controller/SecurityControllerTest.php | 2 +- .../UsernameFeedTokenConverterTest.php | 218 ++++++++++++++++++++ .../UsernameRssTokenConverterTest.php | 218 -------------------- .../CoreBundle/Twig/WallabagExtensionTest.php | 25 +++ .../EventListener/CreateConfigListenerTest.php | 2 +- 8 files changed, 489 insertions(+), 457 deletions(-) create mode 100644 tests/Wallabag/CoreBundle/Controller/FeedControllerTest.php delete mode 100644 tests/Wallabag/CoreBundle/Controller/RssControllerTest.php create mode 100644 tests/Wallabag/CoreBundle/ParamConverter/UsernameFeedTokenConverterTest.php delete mode 100644 tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php (limited to 'tests') diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index 1090a686..d8478ce3 100644 --- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php @@ -33,7 +33,7 @@ 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=rss_config_save]')); + $this->assertCount(1, $crawler->filter('button[id=feed_config_save]')); } public function testUpdate() @@ -297,7 +297,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $this->assertContains('flashes.config.notice.user_updated', $alert[0]); } - public function testRssUpdateResetToken() + public function testFeedUpdateResetToken() { $this->logInAs('admin'); $client = $this->getClient(); @@ -313,7 +313,7 @@ class ConfigControllerTest extends WallabagCoreTestCase } $config = $user->getConfig(); - $config->setRssToken(null); + $config->setFeedToken(null); $em->persist($config); $em->flush(); @@ -322,7 +322,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $this->assertSame(200, $client->getResponse()->getStatusCode()); $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); - $this->assertContains('config.form_rss.no_token', $body[0]); + $this->assertContains('config.form_feed.no_token', $body[0]); $client->request('GET', '/generate-token'); $this->assertSame(302, $client->getResponse()->getStatusCode()); @@ -330,7 +330,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $crawler = $client->followRedirect(); $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); - $this->assertNotContains('config.form_rss.no_token', $body[0]); + $this->assertNotContains('config.form_feed.no_token', $body[0]); } public function testGenerateTokenAjax() @@ -351,7 +351,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $this->assertArrayHasKey('token', $content); } - public function testRssUpdate() + public function testFeedUpdate() { $this->logInAs('admin'); $client = $this->getClient(); @@ -360,10 +360,10 @@ class ConfigControllerTest extends WallabagCoreTestCase $this->assertSame(200, $client->getResponse()->getStatusCode()); - $form = $crawler->filter('button[id=rss_config_save]')->form(); + $form = $crawler->filter('button[id=feed_config_save]')->form(); $data = [ - 'rss_config[rss_limit]' => 12, + 'feed_config[feed_limit]' => 12, ]; $client->submit($form, $data); @@ -372,31 +372,31 @@ class ConfigControllerTest extends WallabagCoreTestCase $crawler = $client->followRedirect(); - $this->assertContains('flashes.config.notice.rss_updated', $crawler->filter('body')->extract(['_text'])[0]); + $this->assertContains('flashes.config.notice.feed_updated', $crawler->filter('body')->extract(['_text'])[0]); } - public function dataForRssFailed() + public function dataForFeedFailed() { return [ [ [ - 'rss_config[rss_limit]' => 0, + 'feed_config[feed_limit]' => 0, ], 'This value should be 1 or more.', ], [ [ - 'rss_config[rss_limit]' => 1000000000000, + 'feed_config[feed_limit]' => 1000000000000, ], - 'validator.rss_limit_too_high', + 'validator.feed_limit_too_high', ], ]; } /** - * @dataProvider dataForRssFailed + * @dataProvider dataForFeedFailed */ - public function testRssFailed($data, $expectedMessage) + public function testFeedFailed($data, $expectedMessage) { $this->logInAs('admin'); $client = $this->getClient(); @@ -405,7 +405,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $this->assertSame(200, $client->getResponse()->getStatusCode()); - $form = $crawler->filter('button[id=rss_config_save]')->form(); + $form = $crawler->filter('button[id=feed_config_save]')->form(); $crawler = $client->submit($form, $data); diff --git a/tests/Wallabag/CoreBundle/Controller/FeedControllerTest.php b/tests/Wallabag/CoreBundle/Controller/FeedControllerTest.php new file mode 100644 index 00000000..7442e8a4 --- /dev/null +++ b/tests/Wallabag/CoreBundle/Controller/FeedControllerTest.php @@ -0,0 +1,228 @@ +loadXML($xml); + + $xpath = new \DOMXpath($doc); + $xpath->registerNamespace('a', 'http://www.w3.org/2005/Atom'); + + if (null === $nb) { + $this->assertGreaterThan(0, $xpath->query('//a:entry')->length); + } else { + $this->assertEquals($nb, $xpath->query('//a:entry')->length); + } + + $this->assertEquals(1, $xpath->query('/a:feed')->length); + + $this->assertEquals(1, $xpath->query('/a:feed/a:title')->length); + $this->assertContains('favicon.ico', $xpath->query('/a:feed/a:icon')->item(0)->nodeValue); + $this->assertContains('logo-square.png', $xpath->query('/a:feed/a:logo')->item(0)->nodeValue); + + $this->assertEquals(1, $xpath->query('/a:feed/a:updated')->length); + + $this->assertEquals(1, $xpath->query('/a:feed/a:generator')->length); + $this->assertEquals('wallabag', $xpath->query('/a:feed/a:generator')->item(0)->nodeValue); + $this->assertEquals('admin', $xpath->query('/a:feed/a:author/a:name')->item(0)->nodeValue); + + $this->assertEquals(1, $xpath->query('/a:feed/a:subtitle')->length); + if (null !== $tagValue && 0 === strpos($type, 'tag')) { + $this->assertEquals('wallabag — '.$type.' '.$tagValue.' feed', $xpath->query('/a:feed/a:title')->item(0)->nodeValue); + $this->assertEquals('Atom feed for entries tagged with ' . $tagValue, $xpath->query('/a:feed/a:subtitle')->item(0)->nodeValue); + } else { + $this->assertEquals('wallabag — '.$type.' feed', $xpath->query('/a:feed/a:title')->item(0)->nodeValue); + $this->assertEquals('Atom feed for ' . $type . ' entries', $xpath->query('/a:feed/a:subtitle')->item(0)->nodeValue); + } + + $this->assertEquals(1, $xpath->query('/a:feed/a:link[@rel="self"]')->length); + $this->assertContains($type, $xpath->query('/a:feed/a:link[@rel="self"]')->item(0)->getAttribute('href')); + + $this->assertEquals(1, $xpath->query('/a:feed/a:link[@rel="last"]')->length); + + foreach ($xpath->query('//a:entry') as $item) { + $this->assertEquals(1, $xpath->query('a:title', $item)->length); + $this->assertEquals(1, $xpath->query('a:link[@rel="via"]', $item)->length); + $this->assertEquals(1, $xpath->query('a:link[@rel="alternate"]', $item)->length); + $this->assertEquals(1, $xpath->query('a:id', $item)->length); + $this->assertEquals(1, $xpath->query('a:published', $item)->length); + $this->assertEquals(1, $xpath->query('a:content', $item)->length); + } + } + + public function dataForBadUrl() + { + return [ + [ + '/feed/admin/YZIOAUZIAO/unread', + ], + [ + '/feed/wallace/YZIOAUZIAO/starred', + ], + [ + '/feed/wallace/YZIOAUZIAO/archives', + ], + [ + '/feed/wallace/YZIOAUZIAO/all', + ], + ]; + } + + /** + * @dataProvider dataForBadUrl + */ + public function testBadUrl($url) + { + $client = $this->getClient(); + + $client->request('GET', $url); + + $this->assertSame(404, $client->getResponse()->getStatusCode()); + } + + public function testUnread() + { + $client = $this->getClient(); + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + $user = $em + ->getRepository('WallabagUserBundle:User') + ->findOneByUsername('admin'); + + $config = $user->getConfig(); + $config->setFeedToken('SUPERTOKEN'); + $config->setFeedLimit(2); + $em->persist($config); + $em->flush(); + + $client->request('GET', '/feed/admin/SUPERTOKEN/unread'); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + $this->validateDom($client->getResponse()->getContent(), 'unread', 2); + } + + public function testStarred() + { + $client = $this->getClient(); + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + $user = $em + ->getRepository('WallabagUserBundle:User') + ->findOneByUsername('admin'); + + $config = $user->getConfig(); + $config->setFeedToken('SUPERTOKEN'); + $config->setFeedLimit(1); + $em->persist($config); + $em->flush(); + + $client = $this->getClient(); + $client->request('GET', '/feed/admin/SUPERTOKEN/starred'); + + $this->assertSame(200, $client->getResponse()->getStatusCode(), 1); + + $this->validateDom($client->getResponse()->getContent(), 'starred'); + } + + public function testArchives() + { + $client = $this->getClient(); + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + $user = $em + ->getRepository('WallabagUserBundle:User') + ->findOneByUsername('admin'); + + $config = $user->getConfig(); + $config->setFeedToken('SUPERTOKEN'); + $config->setFeedLimit(null); + $em->persist($config); + $em->flush(); + + $client = $this->getClient(); + $client->request('GET', '/feed/admin/SUPERTOKEN/archive'); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + $this->validateDom($client->getResponse()->getContent(), 'archive'); + } + + public function testAll() + { + $client = $this->getClient(); + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + $user = $em + ->getRepository('WallabagUserBundle:User') + ->findOneByUsername('admin'); + + $config = $user->getConfig(); + $config->setFeedToken('SUPERTOKEN'); + $config->setFeedLimit(null); + $em->persist($config); + $em->flush(); + + $client = $this->getClient(); + $client->request('GET', '/feed/admin/SUPERTOKEN/all'); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + $this->validateDom($client->getResponse()->getContent(), 'all'); + } + + public function testPagination() + { + $client = $this->getClient(); + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + $user = $em + ->getRepository('WallabagUserBundle:User') + ->findOneByUsername('admin'); + + $config = $user->getConfig(); + $config->setFeedToken('SUPERTOKEN'); + $config->setFeedLimit(1); + $em->persist($config); + $em->flush(); + + $client = $this->getClient(); + + $client->request('GET', '/feed/admin/SUPERTOKEN/unread'); + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->validateDom($client->getResponse()->getContent(), 'unread'); + + $client->request('GET', '/feed/admin/SUPERTOKEN/unread/2'); + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->validateDom($client->getResponse()->getContent(), 'unread'); + + $client->request('GET', '/feed/admin/SUPERTOKEN/unread/3000'); + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + } + + public function testTags() + { + $client = $this->getClient(); + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + $user = $em + ->getRepository('WallabagUserBundle:User') + ->findOneByUsername('admin'); + + $config = $user->getConfig(); + $config->setFeedToken('SUPERTOKEN'); + $config->setFeedLimit(null); + $em->persist($config); + $em->flush(); + + $client = $this->getClient(); + $client->request('GET', '/admin/SUPERTOKEN/tags/foo-bar.xml'); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + $this->validateDom($client->getResponse()->getContent(), 'tag', 2, 'foo-bar'); + + $client->request('GET', '/admin/SUPERTOKEN/tags/foo-bar.xml?page=3000'); + $this->assertSame(302, $client->getResponse()->getStatusCode()); + } +} diff --git a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php deleted file mode 100644 index afa90621..00000000 --- a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php +++ /dev/null @@ -1,221 +0,0 @@ -loadXML($xml); - - $xpath = new \DOMXPath($doc); - - if (null === $nb) { - $this->assertGreaterThan(0, $xpath->query('//item')->length); - } else { - $this->assertSame($nb, $xpath->query('//item')->length); - } - - $this->assertSame(1, $xpath->query('/rss')->length); - $this->assertSame(1, $xpath->query('/rss/channel')->length); - - $this->assertSame(1, $xpath->query('/rss/channel/title')->length); - $this->assertSame('wallabag - ' . $type . ' feed', $xpath->query('/rss/channel/title')->item(0)->nodeValue); - - $this->assertSame(1, $xpath->query('/rss/channel/pubDate')->length); - - $this->assertSame(1, $xpath->query('/rss/channel/generator')->length); - $this->assertSame('wallabag', $xpath->query('/rss/channel/generator')->item(0)->nodeValue); - - $this->assertSame(1, $xpath->query('/rss/channel/description')->length); - $this->assertSame('wallabag ' . $type . ' elements', $xpath->query('/rss/channel/description')->item(0)->nodeValue); - - $this->assertSame(1, $xpath->query('/rss/channel/link[@rel="self"]')->length); - $this->assertContains($urlPagination . '.xml', $xpath->query('/rss/channel/link[@rel="self"]')->item(0)->getAttribute('href')); - - $this->assertSame(1, $xpath->query('/rss/channel/link[@rel="last"]')->length); - $this->assertContains($urlPagination . '.xml?page=', $xpath->query('/rss/channel/link[@rel="last"]')->item(0)->getAttribute('href')); - - foreach ($xpath->query('//item') as $item) { - $this->assertSame(1, $xpath->query('title', $item)->length); - $this->assertSame(1, $xpath->query('source', $item)->length); - $this->assertSame(1, $xpath->query('link', $item)->length); - $this->assertSame(1, $xpath->query('guid', $item)->length); - $this->assertSame(1, $xpath->query('pubDate', $item)->length); - $this->assertSame(1, $xpath->query('description', $item)->length); - } - } - - public function dataForBadUrl() - { - return [ - [ - '/admin/YZIOAUZIAO/unread.xml', - ], - [ - '/wallace/YZIOAUZIAO/starred.xml', - ], - [ - '/wallace/YZIOAUZIAO/archives.xml', - ], - [ - '/wallace/YZIOAUZIAO/all.xml', - ], - ]; - } - - /** - * @dataProvider dataForBadUrl - */ - public function testBadUrl($url) - { - $client = $this->getClient(); - - $client->request('GET', $url); - - $this->assertSame(404, $client->getResponse()->getStatusCode()); - } - - public function testUnread() - { - $client = $this->getClient(); - $em = $client->getContainer()->get('doctrine.orm.entity_manager'); - $user = $em - ->getRepository('WallabagUserBundle:User') - ->findOneByUsername('admin'); - - $config = $user->getConfig(); - $config->setRssToken('SUPERTOKEN'); - $config->setRssLimit(2); - $em->persist($config); - $em->flush(); - - $client->request('GET', '/admin/SUPERTOKEN/unread.xml'); - - $this->assertSame(200, $client->getResponse()->getStatusCode()); - - $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread', 2); - } - - public function testStarred() - { - $client = $this->getClient(); - $em = $client->getContainer()->get('doctrine.orm.entity_manager'); - $user = $em - ->getRepository('WallabagUserBundle:User') - ->findOneByUsername('admin'); - - $config = $user->getConfig(); - $config->setRssToken('SUPERTOKEN'); - $config->setRssLimit(1); - $em->persist($config); - $em->flush(); - - $client = $this->getClient(); - $client->request('GET', '/admin/SUPERTOKEN/starred.xml'); - - $this->assertSame(200, $client->getResponse()->getStatusCode(), 1); - - $this->validateDom($client->getResponse()->getContent(), 'starred', 'starred'); - } - - public function testArchives() - { - $client = $this->getClient(); - $em = $client->getContainer()->get('doctrine.orm.entity_manager'); - $user = $em - ->getRepository('WallabagUserBundle:User') - ->findOneByUsername('admin'); - - $config = $user->getConfig(); - $config->setRssToken('SUPERTOKEN'); - $config->setRssLimit(null); - $em->persist($config); - $em->flush(); - - $client = $this->getClient(); - $client->request('GET', '/admin/SUPERTOKEN/archive.xml'); - - $this->assertSame(200, $client->getResponse()->getStatusCode()); - - $this->validateDom($client->getResponse()->getContent(), 'archive', 'archive'); - } - - public function testAll() - { - $client = $this->getClient(); - $em = $client->getContainer()->get('doctrine.orm.entity_manager'); - $user = $em - ->getRepository('WallabagUserBundle:User') - ->findOneByUsername('admin'); - - $config = $user->getConfig(); - $config->setRssToken('SUPERTOKEN'); - $config->setRssLimit(null); - $em->persist($config); - $em->flush(); - - $client = $this->getClient(); - $client->request('GET', '/admin/SUPERTOKEN/all.xml'); - - $this->assertSame(200, $client->getResponse()->getStatusCode()); - - $this->validateDom($client->getResponse()->getContent(), 'all', 'all'); - } - - public function testPagination() - { - $client = $this->getClient(); - $em = $client->getContainer()->get('doctrine.orm.entity_manager'); - $user = $em - ->getRepository('WallabagUserBundle:User') - ->findOneByUsername('admin'); - - $config = $user->getConfig(); - $config->setRssToken('SUPERTOKEN'); - $config->setRssLimit(1); - $em->persist($config); - $em->flush(); - - $client = $this->getClient(); - - $client->request('GET', '/admin/SUPERTOKEN/unread.xml'); - $this->assertSame(200, $client->getResponse()->getStatusCode()); - $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread'); - - $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=2'); - $this->assertSame(200, $client->getResponse()->getStatusCode()); - $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread'); - - $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=3000'); - $this->assertSame(302, $client->getResponse()->getStatusCode()); - } - - public function testTags() - { - $client = $this->getClient(); - $em = $client->getContainer()->get('doctrine.orm.entity_manager'); - $user = $em - ->getRepository('WallabagUserBundle:User') - ->findOneByUsername('admin'); - - $config = $user->getConfig(); - $config->setRssToken('SUPERTOKEN'); - $config->setRssLimit(null); - $em->persist($config); - $em->flush(); - - $client = $this->getClient(); - $client->request('GET', '/admin/SUPERTOKEN/tags/foo.xml'); - - $this->assertSame(200, $client->getResponse()->getStatusCode()); - - $this->validateDom($client->getResponse()->getContent(), 'tag (foo)', 'tags/foo'); - - $client->request('GET', '/admin/SUPERTOKEN/tags/foo.xml?page=3000'); - $this->assertSame(302, $client->getResponse()->getStatusCode()); - } -} diff --git a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php index b03c7550..3c3354d7 100644 --- a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php @@ -23,7 +23,7 @@ class SecurityControllerTest extends WallabagCoreTestCase $client->followRedirects(); $crawler = $client->request('GET', '/config'); - $this->assertContains('config.form_rss.description', $crawler->filter('body')->extract(['_text'])[0]); + $this->assertContains('config.form_feed.description', $crawler->filter('body')->extract(['_text'])[0]); } public function testLoginWith2FactorEmail() diff --git a/tests/Wallabag/CoreBundle/ParamConverter/UsernameFeedTokenConverterTest.php b/tests/Wallabag/CoreBundle/ParamConverter/UsernameFeedTokenConverterTest.php new file mode 100644 index 00000000..92fe38cd --- /dev/null +++ b/tests/Wallabag/CoreBundle/ParamConverter/UsernameFeedTokenConverterTest.php @@ -0,0 +1,218 @@ +assertFalse($converter->supports($params)); + } + + public function testSupportsWithNoRegistryManagers() + { + $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') + ->disableOriginalConstructor() + ->getMock(); + + $registry->expects($this->once()) + ->method('getManagers') + ->will($this->returnValue([])); + + $params = new ParamConverter([]); + $converter = new UsernameFeedTokenConverter($registry); + + $this->assertFalse($converter->supports($params)); + } + + public function testSupportsWithNoConfigurationClass() + { + $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') + ->disableOriginalConstructor() + ->getMock(); + + $registry->expects($this->once()) + ->method('getManagers') + ->will($this->returnValue(['default' => null])); + + $params = new ParamConverter([]); + $converter = new UsernameFeedTokenConverter($registry); + + $this->assertFalse($converter->supports($params)); + } + + public function testSupportsWithNotTheGoodClass() + { + $meta = $this->getMockBuilder('Doctrine\Common\Persistence\Mapping\ClassMetadata') + ->disableOriginalConstructor() + ->getMock(); + + $meta->expects($this->once()) + ->method('getName') + ->will($this->returnValue('nothingrelated')); + + $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') + ->disableOriginalConstructor() + ->getMock(); + + $em->expects($this->once()) + ->method('getClassMetadata') + ->with('superclass') + ->will($this->returnValue($meta)); + + $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') + ->disableOriginalConstructor() + ->getMock(); + + $registry->expects($this->once()) + ->method('getManagers') + ->will($this->returnValue(['default' => null])); + + $registry->expects($this->once()) + ->method('getManagerForClass') + ->with('superclass') + ->will($this->returnValue($em)); + + $params = new ParamConverter(['class' => 'superclass']); + $converter = new UsernameFeedTokenConverter($registry); + + $this->assertFalse($converter->supports($params)); + } + + public function testSupportsWithGoodClass() + { + $meta = $this->getMockBuilder('Doctrine\Common\Persistence\Mapping\ClassMetadata') + ->disableOriginalConstructor() + ->getMock(); + + $meta->expects($this->once()) + ->method('getName') + ->will($this->returnValue('Wallabag\UserBundle\Entity\User')); + + $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') + ->disableOriginalConstructor() + ->getMock(); + + $em->expects($this->once()) + ->method('getClassMetadata') + ->with('WallabagUserBundle:User') + ->will($this->returnValue($meta)); + + $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') + ->disableOriginalConstructor() + ->getMock(); + + $registry->expects($this->once()) + ->method('getManagers') + ->will($this->returnValue(['default' => null])); + + $registry->expects($this->once()) + ->method('getManagerForClass') + ->with('WallabagUserBundle:User') + ->will($this->returnValue($em)); + + $params = new ParamConverter(['class' => 'WallabagUserBundle:User']); + $converter = new UsernameFeedTokenConverter($registry); + + $this->assertTrue($converter->supports($params)); + } + + public function testApplyEmptyRequest() + { + $params = new ParamConverter([]); + $converter = new UsernameFeedTokenConverter(); + + $res = $converter->apply(new Request(), $params); + + $this->assertFalse($res); + } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException + * @expectedExceptionMessage User not found + */ + public function testApplyUserNotFound() + { + $repo = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') + ->disableOriginalConstructor() + ->getMock(); + + $repo->expects($this->once()) + ->method('findOneByUsernameAndFeedToken') + ->with('test', 'test') + ->will($this->returnValue(null)); + + $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') + ->disableOriginalConstructor() + ->getMock(); + + $em->expects($this->once()) + ->method('getRepository') + ->with('WallabagUserBundle:User') + ->will($this->returnValue($repo)); + + $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') + ->disableOriginalConstructor() + ->getMock(); + + $registry->expects($this->once()) + ->method('getManagerForClass') + ->with('WallabagUserBundle:User') + ->will($this->returnValue($em)); + + $params = new ParamConverter(['class' => 'WallabagUserBundle:User']); + $converter = new UsernameFeedTokenConverter($registry); + $request = new Request([], [], ['username' => 'test', 'token' => 'test']); + + $converter->apply($request, $params); + } + + public function testApplyUserFound() + { + $user = new User(); + + $repo = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') + ->disableOriginalConstructor() + ->getMock(); + + $repo->expects($this->once()) + ->method('findOneByUsernameAndFeedtoken') + ->with('test', 'test') + ->will($this->returnValue($user)); + + $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') + ->disableOriginalConstructor() + ->getMock(); + + $em->expects($this->once()) + ->method('getRepository') + ->with('WallabagUserBundle:User') + ->will($this->returnValue($repo)); + + $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') + ->disableOriginalConstructor() + ->getMock(); + + $registry->expects($this->once()) + ->method('getManagerForClass') + ->with('WallabagUserBundle:User') + ->will($this->returnValue($em)); + + $params = new ParamConverter(['class' => 'WallabagUserBundle:User', 'name' => 'user']); + $converter = new UsernameFeedTokenConverter($registry); + $request = new Request([], [], ['username' => 'test', 'token' => 'test']); + + $converter->apply($request, $params); + + $this->assertSame($user, $request->attributes->get('user')); + } +} diff --git a/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php b/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php deleted file mode 100644 index 800af5c9..00000000 --- a/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php +++ /dev/null @@ -1,218 +0,0 @@ -assertFalse($converter->supports($params)); - } - - public function testSupportsWithNoRegistryManagers() - { - $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') - ->disableOriginalConstructor() - ->getMock(); - - $registry->expects($this->once()) - ->method('getManagers') - ->will($this->returnValue([])); - - $params = new ParamConverter([]); - $converter = new UsernameRssTokenConverter($registry); - - $this->assertFalse($converter->supports($params)); - } - - public function testSupportsWithNoConfigurationClass() - { - $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') - ->disableOriginalConstructor() - ->getMock(); - - $registry->expects($this->once()) - ->method('getManagers') - ->will($this->returnValue(['default' => null])); - - $params = new ParamConverter([]); - $converter = new UsernameRssTokenConverter($registry); - - $this->assertFalse($converter->supports($params)); - } - - public function testSupportsWithNotTheGoodClass() - { - $meta = $this->getMockBuilder('Doctrine\Common\Persistence\Mapping\ClassMetadata') - ->disableOriginalConstructor() - ->getMock(); - - $meta->expects($this->once()) - ->method('getName') - ->will($this->returnValue('nothingrelated')); - - $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') - ->disableOriginalConstructor() - ->getMock(); - - $em->expects($this->once()) - ->method('getClassMetadata') - ->with('superclass') - ->will($this->returnValue($meta)); - - $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') - ->disableOriginalConstructor() - ->getMock(); - - $registry->expects($this->once()) - ->method('getManagers') - ->will($this->returnValue(['default' => null])); - - $registry->expects($this->once()) - ->method('getManagerForClass') - ->with('superclass') - ->will($this->returnValue($em)); - - $params = new ParamConverter(['class' => 'superclass']); - $converter = new UsernameRssTokenConverter($registry); - - $this->assertFalse($converter->supports($params)); - } - - public function testSupportsWithGoodClass() - { - $meta = $this->getMockBuilder('Doctrine\Common\Persistence\Mapping\ClassMetadata') - ->disableOriginalConstructor() - ->getMock(); - - $meta->expects($this->once()) - ->method('getName') - ->will($this->returnValue('Wallabag\UserBundle\Entity\User')); - - $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') - ->disableOriginalConstructor() - ->getMock(); - - $em->expects($this->once()) - ->method('getClassMetadata') - ->with('WallabagUserBundle:User') - ->will($this->returnValue($meta)); - - $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') - ->disableOriginalConstructor() - ->getMock(); - - $registry->expects($this->once()) - ->method('getManagers') - ->will($this->returnValue(['default' => null])); - - $registry->expects($this->once()) - ->method('getManagerForClass') - ->with('WallabagUserBundle:User') - ->will($this->returnValue($em)); - - $params = new ParamConverter(['class' => 'WallabagUserBundle:User']); - $converter = new UsernameRssTokenConverter($registry); - - $this->assertTrue($converter->supports($params)); - } - - public function testApplyEmptyRequest() - { - $params = new ParamConverter([]); - $converter = new UsernameRssTokenConverter(); - - $res = $converter->apply(new Request(), $params); - - $this->assertFalse($res); - } - - /** - * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException - * @expectedExceptionMessage User not found - */ - public function testApplyUserNotFound() - { - $repo = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') - ->disableOriginalConstructor() - ->getMock(); - - $repo->expects($this->once()) - ->method('findOneByUsernameAndRsstoken') - ->with('test', 'test') - ->will($this->returnValue(null)); - - $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') - ->disableOriginalConstructor() - ->getMock(); - - $em->expects($this->once()) - ->method('getRepository') - ->with('WallabagUserBundle:User') - ->will($this->returnValue($repo)); - - $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') - ->disableOriginalConstructor() - ->getMock(); - - $registry->expects($this->once()) - ->method('getManagerForClass') - ->with('WallabagUserBundle:User') - ->will($this->returnValue($em)); - - $params = new ParamConverter(['class' => 'WallabagUserBundle:User']); - $converter = new UsernameRssTokenConverter($registry); - $request = new Request([], [], ['username' => 'test', 'token' => 'test']); - - $converter->apply($request, $params); - } - - public function testApplyUserFound() - { - $user = new User(); - - $repo = $this->getMockBuilder('Wallabag\UserBundle\Repository\UserRepository') - ->disableOriginalConstructor() - ->getMock(); - - $repo->expects($this->once()) - ->method('findOneByUsernameAndRsstoken') - ->with('test', 'test') - ->will($this->returnValue($user)); - - $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') - ->disableOriginalConstructor() - ->getMock(); - - $em->expects($this->once()) - ->method('getRepository') - ->with('WallabagUserBundle:User') - ->will($this->returnValue($repo)); - - $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') - ->disableOriginalConstructor() - ->getMock(); - - $registry->expects($this->once()) - ->method('getManagerForClass') - ->with('WallabagUserBundle:User') - ->will($this->returnValue($em)); - - $params = new ParamConverter(['class' => 'WallabagUserBundle:User', 'name' => 'user']); - $converter = new UsernameRssTokenConverter($registry); - $request = new Request([], [], ['username' => 'test', 'token' => 'test']); - - $converter->apply($request, $params); - - $this->assertSame($user, $request->attributes->get('user')); - } -} diff --git a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php index bb92f745..3fd90fda 100644 --- a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php +++ b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php @@ -32,6 +32,31 @@ class WallabagExtensionTest extends TestCase $this->assertSame('gist.github.com', $extension->removeWww('gist.github.com')); } + public function testRemoveScheme() + { + $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->removeScheme('lemonde.fr')); + $this->assertEquals('gist.github.com', $extension->removeScheme('gist.github.com')); + $this->assertEquals('gist.github.com', $extension->removeScheme('https://gist.github.com')); + } + public function testRemoveSchemeAndWww() { $entryRepository = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') diff --git a/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php b/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php index c13bfbea..fd32f380 100644 --- a/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php +++ b/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php @@ -62,7 +62,7 @@ class CreateConfigListenerTest extends TestCase $config = new Config($user); $config->setTheme('baggy'); $config->setItemsPerPage(20); - $config->setRssLimit(50); + $config->setFeedLimit(50); $config->setLanguage('fr'); $config->setReadingSpeed(1); -- cgit v1.2.3