]>
Commit | Line | Data |
---|---|---|
93fd4692 NL |
1 | <?php |
2 | ||
ad4d1caa | 3 | namespace Wallabag\CoreBundle\Tests\Controller; |
93fd4692 | 4 | |
769e19dc | 5 | use Wallabag\CoreBundle\Tests\WallabagCoreTestCase; |
eb3bd7ef | 6 | use Doctrine\ORM\AbstractQuery; |
93fd4692 | 7 | |
769e19dc | 8 | class EntryControllerTest extends WallabagCoreTestCase |
93fd4692 | 9 | { |
3b815d2d J |
10 | public function testLogin() |
11 | { | |
12 | $client = $this->getClient(); | |
13 | ||
eb3bd7ef | 14 | $client->request('GET', '/new'); |
3b815d2d J |
15 | |
16 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
17 | $this->assertContains('login', $client->getResponse()->headers->get('location')); | |
18 | } | |
19 | ||
9c0c8820 | 20 | public function testGetNew() |
93fd4692 | 21 | { |
eb3bd7ef | 22 | $this->logInAs('admin'); |
3b815d2d | 23 | $client = $this->getClient(); |
93fd4692 | 24 | |
aa6e27cf | 25 | $crawler = $client->request('GET', '/new'); |
93fd4692 NL |
26 | |
27 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
9c0c8820 J |
28 | |
29 | $this->assertCount(1, $crawler->filter('input[type=url]')); | |
30 | $this->assertCount(1, $crawler->filter('button[type=submit]')); | |
31 | } | |
32 | ||
33 | public function testPostNewEmpty() | |
34 | { | |
eb3bd7ef | 35 | $this->logInAs('admin'); |
3b815d2d | 36 | $client = $this->getClient(); |
9c0c8820 J |
37 | |
38 | $crawler = $client->request('GET', '/new'); | |
39 | ||
40 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
41 | ||
42 | $form = $crawler->filter('button[type=submit]')->form(); | |
43 | ||
44 | $crawler = $client->submit($form); | |
45 | ||
46 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
47 | $this->assertCount(1, $alert = $crawler->filter('form ul li')->extract(array('_text'))); | |
48 | $this->assertEquals('This value should not be blank.', $alert[0]); | |
49 | } | |
50 | ||
51 | public function testPostNewOk() | |
52 | { | |
eb3bd7ef | 53 | $this->logInAs('admin'); |
3b815d2d | 54 | $client = $this->getClient(); |
9c0c8820 J |
55 | |
56 | $crawler = $client->request('GET', '/new'); | |
57 | ||
58 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
59 | ||
60 | $form = $crawler->filter('button[type=submit]')->form(); | |
61 | ||
62 | $data = array( | |
34c06cab | 63 | 'entry[url]' => 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', |
9c0c8820 J |
64 | ); |
65 | ||
66 | $client->submit($form, $data); | |
67 | ||
68 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
69 | ||
70 | $crawler = $client->followRedirect(); | |
71 | ||
3b815d2d | 72 | $this->assertGreaterThan(1, $alert = $crawler->filter('h2 a')->extract(array('_text'))); |
34c06cab | 73 | $this->assertContains('Google', $alert[0]); |
9c0c8820 J |
74 | } |
75 | ||
76 | public function testArchive() | |
77 | { | |
eb3bd7ef | 78 | $this->logInAs('admin'); |
3b815d2d | 79 | $client = $this->getClient(); |
9c0c8820 | 80 | |
9fb6ac83 | 81 | $client->request('GET', '/archive/list'); |
9c0c8820 J |
82 | |
83 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
84 | } | |
85 | ||
86 | public function testStarred() | |
87 | { | |
eb3bd7ef | 88 | $this->logInAs('admin'); |
3b815d2d | 89 | $client = $this->getClient(); |
9c0c8820 | 90 | |
9fb6ac83 | 91 | $client->request('GET', '/starred/list'); |
9c0c8820 J |
92 | |
93 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
94 | } | |
95 | ||
96 | public function testView() | |
97 | { | |
eb3bd7ef | 98 | $this->logInAs('admin'); |
3b815d2d | 99 | $client = $this->getClient(); |
9c0c8820 J |
100 | |
101 | $content = $client->getContainer() | |
102 | ->get('doctrine.orm.entity_manager') | |
103 | ->getRepository('WallabagCoreBundle:Entry') | |
159986c4 | 104 | ->findOneByUsernameAndNotArchived('admin'); |
9c0c8820 | 105 | |
eb3bd7ef | 106 | $client->request('GET', '/view/'.$content->getId()); |
9c0c8820 J |
107 | |
108 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
109 | $this->assertContains($content->getTitle(), $client->getResponse()->getContent()); | |
93fd4692 | 110 | } |
eb3bd7ef | 111 | |
82d6d9cb JB |
112 | public function testEdit() |
113 | { | |
114 | $this->logInAs('admin'); | |
115 | $client = $this->getClient(); | |
116 | ||
117 | $content = $client->getContainer() | |
118 | ->get('doctrine.orm.entity_manager') | |
119 | ->getRepository('WallabagCoreBundle:Entry') | |
159986c4 | 120 | ->findOneByUsernameAndNotArchived('admin'); |
82d6d9cb JB |
121 | |
122 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | |
123 | ||
124 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
125 | ||
126 | $this->assertCount(1, $crawler->filter('input[id=entry_title]')); | |
127 | $this->assertCount(1, $crawler->filter('button[id=entry_save]')); | |
128 | } | |
129 | ||
130 | public function testEditUpdate() | |
131 | { | |
132 | $this->logInAs('admin'); | |
133 | $client = $this->getClient(); | |
134 | ||
135 | $content = $client->getContainer() | |
136 | ->get('doctrine.orm.entity_manager') | |
137 | ->getRepository('WallabagCoreBundle:Entry') | |
159986c4 | 138 | ->findOneByUsernameAndNotArchived('admin'); |
82d6d9cb JB |
139 | |
140 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | |
141 | ||
142 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
143 | ||
144 | $form = $crawler->filter('button[type=submit]')->form(); | |
145 | ||
146 | $data = array( | |
147 | 'entry[title]' => 'My updated title hehe :)', | |
148 | ); | |
149 | ||
150 | $client->submit($form, $data); | |
151 | ||
152 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
153 | ||
154 | $crawler = $client->followRedirect(); | |
155 | ||
156 | $this->assertGreaterThan(1, $alert = $crawler->filter('div[id=article] h1')->extract(array('_text'))); | |
157 | $this->assertContains('My updated title hehe :)', $alert[0]); | |
158 | } | |
159 | ||
eb3bd7ef J |
160 | public function testToggleArchive() |
161 | { | |
162 | $this->logInAs('admin'); | |
163 | $client = $this->getClient(); | |
164 | ||
165 | $content = $client->getContainer() | |
166 | ->get('doctrine.orm.entity_manager') | |
167 | ->getRepository('WallabagCoreBundle:Entry') | |
159986c4 | 168 | ->findOneByUsernameAndNotArchived('admin'); |
eb3bd7ef J |
169 | |
170 | $client->request('GET', '/archive/'.$content->getId()); | |
171 | ||
172 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
173 | ||
174 | $res = $client->getContainer() | |
175 | ->get('doctrine.orm.entity_manager') | |
176 | ->getRepository('WallabagCoreBundle:Entry') | |
159986c4 | 177 | ->find($content->getId()); |
eb3bd7ef J |
178 | |
179 | $this->assertEquals($res->isArchived(), true); | |
180 | } | |
181 | ||
182 | public function testToggleStar() | |
183 | { | |
184 | $this->logInAs('admin'); | |
185 | $client = $this->getClient(); | |
186 | ||
187 | $content = $client->getContainer() | |
188 | ->get('doctrine.orm.entity_manager') | |
189 | ->getRepository('WallabagCoreBundle:Entry') | |
159986c4 | 190 | ->findOneByUsernameAndNotStarred('admin'); |
eb3bd7ef J |
191 | |
192 | $client->request('GET', '/star/'.$content->getId()); | |
193 | ||
194 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
195 | ||
196 | $res = $client->getContainer() | |
197 | ->get('doctrine.orm.entity_manager') | |
198 | ->getRepository('WallabagCoreBundle:Entry') | |
199 | ->findOneById($content->getId()); | |
200 | ||
201 | $this->assertEquals($res->isStarred(), true); | |
202 | } | |
203 | ||
204 | public function testDelete() | |
205 | { | |
206 | $this->logInAs('admin'); | |
207 | $client = $this->getClient(); | |
208 | ||
209 | $content = $client->getContainer() | |
210 | ->get('doctrine.orm.entity_manager') | |
211 | ->getRepository('WallabagCoreBundle:Entry') | |
159986c4 | 212 | ->findOneByUsernameAndNotStarred('admin'); |
eb3bd7ef J |
213 | |
214 | $client->request('GET', '/delete/'.$content->getId()); | |
215 | ||
216 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
217 | ||
1d147791 | 218 | $client->request('GET', '/delete/'.$content->getId()); |
eb3bd7ef | 219 | |
1d147791 | 220 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); |
eb3bd7ef | 221 | } |
3d2b2d62 J |
222 | |
223 | public function testViewOtherUserEntry() | |
224 | { | |
159986c4 | 225 | $this->logInAs('admin'); |
3d2b2d62 J |
226 | $client = $this->getClient(); |
227 | ||
228 | $content = $client->getContainer() | |
229 | ->get('doctrine.orm.entity_manager') | |
230 | ->getRepository('WallabagCoreBundle:Entry') | |
159986c4 | 231 | ->findOneByUsernameAndNotArchived('bob'); |
3d2b2d62 | 232 | |
159986c4 | 233 | $client->request('GET', '/view/'.$content->getId()); |
3d2b2d62 J |
234 | |
235 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | |
236 | } | |
26864574 | 237 | |
3f357ee2 | 238 | public function testFilterOnReadingTime() |
26864574 NL |
239 | { |
240 | $this->logInAs('admin'); | |
241 | $client = $this->getClient(); | |
242 | ||
243 | $crawler = $client->request('GET', '/unread/list'); | |
244 | ||
245 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
246 | ||
247 | $data = array( | |
248 | 'entry_filter[readingTime][right_number]' => 11, | |
8ce32af6 | 249 | 'entry_filter[readingTime][left_number]' => 11, |
26864574 NL |
250 | ); |
251 | ||
252 | $crawler = $client->submit($form, $data); | |
253 | ||
254 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
255 | } | |
ab2c93c7 | 256 | |
3f357ee2 NL |
257 | public function testFilterOnCreationDate() |
258 | { | |
259 | $this->logInAs('admin'); | |
260 | $client = $this->getClient(); | |
261 | ||
262 | $crawler = $client->request('GET', '/unread/list'); | |
263 | ||
264 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
265 | ||
266 | $data = array( | |
267 | 'entry_filter[createdAt][left_date]' => date('d/m/Y'), | |
8ce32af6 | 268 | 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')), |
3f357ee2 NL |
269 | ); |
270 | ||
271 | $crawler = $client->submit($form, $data); | |
272 | ||
e1779760 | 273 | $this->assertCount(5, $crawler->filter('div[class=entry]')); |
3f357ee2 | 274 | |
f90af145 JB |
275 | $data = array( |
276 | 'entry_filter[createdAt][left_date]' => date('d/m/Y'), | |
277 | 'entry_filter[createdAt][right_date]' => date('d/m/Y'), | |
278 | ); | |
279 | ||
280 | $crawler = $client->submit($form, $data); | |
281 | ||
282 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
283 | ||
3f357ee2 NL |
284 | $data = array( |
285 | 'entry_filter[createdAt][left_date]' => '01/01/1970', | |
8ce32af6 | 286 | 'entry_filter[createdAt][right_date]' => '01/01/1970', |
3f357ee2 NL |
287 | ); |
288 | ||
289 | $crawler = $client->submit($form, $data); | |
290 | ||
291 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
3f357ee2 NL |
292 | } |
293 | ||
ab2c93c7 NL |
294 | public function testPaginationWithFilter() |
295 | { | |
296 | $this->logInAs('admin'); | |
297 | $client = $this->getClient(); | |
ab2c93c7 NL |
298 | $crawler = $client->request('GET', '/config'); |
299 | ||
300 | $form = $crawler->filter('button[id=config_save]')->form(); | |
301 | ||
302 | $data = array( | |
303 | 'config[items_per_page]' => '1', | |
304 | ); | |
305 | ||
306 | $client->submit($form, $data); | |
307 | ||
308 | $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D='; | |
309 | ||
310 | $crawler = $client->request('GET', 'unread/list'.$parameters); | |
311 | ||
312 | $this->assertContains($parameters, $client->getResponse()->getContent()); | |
e1779760 NL |
313 | |
314 | // reset pagination | |
315 | $crawler = $client->request('GET', '/config'); | |
316 | $form = $crawler->filter('button[id=config_save]')->form(); | |
317 | $data = array( | |
318 | 'config[items_per_page]' => '12', | |
319 | ); | |
320 | $client->submit($form, $data); | |
ab2c93c7 | 321 | } |
443cecd2 NL |
322 | |
323 | public function testFilterOnDomainName() | |
324 | { | |
325 | $this->logInAs('admin'); | |
326 | $client = $this->getClient(); | |
327 | ||
328 | $crawler = $client->request('GET', '/unread/list'); | |
329 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
330 | $data = array( | |
8ce32af6 | 331 | 'entry_filter[domainName]' => 'monde', |
443cecd2 NL |
332 | ); |
333 | ||
334 | $crawler = $client->submit($form, $data); | |
335 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
336 | ||
337 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
338 | $data = array( | |
8ce32af6 | 339 | 'entry_filter[domainName]' => 'wallabag', |
443cecd2 NL |
340 | ); |
341 | ||
342 | $crawler = $client->submit($form, $data); | |
343 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
344 | } | |
e1779760 NL |
345 | |
346 | public function testFilterOnStatus() | |
347 | { | |
348 | $this->logInAs('admin'); | |
349 | $client = $this->getClient(); | |
350 | ||
351 | $crawler = $client->request('GET', '/unread/list'); | |
352 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
353 | $form['entry_filter[isArchived]']->tick(); | |
354 | $form['entry_filter[isStarred]']->untick(); | |
355 | ||
356 | $crawler = $client->submit($form); | |
159986c4 | 357 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
e1779760 NL |
358 | |
359 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
360 | $form['entry_filter[isArchived]']->untick(); | |
361 | $form['entry_filter[isStarred]']->tick(); | |
362 | ||
363 | $crawler = $client->submit($form); | |
af43bd37 | 364 | $this->assertCount(2, $crawler->filter('div[class=entry]')); |
e1779760 | 365 | } |
497e0cad NL |
366 | |
367 | public function testPreviewPictureFilter() | |
368 | { | |
369 | $this->logInAs('admin'); | |
370 | $client = $this->getClient(); | |
371 | ||
372 | $crawler = $client->request('GET', '/unread/list'); | |
373 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
374 | $form['entry_filter[previewPicture]']->tick(); | |
375 | ||
376 | $crawler = $client->submit($form); | |
377 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
378 | } | |
d4ebe5c5 JB |
379 | |
380 | public function testFilterOnLanguage() | |
381 | { | |
382 | $this->logInAs('admin'); | |
383 | $client = $this->getClient(); | |
384 | ||
385 | $crawler = $client->request('GET', '/unread/list'); | |
386 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
387 | $data = array( | |
159986c4 | 388 | 'entry_filter[language]' => 'fr', |
d4ebe5c5 JB |
389 | ); |
390 | ||
391 | $crawler = $client->submit($form, $data); | |
159986c4 | 392 | $this->assertCount(3, $crawler->filter('div[class=entry]')); |
d4ebe5c5 JB |
393 | |
394 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
395 | $data = array( | |
396 | 'entry_filter[language]' => 'en', | |
397 | ); | |
398 | ||
399 | $crawler = $client->submit($form, $data); | |
400 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | |
401 | } | |
93fd4692 | 402 | } |