]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | namespace Wallabag\CoreBundle\Tests\Controller; | |
4 | ||
5 | use Wallabag\CoreBundle\Tests\WallabagCoreTestCase; | |
6 | use Wallabag\CoreBundle\Entity\Entry; | |
7 | ||
8 | class EntryControllerTest extends WallabagCoreTestCase | |
9 | { | |
10 | public $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'; | |
11 | ||
12 | public function testLogin() | |
13 | { | |
14 | $client = $this->getClient(); | |
15 | ||
16 | $client->request('GET', '/new'); | |
17 | ||
18 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
19 | $this->assertContains('login', $client->getResponse()->headers->get('location')); | |
20 | } | |
21 | ||
22 | public function testGetNew() | |
23 | { | |
24 | $this->logInAs('admin'); | |
25 | $client = $this->getClient(); | |
26 | ||
27 | $crawler = $client->request('GET', '/new'); | |
28 | ||
29 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
30 | ||
31 | $this->assertCount(1, $crawler->filter('input[type=url]')); | |
32 | $this->assertCount(1, $crawler->filter('button[type=submit]')); | |
33 | } | |
34 | ||
35 | public function testPostNewViaBookmarklet() | |
36 | { | |
37 | $this->logInAs('admin'); | |
38 | $client = $this->getClient(); | |
39 | ||
40 | $crawler = $client->request('GET', '/'); | |
41 | ||
42 | $this->assertCount(4, $crawler->filter('div[class=entry]')); | |
43 | ||
44 | // Good URL | |
45 | $crawler = $client->request('GET', '/bookmarklet', array('url' => $this->url)); | |
46 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
47 | $crawler = $client->followRedirect(); | |
48 | $crawler = $client->request('GET', '/'); | |
49 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
50 | ||
51 | $em = $client->getContainer() | |
52 | ->get('doctrine.orm.entity_manager'); | |
53 | $entry = $em | |
54 | ->getRepository('WallabagCoreBundle:Entry') | |
55 | ->findOneByUrl($this->url); | |
56 | $em->remove($entry); | |
57 | $em->flush(); | |
58 | } | |
59 | ||
60 | public function testPostNewEmpty() | |
61 | { | |
62 | $this->logInAs('admin'); | |
63 | $client = $this->getClient(); | |
64 | ||
65 | $crawler = $client->request('GET', '/new'); | |
66 | ||
67 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
68 | ||
69 | $form = $crawler->filter('button[type=submit]')->form(); | |
70 | ||
71 | $crawler = $client->submit($form); | |
72 | ||
73 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
74 | $this->assertCount(1, $alert = $crawler->filter('form ul li')->extract(array('_text'))); | |
75 | $this->assertEquals('This value should not be blank.', $alert[0]); | |
76 | } | |
77 | ||
78 | /** | |
79 | * This test will require an internet connection. | |
80 | */ | |
81 | public function testPostNewOk() | |
82 | { | |
83 | $this->logInAs('admin'); | |
84 | $client = $this->getClient(); | |
85 | ||
86 | $crawler = $client->request('GET', '/new'); | |
87 | ||
88 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
89 | ||
90 | $form = $crawler->filter('button[type=submit]')->form(); | |
91 | ||
92 | $data = array( | |
93 | 'entry[url]' => $this->url, | |
94 | ); | |
95 | ||
96 | $client->submit($form, $data); | |
97 | ||
98 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
99 | ||
100 | $crawler = $client->followRedirect(); | |
101 | ||
102 | $this->assertGreaterThan(1, $alert = $crawler->filter('h2 a')->extract(array('_text'))); | |
103 | $this->assertContains('Google', $alert[0]); | |
104 | } | |
105 | ||
106 | /** | |
107 | * This test will require an internet connection. | |
108 | */ | |
109 | public function testPostNewThatWillBeTaggued() | |
110 | { | |
111 | $this->logInAs('admin'); | |
112 | $client = $this->getClient(); | |
113 | ||
114 | $crawler = $client->request('GET', '/new'); | |
115 | ||
116 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
117 | ||
118 | $form = $crawler->filter('button[type=submit]')->form(); | |
119 | ||
120 | $data = array( | |
121 | 'entry[url]' => $url = 'https://github.com/wallabag/wallabag', | |
122 | ); | |
123 | ||
124 | $client->submit($form, $data); | |
125 | ||
126 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
127 | ||
128 | $crawler = $client->followRedirect(); | |
129 | ||
130 | $em = $client->getContainer() | |
131 | ->get('doctrine.orm.entity_manager'); | |
132 | $entry = $em | |
133 | ->getRepository('WallabagCoreBundle:Entry') | |
134 | ->findOneByUrl($url); | |
135 | $tags = $entry->getTags(); | |
136 | ||
137 | $this->assertCount(1, $tags); | |
138 | $this->assertEquals('wallabag', $tags[0]->getLabel()); | |
139 | ||
140 | $em->remove($entry); | |
141 | $em->flush(); | |
142 | } | |
143 | ||
144 | public function testArchive() | |
145 | { | |
146 | $this->logInAs('admin'); | |
147 | $client = $this->getClient(); | |
148 | ||
149 | $client->request('GET', '/archive/list'); | |
150 | ||
151 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
152 | } | |
153 | ||
154 | public function testStarred() | |
155 | { | |
156 | $this->logInAs('admin'); | |
157 | $client = $this->getClient(); | |
158 | ||
159 | $client->request('GET', '/starred/list'); | |
160 | ||
161 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
162 | } | |
163 | ||
164 | /** | |
165 | * @depends testPostNewOk | |
166 | */ | |
167 | public function testView() | |
168 | { | |
169 | $this->logInAs('admin'); | |
170 | $client = $this->getClient(); | |
171 | ||
172 | $content = $client->getContainer() | |
173 | ->get('doctrine.orm.entity_manager') | |
174 | ->getRepository('WallabagCoreBundle:Entry') | |
175 | ->findOneByUrl($this->url); | |
176 | ||
177 | $client->request('GET', '/view/'.$content->getId()); | |
178 | ||
179 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
180 | $this->assertContains($content->getTitle(), $client->getResponse()->getContent()); | |
181 | } | |
182 | ||
183 | public function testEdit() | |
184 | { | |
185 | $this->logInAs('admin'); | |
186 | $client = $this->getClient(); | |
187 | ||
188 | $content = $client->getContainer() | |
189 | ->get('doctrine.orm.entity_manager') | |
190 | ->getRepository('WallabagCoreBundle:Entry') | |
191 | ->findOneByUrl($this->url); | |
192 | ||
193 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | |
194 | ||
195 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
196 | ||
197 | $this->assertCount(1, $crawler->filter('input[id=entry_title]')); | |
198 | $this->assertCount(1, $crawler->filter('button[id=entry_save]')); | |
199 | } | |
200 | ||
201 | public function testEditUpdate() | |
202 | { | |
203 | $this->logInAs('admin'); | |
204 | $client = $this->getClient(); | |
205 | ||
206 | $content = $client->getContainer() | |
207 | ->get('doctrine.orm.entity_manager') | |
208 | ->getRepository('WallabagCoreBundle:Entry') | |
209 | ->findOneByUrl($this->url); | |
210 | ||
211 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | |
212 | ||
213 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
214 | ||
215 | $form = $crawler->filter('button[type=submit]')->form(); | |
216 | ||
217 | $data = array( | |
218 | 'entry[title]' => 'My updated title hehe :)', | |
219 | ); | |
220 | ||
221 | $client->submit($form, $data); | |
222 | ||
223 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
224 | ||
225 | $crawler = $client->followRedirect(); | |
226 | ||
227 | $this->assertGreaterThan(1, $alert = $crawler->filter('div[id=article] h1')->extract(array('_text'))); | |
228 | $this->assertContains('My updated title hehe :)', $alert[0]); | |
229 | } | |
230 | ||
231 | public function testToggleArchive() | |
232 | { | |
233 | $this->logInAs('admin'); | |
234 | $client = $this->getClient(); | |
235 | ||
236 | $content = $client->getContainer() | |
237 | ->get('doctrine.orm.entity_manager') | |
238 | ->getRepository('WallabagCoreBundle:Entry') | |
239 | ->findOneByUrl($this->url); | |
240 | ||
241 | $client->request('GET', '/archive/'.$content->getId()); | |
242 | ||
243 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
244 | ||
245 | $res = $client->getContainer() | |
246 | ->get('doctrine.orm.entity_manager') | |
247 | ->getRepository('WallabagCoreBundle:Entry') | |
248 | ->find($content->getId()); | |
249 | ||
250 | $this->assertEquals($res->isArchived(), true); | |
251 | } | |
252 | ||
253 | public function testToggleStar() | |
254 | { | |
255 | $this->logInAs('admin'); | |
256 | $client = $this->getClient(); | |
257 | ||
258 | $content = $client->getContainer() | |
259 | ->get('doctrine.orm.entity_manager') | |
260 | ->getRepository('WallabagCoreBundle:Entry') | |
261 | ->findOneByUrl($this->url); | |
262 | ||
263 | $client->request('GET', '/star/'.$content->getId()); | |
264 | ||
265 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
266 | ||
267 | $res = $client->getContainer() | |
268 | ->get('doctrine.orm.entity_manager') | |
269 | ->getRepository('WallabagCoreBundle:Entry') | |
270 | ->findOneById($content->getId()); | |
271 | ||
272 | $this->assertEquals($res->isStarred(), true); | |
273 | } | |
274 | ||
275 | public function testDelete() | |
276 | { | |
277 | $this->logInAs('admin'); | |
278 | $client = $this->getClient(); | |
279 | ||
280 | $content = $client->getContainer() | |
281 | ->get('doctrine.orm.entity_manager') | |
282 | ->getRepository('WallabagCoreBundle:Entry') | |
283 | ->findOneByUrl($this->url); | |
284 | ||
285 | $client->request('GET', '/delete/'.$content->getId()); | |
286 | ||
287 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
288 | ||
289 | $client->request('GET', '/delete/'.$content->getId()); | |
290 | ||
291 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | |
292 | } | |
293 | ||
294 | /** | |
295 | * It will create a new entry. | |
296 | * Browse to it. | |
297 | * Then remove it. | |
298 | * | |
299 | * And it'll check that user won't be redirected to the view page of the content when it had been removed | |
300 | */ | |
301 | public function testViewAndDelete() | |
302 | { | |
303 | $this->logInAs('admin'); | |
304 | $client = $this->getClient(); | |
305 | ||
306 | // add a new content to be removed later | |
307 | $user = $client->getContainer() | |
308 | ->get('doctrine.orm.entity_manager') | |
309 | ->getRepository('WallabagUserBundle:User') | |
310 | ->findOneByUserName('admin'); | |
311 | ||
312 | $content = new Entry($user); | |
313 | $content->setUrl('http://1.1.1.1/entry'); | |
314 | $content->setReadingTime(12); | |
315 | $content->setDomainName('domain.io'); | |
316 | $content->setMimetype('text/html'); | |
317 | $content->setTitle('test title entry'); | |
318 | $content->setContent('This is my content /o/'); | |
319 | $content->setArchived(true); | |
320 | $content->setLanguage('fr'); | |
321 | ||
322 | $client->getContainer() | |
323 | ->get('doctrine.orm.entity_manager') | |
324 | ->persist($content); | |
325 | $client->getContainer() | |
326 | ->get('doctrine.orm.entity_manager') | |
327 | ->flush(); | |
328 | ||
329 | $client->request('GET', '/view/'.$content->getId()); | |
330 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
331 | ||
332 | $client->request('GET', '/delete/'.$content->getId()); | |
333 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
334 | ||
335 | $client->followRedirect(); | |
336 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
337 | } | |
338 | ||
339 | public function testViewOtherUserEntry() | |
340 | { | |
341 | $this->logInAs('admin'); | |
342 | $client = $this->getClient(); | |
343 | ||
344 | $content = $client->getContainer() | |
345 | ->get('doctrine.orm.entity_manager') | |
346 | ->getRepository('WallabagCoreBundle:Entry') | |
347 | ->findOneByUsernameAndNotArchived('bob'); | |
348 | ||
349 | $client->request('GET', '/view/'.$content->getId()); | |
350 | ||
351 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | |
352 | } | |
353 | ||
354 | public function testFilterOnReadingTime() | |
355 | { | |
356 | $this->logInAs('admin'); | |
357 | $client = $this->getClient(); | |
358 | ||
359 | $crawler = $client->request('GET', '/unread/list'); | |
360 | ||
361 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
362 | ||
363 | $data = array( | |
364 | 'entry_filter[readingTime][right_number]' => 11, | |
365 | 'entry_filter[readingTime][left_number]' => 11, | |
366 | ); | |
367 | ||
368 | $crawler = $client->submit($form, $data); | |
369 | ||
370 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
371 | } | |
372 | ||
373 | public function testFilterOnCreationDate() | |
374 | { | |
375 | $this->logInAs('admin'); | |
376 | $client = $this->getClient(); | |
377 | ||
378 | $crawler = $client->request('GET', '/unread/list'); | |
379 | ||
380 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
381 | ||
382 | $data = array( | |
383 | 'entry_filter[createdAt][left_date]' => date('d/m/Y'), | |
384 | 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')), | |
385 | ); | |
386 | ||
387 | $crawler = $client->submit($form, $data); | |
388 | ||
389 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
390 | ||
391 | $data = array( | |
392 | 'entry_filter[createdAt][left_date]' => date('d/m/Y'), | |
393 | 'entry_filter[createdAt][right_date]' => date('d/m/Y'), | |
394 | ); | |
395 | ||
396 | $crawler = $client->submit($form, $data); | |
397 | ||
398 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
399 | ||
400 | $data = array( | |
401 | 'entry_filter[createdAt][left_date]' => '01/01/1970', | |
402 | 'entry_filter[createdAt][right_date]' => '01/01/1970', | |
403 | ); | |
404 | ||
405 | $crawler = $client->submit($form, $data); | |
406 | ||
407 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
408 | } | |
409 | ||
410 | public function testPaginationWithFilter() | |
411 | { | |
412 | $this->logInAs('admin'); | |
413 | $client = $this->getClient(); | |
414 | $crawler = $client->request('GET', '/config'); | |
415 | ||
416 | $form = $crawler->filter('button[id=config_save]')->form(); | |
417 | ||
418 | $data = array( | |
419 | 'config[items_per_page]' => '1', | |
420 | ); | |
421 | ||
422 | $client->submit($form, $data); | |
423 | ||
424 | $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D='; | |
425 | ||
426 | $crawler = $client->request('GET', 'unread/list'.$parameters); | |
427 | ||
428 | $this->assertContains($parameters, $client->getResponse()->getContent()); | |
429 | ||
430 | // reset pagination | |
431 | $crawler = $client->request('GET', '/config'); | |
432 | $form = $crawler->filter('button[id=config_save]')->form(); | |
433 | $data = array( | |
434 | 'config[items_per_page]' => '12', | |
435 | ); | |
436 | $client->submit($form, $data); | |
437 | } | |
438 | ||
439 | public function testFilterOnDomainName() | |
440 | { | |
441 | $this->logInAs('admin'); | |
442 | $client = $this->getClient(); | |
443 | ||
444 | $crawler = $client->request('GET', '/unread/list'); | |
445 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
446 | $data = array( | |
447 | 'entry_filter[domainName]' => 'domain', | |
448 | ); | |
449 | ||
450 | $crawler = $client->submit($form, $data); | |
451 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
452 | ||
453 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
454 | $data = array( | |
455 | 'entry_filter[domainName]' => 'wallabag', | |
456 | ); | |
457 | ||
458 | $crawler = $client->submit($form, $data); | |
459 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
460 | } | |
461 | ||
462 | public function testFilterOnStatus() | |
463 | { | |
464 | $this->logInAs('admin'); | |
465 | $client = $this->getClient(); | |
466 | ||
467 | $crawler = $client->request('GET', '/unread/list'); | |
468 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
469 | $form['entry_filter[isArchived]']->tick(); | |
470 | $form['entry_filter[isStarred]']->untick(); | |
471 | ||
472 | $crawler = $client->submit($form); | |
473 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
474 | ||
475 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
476 | $form['entry_filter[isArchived]']->untick(); | |
477 | $form['entry_filter[isStarred]']->tick(); | |
478 | ||
479 | $crawler = $client->submit($form); | |
480 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
481 | } | |
482 | ||
483 | public function testPreviewPictureFilter() | |
484 | { | |
485 | $this->logInAs('admin'); | |
486 | $client = $this->getClient(); | |
487 | ||
488 | $crawler = $client->request('GET', '/unread/list'); | |
489 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
490 | $form['entry_filter[previewPicture]']->tick(); | |
491 | ||
492 | $crawler = $client->submit($form); | |
493 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
494 | } | |
495 | ||
496 | public function testFilterOnLanguage() | |
497 | { | |
498 | $this->logInAs('admin'); | |
499 | $client = $this->getClient(); | |
500 | ||
501 | $crawler = $client->request('GET', '/unread/list'); | |
502 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
503 | $data = array( | |
504 | 'entry_filter[language]' => 'fr', | |
505 | ); | |
506 | ||
507 | $crawler = $client->submit($form, $data); | |
508 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | |
509 | ||
510 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
511 | $data = array( | |
512 | 'entry_filter[language]' => 'en', | |
513 | ); | |
514 | ||
515 | $crawler = $client->submit($form, $data); | |
516 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | |
517 | } | |
518 | } |