diff options
Diffstat (limited to 'tests/Wallabag/CoreBundle/Controller/FeedControllerTest.php')
-rw-r--r-- | tests/Wallabag/CoreBundle/Controller/FeedControllerTest.php | 228 |
1 files changed, 228 insertions, 0 deletions
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 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\CoreBundle\Controller; | ||
4 | |||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | ||
6 | |||
7 | class FeedControllerTest extends WallabagCoreTestCase | ||
8 | { | ||
9 | public function validateDom($xml, $type, $nb = null, $tagValue = null) | ||
10 | { | ||
11 | $doc = new \DOMDocument(); | ||
12 | $doc->loadXML($xml); | ||
13 | |||
14 | $xpath = new \DOMXpath($doc); | ||
15 | $xpath->registerNamespace('a', 'http://www.w3.org/2005/Atom'); | ||
16 | |||
17 | if (null === $nb) { | ||
18 | $this->assertGreaterThan(0, $xpath->query('//a:entry')->length); | ||
19 | } else { | ||
20 | $this->assertEquals($nb, $xpath->query('//a:entry')->length); | ||
21 | } | ||
22 | |||
23 | $this->assertEquals(1, $xpath->query('/a:feed')->length); | ||
24 | |||
25 | $this->assertEquals(1, $xpath->query('/a:feed/a:title')->length); | ||
26 | $this->assertContains('favicon.ico', $xpath->query('/a:feed/a:icon')->item(0)->nodeValue); | ||
27 | $this->assertContains('logo-square.png', $xpath->query('/a:feed/a:logo')->item(0)->nodeValue); | ||
28 | |||
29 | $this->assertEquals(1, $xpath->query('/a:feed/a:updated')->length); | ||
30 | |||
31 | $this->assertEquals(1, $xpath->query('/a:feed/a:generator')->length); | ||
32 | $this->assertEquals('wallabag', $xpath->query('/a:feed/a:generator')->item(0)->nodeValue); | ||
33 | $this->assertEquals('admin', $xpath->query('/a:feed/a:author/a:name')->item(0)->nodeValue); | ||
34 | |||
35 | $this->assertEquals(1, $xpath->query('/a:feed/a:subtitle')->length); | ||
36 | if (null !== $tagValue && 0 === strpos($type, 'tag')) { | ||
37 | $this->assertEquals('wallabag — '.$type.' '.$tagValue.' feed', $xpath->query('/a:feed/a:title')->item(0)->nodeValue); | ||
38 | $this->assertEquals('Atom feed for entries tagged with ' . $tagValue, $xpath->query('/a:feed/a:subtitle')->item(0)->nodeValue); | ||
39 | } else { | ||
40 | $this->assertEquals('wallabag — '.$type.' feed', $xpath->query('/a:feed/a:title')->item(0)->nodeValue); | ||
41 | $this->assertEquals('Atom feed for ' . $type . ' entries', $xpath->query('/a:feed/a:subtitle')->item(0)->nodeValue); | ||
42 | } | ||
43 | |||
44 | $this->assertEquals(1, $xpath->query('/a:feed/a:link[@rel="self"]')->length); | ||
45 | $this->assertContains($type, $xpath->query('/a:feed/a:link[@rel="self"]')->item(0)->getAttribute('href')); | ||
46 | |||
47 | $this->assertEquals(1, $xpath->query('/a:feed/a:link[@rel="last"]')->length); | ||
48 | |||
49 | foreach ($xpath->query('//a:entry') as $item) { | ||
50 | $this->assertEquals(1, $xpath->query('a:title', $item)->length); | ||
51 | $this->assertEquals(1, $xpath->query('a:link[@rel="via"]', $item)->length); | ||
52 | $this->assertEquals(1, $xpath->query('a:link[@rel="alternate"]', $item)->length); | ||
53 | $this->assertEquals(1, $xpath->query('a:id', $item)->length); | ||
54 | $this->assertEquals(1, $xpath->query('a:published', $item)->length); | ||
55 | $this->assertEquals(1, $xpath->query('a:content', $item)->length); | ||
56 | } | ||
57 | } | ||
58 | |||
59 | public function dataForBadUrl() | ||
60 | { | ||
61 | return [ | ||
62 | [ | ||
63 | '/feed/admin/YZIOAUZIAO/unread', | ||
64 | ], | ||
65 | [ | ||
66 | '/feed/wallace/YZIOAUZIAO/starred', | ||
67 | ], | ||
68 | [ | ||
69 | '/feed/wallace/YZIOAUZIAO/archives', | ||
70 | ], | ||
71 | [ | ||
72 | '/feed/wallace/YZIOAUZIAO/all', | ||
73 | ], | ||
74 | ]; | ||
75 | } | ||
76 | |||
77 | /** | ||
78 | * @dataProvider dataForBadUrl | ||
79 | */ | ||
80 | public function testBadUrl($url) | ||
81 | { | ||
82 | $client = $this->getClient(); | ||
83 | |||
84 | $client->request('GET', $url); | ||
85 | |||
86 | $this->assertSame(404, $client->getResponse()->getStatusCode()); | ||
87 | } | ||
88 | |||
89 | public function testUnread() | ||
90 | { | ||
91 | $client = $this->getClient(); | ||
92 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
93 | $user = $em | ||
94 | ->getRepository('WallabagUserBundle:User') | ||
95 | ->findOneByUsername('admin'); | ||
96 | |||
97 | $config = $user->getConfig(); | ||
98 | $config->setFeedToken('SUPERTOKEN'); | ||
99 | $config->setFeedLimit(2); | ||
100 | $em->persist($config); | ||
101 | $em->flush(); | ||
102 | |||
103 | $client->request('GET', '/feed/admin/SUPERTOKEN/unread'); | ||
104 | |||
105 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
106 | |||
107 | $this->validateDom($client->getResponse()->getContent(), 'unread', 2); | ||
108 | } | ||
109 | |||
110 | public function testStarred() | ||
111 | { | ||
112 | $client = $this->getClient(); | ||
113 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
114 | $user = $em | ||
115 | ->getRepository('WallabagUserBundle:User') | ||
116 | ->findOneByUsername('admin'); | ||
117 | |||
118 | $config = $user->getConfig(); | ||
119 | $config->setFeedToken('SUPERTOKEN'); | ||
120 | $config->setFeedLimit(1); | ||
121 | $em->persist($config); | ||
122 | $em->flush(); | ||
123 | |||
124 | $client = $this->getClient(); | ||
125 | $client->request('GET', '/feed/admin/SUPERTOKEN/starred'); | ||
126 | |||
127 | $this->assertSame(200, $client->getResponse()->getStatusCode(), 1); | ||
128 | |||
129 | $this->validateDom($client->getResponse()->getContent(), 'starred'); | ||
130 | } | ||
131 | |||
132 | public function testArchives() | ||
133 | { | ||
134 | $client = $this->getClient(); | ||
135 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
136 | $user = $em | ||
137 | ->getRepository('WallabagUserBundle:User') | ||
138 | ->findOneByUsername('admin'); | ||
139 | |||
140 | $config = $user->getConfig(); | ||
141 | $config->setFeedToken('SUPERTOKEN'); | ||
142 | $config->setFeedLimit(null); | ||
143 | $em->persist($config); | ||
144 | $em->flush(); | ||
145 | |||
146 | $client = $this->getClient(); | ||
147 | $client->request('GET', '/feed/admin/SUPERTOKEN/archive'); | ||
148 | |||
149 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
150 | |||
151 | $this->validateDom($client->getResponse()->getContent(), 'archive'); | ||
152 | } | ||
153 | |||
154 | public function testAll() | ||
155 | { | ||
156 | $client = $this->getClient(); | ||
157 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
158 | $user = $em | ||
159 | ->getRepository('WallabagUserBundle:User') | ||
160 | ->findOneByUsername('admin'); | ||
161 | |||
162 | $config = $user->getConfig(); | ||
163 | $config->setFeedToken('SUPERTOKEN'); | ||
164 | $config->setFeedLimit(null); | ||
165 | $em->persist($config); | ||
166 | $em->flush(); | ||
167 | |||
168 | $client = $this->getClient(); | ||
169 | $client->request('GET', '/feed/admin/SUPERTOKEN/all'); | ||
170 | |||
171 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
172 | |||
173 | $this->validateDom($client->getResponse()->getContent(), 'all'); | ||
174 | } | ||
175 | |||
176 | public function testPagination() | ||
177 | { | ||
178 | $client = $this->getClient(); | ||
179 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
180 | $user = $em | ||
181 | ->getRepository('WallabagUserBundle:User') | ||
182 | ->findOneByUsername('admin'); | ||
183 | |||
184 | $config = $user->getConfig(); | ||
185 | $config->setFeedToken('SUPERTOKEN'); | ||
186 | $config->setFeedLimit(1); | ||
187 | $em->persist($config); | ||
188 | $em->flush(); | ||
189 | |||
190 | $client = $this->getClient(); | ||
191 | |||
192 | $client->request('GET', '/feed/admin/SUPERTOKEN/unread'); | ||
193 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
194 | $this->validateDom($client->getResponse()->getContent(), 'unread'); | ||
195 | |||
196 | $client->request('GET', '/feed/admin/SUPERTOKEN/unread/2'); | ||
197 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
198 | $this->validateDom($client->getResponse()->getContent(), 'unread'); | ||
199 | |||
200 | $client->request('GET', '/feed/admin/SUPERTOKEN/unread/3000'); | ||
201 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
202 | } | ||
203 | |||
204 | public function testTags() | ||
205 | { | ||
206 | $client = $this->getClient(); | ||
207 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
208 | $user = $em | ||
209 | ->getRepository('WallabagUserBundle:User') | ||
210 | ->findOneByUsername('admin'); | ||
211 | |||
212 | $config = $user->getConfig(); | ||
213 | $config->setFeedToken('SUPERTOKEN'); | ||
214 | $config->setFeedLimit(null); | ||
215 | $em->persist($config); | ||
216 | $em->flush(); | ||
217 | |||
218 | $client = $this->getClient(); | ||
219 | $client->request('GET', '/admin/SUPERTOKEN/tags/foo-bar.xml'); | ||
220 | |||
221 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
222 | |||
223 | $this->validateDom($client->getResponse()->getContent(), 'tag', 2, 'foo-bar'); | ||
224 | |||
225 | $client->request('GET', '/admin/SUPERTOKEN/tags/foo-bar.xml?page=3000'); | ||
226 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
227 | } | ||
228 | } | ||