diff options
Diffstat (limited to 'tests/Wallabag/CoreBundle/Controller/RssControllerTest.php')
-rw-r--r-- | tests/Wallabag/CoreBundle/Controller/RssControllerTest.php | 91 |
1 files changed, 58 insertions, 33 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php index 5a59654d..c6ca4937 100644 --- a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php | |||
@@ -6,7 +6,7 @@ use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | |||
6 | 6 | ||
7 | class RssControllerTest extends WallabagCoreTestCase | 7 | class RssControllerTest extends WallabagCoreTestCase |
8 | { | 8 | { |
9 | public function validateDom($xml, $type, $nb = null) | 9 | public function validateDom($xml, $type, $urlPagination, $nb = null) |
10 | { | 10 | { |
11 | $doc = new \DOMDocument(); | 11 | $doc = new \DOMDocument(); |
12 | $doc->loadXML($xml); | 12 | $doc->loadXML($xml); |
@@ -16,36 +16,36 @@ class RssControllerTest extends WallabagCoreTestCase | |||
16 | if (null === $nb) { | 16 | if (null === $nb) { |
17 | $this->assertGreaterThan(0, $xpath->query('//item')->length); | 17 | $this->assertGreaterThan(0, $xpath->query('//item')->length); |
18 | } else { | 18 | } else { |
19 | $this->assertEquals($nb, $xpath->query('//item')->length); | 19 | $this->assertSame($nb, $xpath->query('//item')->length); |
20 | } | 20 | } |
21 | 21 | ||
22 | $this->assertEquals(1, $xpath->query('/rss')->length); | 22 | $this->assertSame(1, $xpath->query('/rss')->length); |
23 | $this->assertEquals(1, $xpath->query('/rss/channel')->length); | 23 | $this->assertSame(1, $xpath->query('/rss/channel')->length); |
24 | 24 | ||
25 | $this->assertEquals(1, $xpath->query('/rss/channel/title')->length); | 25 | $this->assertSame(1, $xpath->query('/rss/channel/title')->length); |
26 | $this->assertEquals('wallabag — '.$type.' feed', $xpath->query('/rss/channel/title')->item(0)->nodeValue); | 26 | $this->assertSame('wallabag - ' . $type . ' feed', $xpath->query('/rss/channel/title')->item(0)->nodeValue); |
27 | 27 | ||
28 | $this->assertEquals(1, $xpath->query('/rss/channel/pubDate')->length); | 28 | $this->assertSame(1, $xpath->query('/rss/channel/pubDate')->length); |
29 | 29 | ||
30 | $this->assertEquals(1, $xpath->query('/rss/channel/generator')->length); | 30 | $this->assertSame(1, $xpath->query('/rss/channel/generator')->length); |
31 | $this->assertEquals('wallabag', $xpath->query('/rss/channel/generator')->item(0)->nodeValue); | 31 | $this->assertSame('wallabag', $xpath->query('/rss/channel/generator')->item(0)->nodeValue); |
32 | 32 | ||
33 | $this->assertEquals(1, $xpath->query('/rss/channel/description')->length); | 33 | $this->assertSame(1, $xpath->query('/rss/channel/description')->length); |
34 | $this->assertEquals('wallabag '.$type.' elements', $xpath->query('/rss/channel/description')->item(0)->nodeValue); | 34 | $this->assertSame('wallabag ' . $type . ' elements', $xpath->query('/rss/channel/description')->item(0)->nodeValue); |
35 | 35 | ||
36 | $this->assertEquals(1, $xpath->query('/rss/channel/link[@rel="self"]')->length); | 36 | $this->assertSame(1, $xpath->query('/rss/channel/link[@rel="self"]')->length); |
37 | $this->assertContains($type.'.xml', $xpath->query('/rss/channel/link[@rel="self"]')->item(0)->getAttribute('href')); | 37 | $this->assertContains($urlPagination . '.xml', $xpath->query('/rss/channel/link[@rel="self"]')->item(0)->getAttribute('href')); |
38 | 38 | ||
39 | $this->assertEquals(1, $xpath->query('/rss/channel/link[@rel="last"]')->length); | 39 | $this->assertSame(1, $xpath->query('/rss/channel/link[@rel="last"]')->length); |
40 | $this->assertContains($type.'.xml?page=', $xpath->query('/rss/channel/link[@rel="last"]')->item(0)->getAttribute('href')); | 40 | $this->assertContains($urlPagination . '.xml?page=', $xpath->query('/rss/channel/link[@rel="last"]')->item(0)->getAttribute('href')); |
41 | 41 | ||
42 | foreach ($xpath->query('//item') as $item) { | 42 | foreach ($xpath->query('//item') as $item) { |
43 | $this->assertEquals(1, $xpath->query('title', $item)->length); | 43 | $this->assertSame(1, $xpath->query('title', $item)->length); |
44 | $this->assertEquals(1, $xpath->query('source', $item)->length); | 44 | $this->assertSame(1, $xpath->query('source', $item)->length); |
45 | $this->assertEquals(1, $xpath->query('link', $item)->length); | 45 | $this->assertSame(1, $xpath->query('link', $item)->length); |
46 | $this->assertEquals(1, $xpath->query('guid', $item)->length); | 46 | $this->assertSame(1, $xpath->query('guid', $item)->length); |
47 | $this->assertEquals(1, $xpath->query('pubDate', $item)->length); | 47 | $this->assertSame(1, $xpath->query('pubDate', $item)->length); |
48 | $this->assertEquals(1, $xpath->query('description', $item)->length); | 48 | $this->assertSame(1, $xpath->query('description', $item)->length); |
49 | } | 49 | } |
50 | } | 50 | } |
51 | 51 | ||
@@ -73,7 +73,7 @@ class RssControllerTest extends WallabagCoreTestCase | |||
73 | 73 | ||
74 | $client->request('GET', $url); | 74 | $client->request('GET', $url); |
75 | 75 | ||
76 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | 76 | $this->assertSame(404, $client->getResponse()->getStatusCode()); |
77 | } | 77 | } |
78 | 78 | ||
79 | public function testUnread() | 79 | public function testUnread() |
@@ -92,9 +92,9 @@ class RssControllerTest extends WallabagCoreTestCase | |||
92 | 92 | ||
93 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml'); | 93 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml'); |
94 | 94 | ||
95 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 95 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
96 | 96 | ||
97 | $this->validateDom($client->getResponse()->getContent(), 'unread', 2); | 97 | $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread', 2); |
98 | } | 98 | } |
99 | 99 | ||
100 | public function testStarred() | 100 | public function testStarred() |
@@ -114,9 +114,9 @@ class RssControllerTest extends WallabagCoreTestCase | |||
114 | $client = $this->getClient(); | 114 | $client = $this->getClient(); |
115 | $client->request('GET', '/admin/SUPERTOKEN/starred.xml'); | 115 | $client->request('GET', '/admin/SUPERTOKEN/starred.xml'); |
116 | 116 | ||
117 | $this->assertEquals(200, $client->getResponse()->getStatusCode(), 1); | 117 | $this->assertSame(200, $client->getResponse()->getStatusCode(), 1); |
118 | 118 | ||
119 | $this->validateDom($client->getResponse()->getContent(), 'starred'); | 119 | $this->validateDom($client->getResponse()->getContent(), 'starred', 'starred'); |
120 | } | 120 | } |
121 | 121 | ||
122 | public function testArchives() | 122 | public function testArchives() |
@@ -136,9 +136,9 @@ class RssControllerTest extends WallabagCoreTestCase | |||
136 | $client = $this->getClient(); | 136 | $client = $this->getClient(); |
137 | $client->request('GET', '/admin/SUPERTOKEN/archive.xml'); | 137 | $client->request('GET', '/admin/SUPERTOKEN/archive.xml'); |
138 | 138 | ||
139 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 139 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
140 | 140 | ||
141 | $this->validateDom($client->getResponse()->getContent(), 'archive'); | 141 | $this->validateDom($client->getResponse()->getContent(), 'archive', 'archive'); |
142 | } | 142 | } |
143 | 143 | ||
144 | public function testPagination() | 144 | public function testPagination() |
@@ -158,14 +158,39 @@ class RssControllerTest extends WallabagCoreTestCase | |||
158 | $client = $this->getClient(); | 158 | $client = $this->getClient(); |
159 | 159 | ||
160 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml'); | 160 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml'); |
161 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 161 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
162 | $this->validateDom($client->getResponse()->getContent(), 'unread'); | 162 | $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread'); |
163 | 163 | ||
164 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=2'); | 164 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=2'); |
165 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 165 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
166 | $this->validateDom($client->getResponse()->getContent(), 'unread'); | 166 | $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread'); |
167 | 167 | ||
168 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=3000'); | 168 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=3000'); |
169 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 169 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
170 | } | ||
171 | |||
172 | public function testTags() | ||
173 | { | ||
174 | $client = $this->getClient(); | ||
175 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
176 | $user = $em | ||
177 | ->getRepository('WallabagUserBundle:User') | ||
178 | ->findOneByUsername('admin'); | ||
179 | |||
180 | $config = $user->getConfig(); | ||
181 | $config->setRssToken('SUPERTOKEN'); | ||
182 | $config->setRssLimit(null); | ||
183 | $em->persist($config); | ||
184 | $em->flush(); | ||
185 | |||
186 | $client = $this->getClient(); | ||
187 | $client->request('GET', '/admin/SUPERTOKEN/tags/foo.xml'); | ||
188 | |||
189 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
190 | |||
191 | $this->validateDom($client->getResponse()->getContent(), 'tag (foo)', 'tags/foo'); | ||
192 | |||
193 | $client->request('GET', '/admin/SUPERTOKEN/tags/foo.xml?page=3000'); | ||
194 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
170 | } | 195 | } |
171 | } | 196 | } |