diff options
author | Jérémy Benoist <j0k3r@users.noreply.github.com> | 2019-05-29 11:14:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-29 11:14:00 +0200 |
commit | 73ec68b1ffafb792265a3805833e5cd84c966aed (patch) | |
tree | 33c6040c050f85c537f8dbf5e91d8c281db092cd /tests/Wallabag/CoreBundle/Controller/FeedControllerTest.php | |
parent | 2ba365c7c49556cd23b444dc3bb8d4a8cf08809d (diff) | |
parent | 2cbee36a0184786644470a84fdd8c720cfcac58e (diff) | |
download | wallabag-73ec68b1ffafb792265a3805833e5cd84c966aed.tar.gz wallabag-73ec68b1ffafb792265a3805833e5cd84c966aed.tar.zst wallabag-73ec68b1ffafb792265a3805833e5cd84c966aed.zip |
Merge pull request #3984 from wallabag/2.4
Merge 2.4 into master
Diffstat (limited to 'tests/Wallabag/CoreBundle/Controller/FeedControllerTest.php')
-rw-r--r-- | tests/Wallabag/CoreBundle/Controller/FeedControllerTest.php | 261 |
1 files changed, 261 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..d52d7bb8 --- /dev/null +++ b/tests/Wallabag/CoreBundle/Controller/FeedControllerTest.php | |||
@@ -0,0 +1,261 @@ | |||
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->assertSame($nb, $xpath->query('//a:entry')->length); | ||
21 | } | ||
22 | |||
23 | $this->assertSame(1, $xpath->query('/a:feed')->length); | ||
24 | |||
25 | $this->assertSame(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->assertSame(1, $xpath->query('/a:feed/a:updated')->length); | ||
30 | |||
31 | $this->assertSame(1, $xpath->query('/a:feed/a:generator')->length); | ||
32 | $this->assertSame('wallabag', $xpath->query('/a:feed/a:generator')->item(0)->nodeValue); | ||
33 | $this->assertSame('admin', $xpath->query('/a:feed/a:author/a:name')->item(0)->nodeValue); | ||
34 | |||
35 | $this->assertSame(1, $xpath->query('/a:feed/a:subtitle')->length); | ||
36 | if (null !== $tagValue && 0 === strpos($type, 'tag')) { | ||
37 | $this->assertSame('wallabag — ' . $type . ' ' . $tagValue . ' feed', $xpath->query('/a:feed/a:title')->item(0)->nodeValue); | ||
38 | $this->assertSame('Atom feed for entries tagged with ' . $tagValue, $xpath->query('/a:feed/a:subtitle')->item(0)->nodeValue); | ||
39 | } else { | ||
40 | $this->assertSame('wallabag — ' . $type . ' feed', $xpath->query('/a:feed/a:title')->item(0)->nodeValue); | ||
41 | $this->assertSame('Atom feed for ' . $type . ' entries', $xpath->query('/a:feed/a:subtitle')->item(0)->nodeValue); | ||
42 | } | ||
43 | |||
44 | $this->assertSame(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->assertSame(1, $xpath->query('/a:feed/a:link[@rel="last"]')->length); | ||
48 | |||
49 | foreach ($xpath->query('//a:entry') as $item) { | ||
50 | $this->assertSame(1, $xpath->query('a:title', $item)->length); | ||
51 | $this->assertSame(1, $xpath->query('a:link[@rel="via"]', $item)->length); | ||
52 | $this->assertSame(1, $xpath->query('a:link[@rel="alternate"]', $item)->length); | ||
53 | $this->assertSame(1, $xpath->query('a:id', $item)->length); | ||
54 | $this->assertSame(1, $xpath->query('a:published', $item)->length); | ||
55 | $this->assertSame(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->assertSame(200, $client->getResponse()->getStatusCode()); | ||
194 | $this->validateDom($client->getResponse()->getContent(), 'unread'); | ||
195 | |||
196 | $client->request('GET', '/feed/admin/SUPERTOKEN/unread/2'); | ||
197 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
198 | $this->validateDom($client->getResponse()->getContent(), 'unread'); | ||
199 | |||
200 | $client->request('GET', '/feed/admin/SUPERTOKEN/unread/3000'); | ||
201 | $this->assertSame(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', '/feed/admin/SUPERTOKEN/tags/foo'); | ||
220 | |||
221 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
222 | |||
223 | $this->validateDom($client->getResponse()->getContent(), 'tag', 2, 'foo'); | ||
224 | |||
225 | $client->request('GET', '/feed/admin/SUPERTOKEN/tags/foo/3000'); | ||
226 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
227 | } | ||
228 | |||
229 | public function dataForRedirect() | ||
230 | { | ||
231 | return [ | ||
232 | [ | ||
233 | '/admin/YZIOAUZIAO/unread.xml', | ||
234 | ], | ||
235 | [ | ||
236 | '/admin/YZIOAUZIAO/starred.xml', | ||
237 | ], | ||
238 | [ | ||
239 | '/admin/YZIOAUZIAO/archive.xml', | ||
240 | ], | ||
241 | [ | ||
242 | '/admin/YZIOAUZIAO/all.xml', | ||
243 | ], | ||
244 | [ | ||
245 | '/admin/YZIOAUZIAO/tags/foo.xml', | ||
246 | ], | ||
247 | ]; | ||
248 | } | ||
249 | |||
250 | /** | ||
251 | * @dataProvider dataForRedirect | ||
252 | */ | ||
253 | public function testRedirectFromRssToAtom($url) | ||
254 | { | ||
255 | $client = $this->getClient(); | ||
256 | |||
257 | $client->request('GET', $url); | ||
258 | |||
259 | $this->assertSame(301, $client->getResponse()->getStatusCode()); | ||
260 | } | ||
261 | } | ||