From 8670250a2674b6b388f3d40a8ba291a4dca41b82 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 19 Nov 2016 14:53:28 +0100 Subject: Add RSS pagination Following https://tools.ietf.org/html/rfc5005#page-4 --- .../CoreBundle/Controller/RssControllerTest.php | 57 ++++++++++++++++++++-- 1 file changed, 53 insertions(+), 4 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php index fb6fe06a..1d6c02b2 100644 --- a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php @@ -6,7 +6,7 @@ use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; class RssControllerTest extends WallabagCoreTestCase { - public function validateDom($xml, $nb = null) + public function validateDom($xml, $type, $nb = null) { $doc = new \DOMDocument(); $doc->loadXML($xml); @@ -22,6 +22,23 @@ class RssControllerTest extends WallabagCoreTestCase $this->assertEquals(1, $xpath->query('/rss')->length); $this->assertEquals(1, $xpath->query('/rss/channel')->length); + $this->assertEquals(1, $xpath->query('/rss/channel/title')->length); + $this->assertEquals('wallabag — '.$type.' feed', $xpath->query('/rss/channel/title')->item(0)->nodeValue); + + $this->assertEquals(1, $xpath->query('/rss/channel/pubDate')->length); + + $this->assertEquals(1, $xpath->query('/rss/channel/generator')->length); + $this->assertEquals('wallabag', $xpath->query('/rss/channel/generator')->item(0)->nodeValue); + + $this->assertEquals(1, $xpath->query('/rss/channel/description')->length); + $this->assertEquals('wallabag '.$type.' elements', $xpath->query('/rss/channel/description')->item(0)->nodeValue); + + $this->assertEquals(1, $xpath->query('/rss/channel/link[@rel="self"]')->length); + $this->assertContains($type.'.xml', $xpath->query('/rss/channel/link[@rel="self"]')->item(0)->getAttribute('href')); + + $this->assertEquals(1, $xpath->query('/rss/channel/link[@rel="last"]')->length); + $this->assertContains($type.'.xml?page=', $xpath->query('/rss/channel/link[@rel="last"]')->item(0)->getAttribute('href')); + foreach ($xpath->query('//item') as $item) { $this->assertEquals(1, $xpath->query('title', $item)->length); $this->assertEquals(1, $xpath->query('source', $item)->length); @@ -77,7 +94,7 @@ class RssControllerTest extends WallabagCoreTestCase $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->validateDom($client->getResponse()->getContent(), 2); + $this->validateDom($client->getResponse()->getContent(), 'unread', 2); } public function testStarred() @@ -99,7 +116,7 @@ class RssControllerTest extends WallabagCoreTestCase $this->assertEquals(200, $client->getResponse()->getStatusCode(), 1); - $this->validateDom($client->getResponse()->getContent()); + $this->validateDom($client->getResponse()->getContent(), 'starred'); } public function testArchives() @@ -121,6 +138,38 @@ class RssControllerTest extends WallabagCoreTestCase $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->validateDom($client->getResponse()->getContent()); + $this->validateDom($client->getResponse()->getContent(), 'archive'); + } + + 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/archive.xml'); + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->validateDom($client->getResponse()->getContent(), 'archive'); + + $client->request('GET', '/admin/SUPERTOKEN/archive.xml?page=2'); + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->validateDom($client->getResponse()->getContent(), 'archive'); + + $client->request('GET', '/admin/SUPERTOKEN/archive.xml?page=3'); + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->validateDom($client->getResponse()->getContent(), 'archive'); + + $client->request('GET', '/admin/SUPERTOKEN/archive.xml?page=3000'); + $this->assertEquals(302, $client->getResponse()->getStatusCode()); } } -- cgit v1.2.3 From edd2472faa1ad01fe8b165ea8bbf4414cec8cbe1 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 19 Nov 2016 15:58:10 +0100 Subject: Fix tests --- tests/Wallabag/CoreBundle/Controller/RssControllerTest.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php index 1d6c02b2..5a59654d 100644 --- a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php @@ -157,19 +157,15 @@ class RssControllerTest extends WallabagCoreTestCase $client = $this->getClient(); - $client->request('GET', '/admin/SUPERTOKEN/archive.xml'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->validateDom($client->getResponse()->getContent(), 'archive'); - - $client->request('GET', '/admin/SUPERTOKEN/archive.xml?page=2'); + $client->request('GET', '/admin/SUPERTOKEN/unread.xml'); $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->validateDom($client->getResponse()->getContent(), 'archive'); + $this->validateDom($client->getResponse()->getContent(), 'unread'); - $client->request('GET', '/admin/SUPERTOKEN/archive.xml?page=3'); + $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=2'); $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->validateDom($client->getResponse()->getContent(), 'archive'); + $this->validateDom($client->getResponse()->getContent(), 'unread'); - $client->request('GET', '/admin/SUPERTOKEN/archive.xml?page=3000'); + $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=3000'); $this->assertEquals(302, $client->getResponse()->getStatusCode()); } } -- cgit v1.2.3