]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | namespace Tests\Wallabag\CoreBundle\Controller; | |
4 | ||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | |
6 | use Wallabag\CoreBundle\Entity\Config; | |
7 | use Wallabag\CoreBundle\Entity\Entry; | |
8 | ||
9 | class EntryControllerTest extends WallabagCoreTestCase | |
10 | { | |
11 | public $downloadImagesEnabled = false; | |
12 | 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'; | |
13 | ||
14 | /** | |
15 | * @after | |
16 | * | |
17 | * Ensure download_images_enabled is disabled after each script | |
18 | */ | |
19 | public function tearDownImagesEnabled() | |
20 | { | |
21 | if ($this->downloadImagesEnabled) { | |
22 | $client = static::createClient(); | |
23 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); | |
24 | ||
25 | $this->downloadImagesEnabled = false; | |
26 | } | |
27 | } | |
28 | ||
29 | public function testLogin() | |
30 | { | |
31 | $client = $this->getClient(); | |
32 | ||
33 | $client->request('GET', '/new'); | |
34 | ||
35 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
36 | $this->assertContains('login', $client->getResponse()->headers->get('location')); | |
37 | } | |
38 | ||
39 | public function testQuickstart() | |
40 | { | |
41 | $this->logInAs('empty'); | |
42 | $client = $this->getClient(); | |
43 | ||
44 | $client->request('GET', '/unread/list'); | |
45 | $crawler = $client->followRedirect(); | |
46 | ||
47 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
48 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
49 | $this->assertContains('quickstart.intro.title', $body[0]); | |
50 | ||
51 | // Test if quickstart is disabled when user has 1 entry | |
52 | $crawler = $client->request('GET', '/new'); | |
53 | ||
54 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
55 | ||
56 | $form = $crawler->filter('form[name=entry]')->form(); | |
57 | ||
58 | $data = [ | |
59 | 'entry[url]' => $this->url, | |
60 | ]; | |
61 | ||
62 | $client->submit($form, $data); | |
63 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
64 | $client->followRedirect(); | |
65 | ||
66 | $crawler = $client->request('GET', '/unread/list'); | |
67 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
68 | $this->assertContains('entry.list.number_on_the_page', $body[0]); | |
69 | } | |
70 | ||
71 | public function testGetNew() | |
72 | { | |
73 | $this->logInAs('admin'); | |
74 | $client = $this->getClient(); | |
75 | ||
76 | $crawler = $client->request('GET', '/new'); | |
77 | ||
78 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
79 | ||
80 | $this->assertCount(1, $crawler->filter('input[type=url]')); | |
81 | $this->assertCount(1, $crawler->filter('form[name=entry]')); | |
82 | } | |
83 | ||
84 | public function testPostNewViaBookmarklet() | |
85 | { | |
86 | $this->logInAs('admin'); | |
87 | $client = $this->getClient(); | |
88 | ||
89 | $crawler = $client->request('GET', '/'); | |
90 | ||
91 | $this->assertCount(4, $crawler->filter('div[class=entry]')); | |
92 | ||
93 | // Good URL | |
94 | $client->request('GET', '/bookmarklet', ['url' => $this->url]); | |
95 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
96 | $client->followRedirect(); | |
97 | $crawler = $client->request('GET', '/'); | |
98 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
99 | ||
100 | $em = $client->getContainer() | |
101 | ->get('doctrine.orm.entity_manager'); | |
102 | $entry = $em | |
103 | ->getRepository('WallabagCoreBundle:Entry') | |
104 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
105 | $em->remove($entry); | |
106 | $em->flush(); | |
107 | } | |
108 | ||
109 | public function testPostNewEmpty() | |
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('form[name=entry]')->form(); | |
119 | ||
120 | $crawler = $client->submit($form); | |
121 | ||
122 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
123 | $this->assertCount(1, $alert = $crawler->filter('form ul li')->extract(['_text'])); | |
124 | $this->assertEquals('This value should not be blank.', $alert[0]); | |
125 | } | |
126 | ||
127 | /** | |
128 | * This test will require an internet connection. | |
129 | */ | |
130 | public function testPostNewOk() | |
131 | { | |
132 | $this->logInAs('admin'); | |
133 | $client = $this->getClient(); | |
134 | ||
135 | $crawler = $client->request('GET', '/new'); | |
136 | ||
137 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
138 | ||
139 | $form = $crawler->filter('form[name=entry]')->form(); | |
140 | ||
141 | $data = [ | |
142 | 'entry[url]' => $this->url, | |
143 | ]; | |
144 | ||
145 | $client->submit($form, $data); | |
146 | ||
147 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
148 | ||
149 | $content = $client->getContainer() | |
150 | ->get('doctrine.orm.entity_manager') | |
151 | ->getRepository('WallabagCoreBundle:Entry') | |
152 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
153 | ||
154 | $author = $content->getPublishedBy(); | |
155 | ||
156 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); | |
157 | $this->assertEquals($this->url, $content->getUrl()); | |
158 | $this->assertContains('Google', $content->getTitle()); | |
159 | $this->assertEquals('2015-03-28 15:37:39', $content->getPublishedAt()->format('Y-m-d H:i:s')); | |
160 | $this->assertEquals('Morgane Tual', $author[0]); | |
161 | $this->assertArrayHasKey('x-varnish1', $content->getHeaders()); | |
162 | } | |
163 | ||
164 | public function testPostWithMultipleAuthors() | |
165 | { | |
166 | $url = 'http://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768'; | |
167 | $this->logInAs('admin'); | |
168 | $client = $this->getClient(); | |
169 | ||
170 | $crawler = $client->request('GET', '/new'); | |
171 | ||
172 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
173 | ||
174 | $form = $crawler->filter('form[name=entry]')->form(); | |
175 | ||
176 | $data = [ | |
177 | 'entry[url]' => $url, | |
178 | ]; | |
179 | ||
180 | $client->submit($form, $data); | |
181 | ||
182 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
183 | ||
184 | $content = $client->getContainer() | |
185 | ->get('doctrine.orm.entity_manager') | |
186 | ->getRepository('WallabagCoreBundle:Entry') | |
187 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | |
188 | ||
189 | $authors = $content->getPublishedBy(); | |
190 | $this->assertEquals('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s')); | |
191 | $this->assertEquals('Raphaël Balenieri, correspondant à Pékin', $authors[0]); | |
192 | $this->assertEquals('Frédéric Autran, correspondant à New York', $authors[1]); | |
193 | } | |
194 | ||
195 | public function testPostNewOkUrlExist() | |
196 | { | |
197 | $this->logInAs('admin'); | |
198 | $client = $this->getClient(); | |
199 | ||
200 | $crawler = $client->request('GET', '/new'); | |
201 | ||
202 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
203 | ||
204 | $form = $crawler->filter('form[name=entry]')->form(); | |
205 | ||
206 | $data = [ | |
207 | 'entry[url]' => $this->url, | |
208 | ]; | |
209 | ||
210 | $client->submit($form, $data); | |
211 | ||
212 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
213 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); | |
214 | } | |
215 | ||
216 | public function testPostNewOkUrlExistWithAccent() | |
217 | { | |
218 | $this->logInAs('admin'); | |
219 | $client = $this->getClient(); | |
220 | ||
221 | $url = 'http://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing'; | |
222 | ||
223 | $crawler = $client->request('GET', '/new'); | |
224 | ||
225 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
226 | ||
227 | $form = $crawler->filter('form[name=entry]')->form(); | |
228 | ||
229 | $data = [ | |
230 | 'entry[url]' => $url, | |
231 | ]; | |
232 | ||
233 | $client->submit($form, $data); | |
234 | ||
235 | $crawler = $client->request('GET', '/new'); | |
236 | ||
237 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
238 | ||
239 | $form = $crawler->filter('form[name=entry]')->form(); | |
240 | ||
241 | $data = [ | |
242 | 'entry[url]' => $url, | |
243 | ]; | |
244 | ||
245 | $client->submit($form, $data); | |
246 | ||
247 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
248 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); | |
249 | ||
250 | $em = $client->getContainer() | |
251 | ->get('doctrine.orm.entity_manager'); | |
252 | $entry = $em | |
253 | ->getRepository('WallabagCoreBundle:Entry') | |
254 | ->findOneByUrl(urldecode($url)); | |
255 | ||
256 | $em->remove($entry); | |
257 | $em->flush(); | |
258 | } | |
259 | ||
260 | /** | |
261 | * This test will require an internet connection. | |
262 | */ | |
263 | public function testPostNewThatWillBeTagged() | |
264 | { | |
265 | $this->logInAs('admin'); | |
266 | $client = $this->getClient(); | |
267 | ||
268 | $crawler = $client->request('GET', '/new'); | |
269 | ||
270 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
271 | ||
272 | $form = $crawler->filter('form[name=entry]')->form(); | |
273 | ||
274 | $data = [ | |
275 | 'entry[url]' => $url = 'https://github.com/wallabag/wallabag', | |
276 | ]; | |
277 | ||
278 | $client->submit($form, $data); | |
279 | ||
280 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
281 | $this->assertContains('/', $client->getResponse()->getTargetUrl()); | |
282 | ||
283 | $em = $client->getContainer() | |
284 | ->get('doctrine.orm.entity_manager'); | |
285 | $entry = $em | |
286 | ->getRepository('WallabagCoreBundle:Entry') | |
287 | ->findOneByUrl($url); | |
288 | $tags = $entry->getTags(); | |
289 | ||
290 | $this->assertCount(2, $tags); | |
291 | $this->assertEquals('wallabag', $tags[0]->getLabel()); | |
292 | ||
293 | $em->remove($entry); | |
294 | $em->flush(); | |
295 | ||
296 | // and now re-submit it to test the cascade persistence for tags after entry removal | |
297 | // related https://github.com/wallabag/wallabag/issues/2121 | |
298 | $crawler = $client->request('GET', '/new'); | |
299 | ||
300 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
301 | ||
302 | $form = $crawler->filter('form[name=entry]')->form(); | |
303 | ||
304 | $data = [ | |
305 | 'entry[url]' => $url = 'https://github.com/wallabag/wallabag/tree/master', | |
306 | ]; | |
307 | ||
308 | $client->submit($form, $data); | |
309 | ||
310 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
311 | $this->assertContains('/', $client->getResponse()->getTargetUrl()); | |
312 | ||
313 | $entry = $em | |
314 | ->getRepository('WallabagCoreBundle:Entry') | |
315 | ->findOneByUrl($url); | |
316 | ||
317 | $tags = $entry->getTags(); | |
318 | ||
319 | $this->assertCount(2, $tags); | |
320 | $this->assertEquals('wallabag', $tags[1]->getLabel()); | |
321 | ||
322 | $em->remove($entry); | |
323 | $em->flush(); | |
324 | } | |
325 | ||
326 | public function testArchive() | |
327 | { | |
328 | $this->logInAs('admin'); | |
329 | $client = $this->getClient(); | |
330 | ||
331 | $client->request('GET', '/archive/list'); | |
332 | ||
333 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
334 | } | |
335 | ||
336 | public function testUntagged() | |
337 | { | |
338 | $this->logInAs('admin'); | |
339 | $client = $this->getClient(); | |
340 | ||
341 | $client->request('GET', '/untagged/list'); | |
342 | ||
343 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
344 | } | |
345 | ||
346 | public function testStarred() | |
347 | { | |
348 | $this->logInAs('admin'); | |
349 | $client = $this->getClient(); | |
350 | ||
351 | $client->request('GET', '/starred/list'); | |
352 | ||
353 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
354 | } | |
355 | ||
356 | public function testRangeException() | |
357 | { | |
358 | $this->logInAs('admin'); | |
359 | $client = $this->getClient(); | |
360 | ||
361 | $client->request('GET', '/all/list/900'); | |
362 | ||
363 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
364 | $this->assertEquals('/all/list', $client->getResponse()->getTargetUrl()); | |
365 | } | |
366 | ||
367 | /** | |
368 | * @depends testPostNewOk | |
369 | */ | |
370 | public function testView() | |
371 | { | |
372 | $this->logInAs('admin'); | |
373 | $client = $this->getClient(); | |
374 | ||
375 | $content = $client->getContainer() | |
376 | ->get('doctrine.orm.entity_manager') | |
377 | ->getRepository('WallabagCoreBundle:Entry') | |
378 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
379 | ||
380 | $crawler = $client->request('GET', '/view/'.$content->getId()); | |
381 | ||
382 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
383 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
384 | $this->assertContains($content->getTitle(), $body[0]); | |
385 | } | |
386 | ||
387 | /** | |
388 | * @depends testPostNewOk | |
389 | * | |
390 | * This test will require an internet connection. | |
391 | */ | |
392 | public function testReload() | |
393 | { | |
394 | $this->logInAs('admin'); | |
395 | $client = $this->getClient(); | |
396 | ||
397 | $em = $client->getContainer() | |
398 | ->get('doctrine.orm.entity_manager'); | |
399 | ||
400 | $content = $em | |
401 | ->getRepository('WallabagCoreBundle:Entry') | |
402 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
403 | ||
404 | // empty content | |
405 | $content->setContent(''); | |
406 | $em->persist($content); | |
407 | $em->flush(); | |
408 | ||
409 | $client->request('GET', '/reload/'.$content->getId()); | |
410 | ||
411 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
412 | ||
413 | $content = $em | |
414 | ->getRepository('WallabagCoreBundle:Entry') | |
415 | ->find($content->getId()); | |
416 | ||
417 | $this->assertNotEmpty($content->getContent()); | |
418 | } | |
419 | ||
420 | /** | |
421 | * @depends testPostNewOk | |
422 | */ | |
423 | public function testReloadWithFetchingFailed() | |
424 | { | |
425 | $this->logInAs('admin'); | |
426 | $client = $this->getClient(); | |
427 | ||
428 | $em = $client->getContainer() | |
429 | ->get('doctrine.orm.entity_manager'); | |
430 | ||
431 | $content = $em | |
432 | ->getRepository('WallabagCoreBundle:Entry') | |
433 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
434 | ||
435 | // put a known failed url | |
436 | $content->setUrl('http://0.0.0.0/failed.html'); | |
437 | $em->persist($content); | |
438 | $em->flush(); | |
439 | ||
440 | $client->request('GET', '/reload/'.$content->getId()); | |
441 | ||
442 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
443 | ||
444 | // force EntityManager to clear previous entity | |
445 | // otherwise, retrieve the same entity will retrieve change from the previous request :0 | |
446 | $em->clear(); | |
447 | $newContent = $em | |
448 | ->getRepository('WallabagCoreBundle:Entry') | |
449 | ->find($content->getId()); | |
450 | ||
451 | $newContent->setUrl($this->url); | |
452 | $em->persist($newContent); | |
453 | $em->flush(); | |
454 | ||
455 | $this->assertNotEquals($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent()); | |
456 | } | |
457 | ||
458 | public function testEdit() | |
459 | { | |
460 | $this->logInAs('admin'); | |
461 | $client = $this->getClient(); | |
462 | ||
463 | $content = $client->getContainer() | |
464 | ->get('doctrine.orm.entity_manager') | |
465 | ->getRepository('WallabagCoreBundle:Entry') | |
466 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
467 | ||
468 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | |
469 | ||
470 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
471 | ||
472 | $this->assertCount(1, $crawler->filter('input[id=entry_title]')); | |
473 | $this->assertCount(1, $crawler->filter('button[id=entry_save]')); | |
474 | } | |
475 | ||
476 | public function testEditUpdate() | |
477 | { | |
478 | $this->logInAs('admin'); | |
479 | $client = $this->getClient(); | |
480 | ||
481 | $content = $client->getContainer() | |
482 | ->get('doctrine.orm.entity_manager') | |
483 | ->getRepository('WallabagCoreBundle:Entry') | |
484 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
485 | ||
486 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | |
487 | ||
488 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
489 | ||
490 | $form = $crawler->filter('button[type=submit]')->form(); | |
491 | ||
492 | $data = [ | |
493 | 'entry[title]' => 'My updated title hehe :)', | |
494 | ]; | |
495 | ||
496 | $client->submit($form, $data); | |
497 | ||
498 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
499 | ||
500 | $crawler = $client->followRedirect(); | |
501 | ||
502 | $this->assertGreaterThan(1, $alert = $crawler->filter('div[id=article] h1')->extract(['_text'])); | |
503 | $this->assertContains('My updated title hehe :)', $alert[0]); | |
504 | } | |
505 | ||
506 | public function testToggleArchive() | |
507 | { | |
508 | $this->logInAs('admin'); | |
509 | $client = $this->getClient(); | |
510 | ||
511 | $content = $client->getContainer() | |
512 | ->get('doctrine.orm.entity_manager') | |
513 | ->getRepository('WallabagCoreBundle:Entry') | |
514 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
515 | ||
516 | $client->request('GET', '/archive/'.$content->getId()); | |
517 | ||
518 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
519 | ||
520 | $res = $client->getContainer() | |
521 | ->get('doctrine.orm.entity_manager') | |
522 | ->getRepository('WallabagCoreBundle:Entry') | |
523 | ->find($content->getId()); | |
524 | ||
525 | $this->assertEquals($res->isArchived(), true); | |
526 | } | |
527 | ||
528 | public function testToggleStar() | |
529 | { | |
530 | $this->logInAs('admin'); | |
531 | $client = $this->getClient(); | |
532 | ||
533 | $content = $client->getContainer() | |
534 | ->get('doctrine.orm.entity_manager') | |
535 | ->getRepository('WallabagCoreBundle:Entry') | |
536 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
537 | ||
538 | $client->request('GET', '/star/'.$content->getId()); | |
539 | ||
540 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
541 | ||
542 | $res = $client->getContainer() | |
543 | ->get('doctrine.orm.entity_manager') | |
544 | ->getRepository('WallabagCoreBundle:Entry') | |
545 | ->findOneById($content->getId()); | |
546 | ||
547 | $this->assertEquals($res->isStarred(), true); | |
548 | } | |
549 | ||
550 | public function testDelete() | |
551 | { | |
552 | $this->logInAs('admin'); | |
553 | $client = $this->getClient(); | |
554 | ||
555 | $content = $client->getContainer() | |
556 | ->get('doctrine.orm.entity_manager') | |
557 | ->getRepository('WallabagCoreBundle:Entry') | |
558 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
559 | ||
560 | $client->request('GET', '/delete/'.$content->getId()); | |
561 | ||
562 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
563 | ||
564 | $client->request('GET', '/delete/'.$content->getId()); | |
565 | ||
566 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | |
567 | } | |
568 | ||
569 | /** | |
570 | * It will create a new entry. | |
571 | * Browse to it. | |
572 | * Then remove it. | |
573 | * | |
574 | * And it'll check that user won't be redirected to the view page of the content when it had been removed | |
575 | */ | |
576 | public function testViewAndDelete() | |
577 | { | |
578 | $this->logInAs('admin'); | |
579 | $client = $this->getClient(); | |
580 | ||
581 | $em = $client->getContainer() | |
582 | ->get('doctrine.orm.entity_manager'); | |
583 | ||
584 | // add a new content to be removed later | |
585 | $user = $em | |
586 | ->getRepository('WallabagUserBundle:User') | |
587 | ->findOneByUserName('admin'); | |
588 | ||
589 | $content = new Entry($user); | |
590 | $content->setUrl('http://1.1.1.1/entry'); | |
591 | $content->setReadingTime(12); | |
592 | $content->setDomainName('domain.io'); | |
593 | $content->setMimetype('text/html'); | |
594 | $content->setTitle('test title entry'); | |
595 | $content->setContent('This is my content /o/'); | |
596 | $content->setArchived(true); | |
597 | $content->setLanguage('fr'); | |
598 | ||
599 | $em->persist($content); | |
600 | $em->flush(); | |
601 | ||
602 | $client->request('GET', '/view/'.$content->getId()); | |
603 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
604 | ||
605 | $client->request('GET', '/delete/'.$content->getId()); | |
606 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
607 | ||
608 | $client->followRedirect(); | |
609 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
610 | } | |
611 | ||
612 | public function testViewOtherUserEntry() | |
613 | { | |
614 | $this->logInAs('admin'); | |
615 | $client = $this->getClient(); | |
616 | ||
617 | $content = $client->getContainer() | |
618 | ->get('doctrine.orm.entity_manager') | |
619 | ->getRepository('WallabagCoreBundle:Entry') | |
620 | ->findOneByUsernameAndNotArchived('bob'); | |
621 | ||
622 | $client->request('GET', '/view/'.$content->getId()); | |
623 | ||
624 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | |
625 | } | |
626 | ||
627 | public function testFilterOnReadingTime() | |
628 | { | |
629 | $this->logInAs('admin'); | |
630 | $client = $this->getClient(); | |
631 | ||
632 | $crawler = $client->request('GET', '/unread/list'); | |
633 | ||
634 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
635 | ||
636 | $data = [ | |
637 | 'entry_filter[readingTime][right_number]' => 22, | |
638 | 'entry_filter[readingTime][left_number]' => 22, | |
639 | ]; | |
640 | ||
641 | $crawler = $client->submit($form, $data); | |
642 | ||
643 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
644 | } | |
645 | ||
646 | public function testFilterOnReadingTimeWithNegativeValue() | |
647 | { | |
648 | $this->logInAs('admin'); | |
649 | $client = $this->getClient(); | |
650 | ||
651 | $crawler = $client->request('GET', '/unread/list'); | |
652 | ||
653 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
654 | ||
655 | $data = [ | |
656 | 'entry_filter[readingTime][right_number]' => -22, | |
657 | 'entry_filter[readingTime][left_number]' => -22, | |
658 | ]; | |
659 | ||
660 | $crawler = $client->submit($form, $data); | |
661 | ||
662 | // forcing negative value results in no entry displayed | |
663 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
664 | } | |
665 | ||
666 | public function testFilterOnReadingTimeOnlyUpper() | |
667 | { | |
668 | $this->logInAs('admin'); | |
669 | $client = $this->getClient(); | |
670 | ||
671 | $crawler = $client->request('GET', '/unread/list'); | |
672 | ||
673 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
674 | ||
675 | $data = [ | |
676 | 'entry_filter[readingTime][right_number]' => 22, | |
677 | ]; | |
678 | ||
679 | $crawler = $client->submit($form, $data); | |
680 | ||
681 | $this->assertCount(3, $crawler->filter('div[class=entry]')); | |
682 | } | |
683 | ||
684 | public function testFilterOnReadingTimeOnlyLower() | |
685 | { | |
686 | $this->logInAs('admin'); | |
687 | $client = $this->getClient(); | |
688 | ||
689 | $crawler = $client->request('GET', '/unread/list'); | |
690 | ||
691 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
692 | ||
693 | $data = [ | |
694 | 'entry_filter[readingTime][left_number]' => 22, | |
695 | ]; | |
696 | ||
697 | $crawler = $client->submit($form, $data); | |
698 | ||
699 | $this->assertCount(4, $crawler->filter('div[class=entry]')); | |
700 | } | |
701 | ||
702 | public function testFilterOnUnreadStatus() | |
703 | { | |
704 | $this->logInAs('admin'); | |
705 | $client = $this->getClient(); | |
706 | ||
707 | $crawler = $client->request('GET', '/all/list'); | |
708 | ||
709 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
710 | ||
711 | $data = [ | |
712 | 'entry_filter[isUnread]' => true, | |
713 | ]; | |
714 | ||
715 | $crawler = $client->submit($form, $data); | |
716 | ||
717 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
718 | } | |
719 | ||
720 | public function testFilterOnCreationDate() | |
721 | { | |
722 | $this->logInAs('admin'); | |
723 | $client = $this->getClient(); | |
724 | ||
725 | $crawler = $client->request('GET', '/unread/list'); | |
726 | ||
727 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
728 | ||
729 | $data = [ | |
730 | 'entry_filter[createdAt][left_date]' => date('d/m/Y'), | |
731 | 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')), | |
732 | ]; | |
733 | ||
734 | $crawler = $client->submit($form, $data); | |
735 | ||
736 | $this->assertCount(6, $crawler->filter('div[class=entry]')); | |
737 | ||
738 | $data = [ | |
739 | 'entry_filter[createdAt][left_date]' => date('d/m/Y'), | |
740 | 'entry_filter[createdAt][right_date]' => date('d/m/Y'), | |
741 | ]; | |
742 | ||
743 | $crawler = $client->submit($form, $data); | |
744 | ||
745 | $this->assertCount(6, $crawler->filter('div[class=entry]')); | |
746 | ||
747 | $data = [ | |
748 | 'entry_filter[createdAt][left_date]' => '01/01/1970', | |
749 | 'entry_filter[createdAt][right_date]' => '01/01/1970', | |
750 | ]; | |
751 | ||
752 | $crawler = $client->submit($form, $data); | |
753 | ||
754 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
755 | } | |
756 | ||
757 | public function testPaginationWithFilter() | |
758 | { | |
759 | $this->logInAs('admin'); | |
760 | $client = $this->getClient(); | |
761 | $crawler = $client->request('GET', '/config'); | |
762 | ||
763 | $form = $crawler->filter('button[id=config_save]')->form(); | |
764 | ||
765 | $data = [ | |
766 | 'config[items_per_page]' => '1', | |
767 | ]; | |
768 | ||
769 | $client->submit($form, $data); | |
770 | ||
771 | $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D='; | |
772 | ||
773 | $client->request('GET', 'unread/list'.$parameters); | |
774 | ||
775 | $this->assertContains($parameters, $client->getResponse()->getContent()); | |
776 | ||
777 | // reset pagination | |
778 | $crawler = $client->request('GET', '/config'); | |
779 | $form = $crawler->filter('button[id=config_save]')->form(); | |
780 | $data = [ | |
781 | 'config[items_per_page]' => '12', | |
782 | ]; | |
783 | $client->submit($form, $data); | |
784 | } | |
785 | ||
786 | public function testFilterOnDomainName() | |
787 | { | |
788 | $this->logInAs('admin'); | |
789 | $client = $this->getClient(); | |
790 | ||
791 | $crawler = $client->request('GET', '/unread/list'); | |
792 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
793 | $data = [ | |
794 | 'entry_filter[domainName]' => 'domain', | |
795 | ]; | |
796 | ||
797 | $crawler = $client->submit($form, $data); | |
798 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
799 | ||
800 | $crawler = $client->request('GET', '/unread/list'); | |
801 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
802 | $data = [ | |
803 | 'entry_filter[domainName]' => 'dOmain', | |
804 | ]; | |
805 | ||
806 | $crawler = $client->submit($form, $data); | |
807 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
808 | ||
809 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
810 | $data = [ | |
811 | 'entry_filter[domainName]' => 'wallabag', | |
812 | ]; | |
813 | ||
814 | $crawler = $client->submit($form, $data); | |
815 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
816 | } | |
817 | ||
818 | public function testFilterOnStatus() | |
819 | { | |
820 | $this->logInAs('admin'); | |
821 | $client = $this->getClient(); | |
822 | ||
823 | $crawler = $client->request('GET', '/unread/list'); | |
824 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
825 | $form['entry_filter[isArchived]']->tick(); | |
826 | $form['entry_filter[isStarred]']->untick(); | |
827 | ||
828 | $crawler = $client->submit($form); | |
829 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
830 | ||
831 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
832 | $form['entry_filter[isArchived]']->untick(); | |
833 | $form['entry_filter[isStarred]']->tick(); | |
834 | ||
835 | $crawler = $client->submit($form); | |
836 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
837 | } | |
838 | ||
839 | public function testPreviewPictureFilter() | |
840 | { | |
841 | $this->logInAs('admin'); | |
842 | $client = $this->getClient(); | |
843 | ||
844 | $crawler = $client->request('GET', '/unread/list'); | |
845 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
846 | $form['entry_filter[previewPicture]']->tick(); | |
847 | ||
848 | $crawler = $client->submit($form); | |
849 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | |
850 | } | |
851 | ||
852 | public function testFilterOnLanguage() | |
853 | { | |
854 | $this->logInAs('admin'); | |
855 | $client = $this->getClient(); | |
856 | ||
857 | $crawler = $client->request('GET', '/unread/list'); | |
858 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
859 | $data = [ | |
860 | 'entry_filter[language]' => 'fr', | |
861 | ]; | |
862 | ||
863 | $crawler = $client->submit($form, $data); | |
864 | $this->assertCount(3, $crawler->filter('div[class=entry]')); | |
865 | ||
866 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
867 | $data = [ | |
868 | 'entry_filter[language]' => 'en', | |
869 | ]; | |
870 | ||
871 | $crawler = $client->submit($form, $data); | |
872 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | |
873 | } | |
874 | ||
875 | public function testShareEntryPublicly() | |
876 | { | |
877 | $this->logInAs('admin'); | |
878 | $client = $this->getClient(); | |
879 | ||
880 | $content = $client->getContainer() | |
881 | ->get('doctrine.orm.entity_manager') | |
882 | ->getRepository('WallabagCoreBundle:Entry') | |
883 | ->findOneByUser($this->getLoggedInUserId()); | |
884 | ||
885 | // no uid | |
886 | $client->request('GET', '/share/'.$content->getUid()); | |
887 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | |
888 | ||
889 | // generating the uid | |
890 | $client->request('GET', '/share/'.$content->getId()); | |
891 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
892 | ||
893 | // follow link with uid | |
894 | $crawler = $client->followRedirect(); | |
895 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
896 | $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control')); | |
897 | $this->assertContains('public', $client->getResponse()->headers->get('cache-control')); | |
898 | $this->assertContains('s-maxage=25200', $client->getResponse()->headers->get('cache-control')); | |
899 | $this->assertNotContains('no-cache', $client->getResponse()->headers->get('cache-control')); | |
900 | $this->assertContains('og:title', $client->getResponse()->getContent()); | |
901 | $this->assertContains('og:type', $client->getResponse()->getContent()); | |
902 | $this->assertContains('og:url', $client->getResponse()->getContent()); | |
903 | $this->assertContains('og:image', $client->getResponse()->getContent()); | |
904 | ||
905 | // sharing is now disabled | |
906 | $client->getContainer()->get('craue_config')->set('share_public', 0); | |
907 | $client->request('GET', '/share/'.$content->getUid()); | |
908 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | |
909 | ||
910 | $client->request('GET', '/view/'.$content->getId()); | |
911 | $this->assertContains('no-cache', $client->getResponse()->headers->get('cache-control')); | |
912 | ||
913 | // removing the share | |
914 | $client->request('GET', '/share/delete/'.$content->getId()); | |
915 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
916 | ||
917 | // share is now disable | |
918 | $client->request('GET', '/share/'.$content->getUid()); | |
919 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | |
920 | } | |
921 | ||
922 | public function testNewEntryWithDownloadImagesEnabled() | |
923 | { | |
924 | $this->downloadImagesEnabled = true; | |
925 | $this->logInAs('admin'); | |
926 | $client = $this->getClient(); | |
927 | ||
928 | $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route'; | |
929 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 1); | |
930 | ||
931 | $crawler = $client->request('GET', '/new'); | |
932 | ||
933 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
934 | ||
935 | $form = $crawler->filter('form[name=entry]')->form(); | |
936 | ||
937 | $data = [ | |
938 | 'entry[url]' => $url, | |
939 | ]; | |
940 | ||
941 | $client->submit($form, $data); | |
942 | ||
943 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
944 | ||
945 | $em = $client->getContainer() | |
946 | ->get('doctrine.orm.entity_manager'); | |
947 | ||
948 | $entry = $em | |
949 | ->getRepository('WallabagCoreBundle:Entry') | |
950 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | |
951 | ||
952 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry); | |
953 | $this->assertEquals($url, $entry->getUrl()); | |
954 | $this->assertContains('Perpignan', $entry->getTitle()); | |
955 | // instead of checking for the filename (which might change) check that the image is now local | |
956 | $this->assertContains('http://v2.wallabag.org/assets/images/', $entry->getContent()); | |
957 | ||
958 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); | |
959 | } | |
960 | ||
961 | /** | |
962 | * @depends testNewEntryWithDownloadImagesEnabled | |
963 | */ | |
964 | public function testRemoveEntryWithDownloadImagesEnabled() | |
965 | { | |
966 | $this->downloadImagesEnabled = true; | |
967 | $this->logInAs('admin'); | |
968 | $client = $this->getClient(); | |
969 | ||
970 | $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route'; | |
971 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 1); | |
972 | ||
973 | $content = $client->getContainer() | |
974 | ->get('doctrine.orm.entity_manager') | |
975 | ->getRepository('WallabagCoreBundle:Entry') | |
976 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | |
977 | ||
978 | $client->request('GET', '/delete/'.$content->getId()); | |
979 | ||
980 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
981 | ||
982 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); | |
983 | } | |
984 | ||
985 | public function testRedirectToHomepage() | |
986 | { | |
987 | $this->logInAs('empty'); | |
988 | $client = $this->getClient(); | |
989 | ||
990 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
991 | $user = $em | |
992 | ->getRepository('WallabagUserBundle:User') | |
993 | ->find($this->getLoggedInUserId()); | |
994 | ||
995 | if (!$user) { | |
996 | $this->markTestSkipped('No user found in db.'); | |
997 | } | |
998 | ||
999 | // Redirect to homepage | |
1000 | $config = $user->getConfig(); | |
1001 | $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); | |
1002 | $em->persist($config); | |
1003 | $em->flush(); | |
1004 | ||
1005 | $content = $client->getContainer() | |
1006 | ->get('doctrine.orm.entity_manager') | |
1007 | ->getRepository('WallabagCoreBundle:Entry') | |
1008 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
1009 | ||
1010 | $client->request('GET', '/view/'.$content->getId()); | |
1011 | $client->request('GET', '/archive/'.$content->getId()); | |
1012 | ||
1013 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
1014 | $this->assertEquals('/', $client->getResponse()->headers->get('location')); | |
1015 | } | |
1016 | ||
1017 | public function testRedirectToCurrentPage() | |
1018 | { | |
1019 | $this->logInAs('empty'); | |
1020 | $client = $this->getClient(); | |
1021 | ||
1022 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
1023 | $user = $em | |
1024 | ->getRepository('WallabagUserBundle:User') | |
1025 | ->find($this->getLoggedInUserId()); | |
1026 | ||
1027 | if (!$user) { | |
1028 | $this->markTestSkipped('No user found in db.'); | |
1029 | } | |
1030 | ||
1031 | // Redirect to current page | |
1032 | $config = $user->getConfig(); | |
1033 | $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE); | |
1034 | $em->persist($config); | |
1035 | $em->flush(); | |
1036 | ||
1037 | $content = $client->getContainer() | |
1038 | ->get('doctrine.orm.entity_manager') | |
1039 | ->getRepository('WallabagCoreBundle:Entry') | |
1040 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
1041 | ||
1042 | $client->request('GET', '/view/'.$content->getId()); | |
1043 | $client->request('GET', '/archive/'.$content->getId()); | |
1044 | ||
1045 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
1046 | $this->assertContains('/view/'.$content->getId(), $client->getResponse()->headers->get('location')); | |
1047 | } | |
1048 | ||
1049 | public function testFilterOnHttpStatus() | |
1050 | { | |
1051 | $this->logInAs('admin'); | |
1052 | $client = $this->getClient(); | |
1053 | ||
1054 | $crawler = $client->request('GET', '/new'); | |
1055 | $form = $crawler->filter('form[name=entry]')->form(); | |
1056 | ||
1057 | $data = [ | |
1058 | 'entry[url]' => 'http://www.lemonde.fr/incorrect-url/', | |
1059 | ]; | |
1060 | ||
1061 | $client->submit($form, $data); | |
1062 | ||
1063 | $crawler = $client->request('GET', '/all/list'); | |
1064 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
1065 | ||
1066 | $data = [ | |
1067 | 'entry_filter[httpStatus]' => 404, | |
1068 | ]; | |
1069 | ||
1070 | $crawler = $client->submit($form, $data); | |
1071 | ||
1072 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
1073 | ||
1074 | $crawler = $client->request('GET', '/new'); | |
1075 | $form = $crawler->filter('form[name=entry]')->form(); | |
1076 | ||
1077 | $data = [ | |
1078 | 'entry[url]' => 'http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm', | |
1079 | ]; | |
1080 | ||
1081 | $client->submit($form, $data); | |
1082 | ||
1083 | $crawler = $client->request('GET', '/all/list'); | |
1084 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
1085 | ||
1086 | $data = [ | |
1087 | 'entry_filter[httpStatus]' => 200, | |
1088 | ]; | |
1089 | ||
1090 | $crawler = $client->submit($form, $data); | |
1091 | ||
1092 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | |
1093 | ||
1094 | $crawler = $client->request('GET', '/all/list'); | |
1095 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
1096 | ||
1097 | $data = [ | |
1098 | 'entry_filter[httpStatus]' => 1024, | |
1099 | ]; | |
1100 | ||
1101 | $crawler = $client->submit($form, $data); | |
1102 | ||
1103 | $this->assertCount(8, $crawler->filter('div[class=entry]')); | |
1104 | } | |
1105 | ||
1106 | public function testSearch() | |
1107 | { | |
1108 | $this->logInAs('admin'); | |
1109 | $client = $this->getClient(); | |
1110 | ||
1111 | // Search on unread list | |
1112 | $crawler = $client->request('GET', '/unread/list'); | |
1113 | ||
1114 | $form = $crawler->filter('form[name=search]')->form(); | |
1115 | $data = [ | |
1116 | 'search_entry[term]' => 'title', | |
1117 | ]; | |
1118 | ||
1119 | $crawler = $client->submit($form, $data); | |
1120 | ||
1121 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
1122 | ||
1123 | // Search on starred list | |
1124 | $crawler = $client->request('GET', '/starred/list'); | |
1125 | ||
1126 | $form = $crawler->filter('form[name=search]')->form(); | |
1127 | $data = [ | |
1128 | 'search_entry[term]' => 'title', | |
1129 | ]; | |
1130 | ||
1131 | $crawler = $client->submit($form, $data); | |
1132 | ||
1133 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
1134 | ||
1135 | // Added new article to test on archive list | |
1136 | $crawler = $client->request('GET', '/new'); | |
1137 | $form = $crawler->filter('form[name=entry]')->form(); | |
1138 | $data = [ | |
1139 | 'entry[url]' => $this->url, | |
1140 | ]; | |
1141 | $client->submit($form, $data); | |
1142 | $content = $client->getContainer() | |
1143 | ->get('doctrine.orm.entity_manager') | |
1144 | ->getRepository('WallabagCoreBundle:Entry') | |
1145 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
1146 | $client->request('GET', '/archive/'.$content->getId()); | |
1147 | ||
1148 | $crawler = $client->request('GET', '/archive/list'); | |
1149 | ||
1150 | $form = $crawler->filter('form[name=search]')->form(); | |
1151 | $data = [ | |
1152 | 'search_entry[term]' => 'manège', | |
1153 | ]; | |
1154 | ||
1155 | $crawler = $client->submit($form, $data); | |
1156 | ||
1157 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
1158 | $client->request('GET', '/delete/'.$content->getId()); | |
1159 | ||
1160 | // test on list of all articles | |
1161 | $crawler = $client->request('GET', '/all/list'); | |
1162 | ||
1163 | $form = $crawler->filter('form[name=search]')->form(); | |
1164 | $data = [ | |
1165 | 'search_entry[term]' => 'wxcvbnqsdf', // a string not available in the database | |
1166 | ]; | |
1167 | ||
1168 | $crawler = $client->submit($form, $data); | |
1169 | ||
1170 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
1171 | ||
1172 | // test url search on list of all articles | |
1173 | $crawler = $client->request('GET', '/all/list'); | |
1174 | ||
1175 | $form = $crawler->filter('form[name=search]')->form(); | |
1176 | $data = [ | |
1177 | 'search_entry[term]' => 'domain', // the search will match an entry with 'domain' in its url | |
1178 | ]; | |
1179 | ||
1180 | $crawler = $client->submit($form, $data); | |
1181 | ||
1182 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
1183 | ||
1184 | // same as previous test but for case-sensitivity | |
1185 | $crawler = $client->request('GET', '/all/list'); | |
1186 | ||
1187 | $form = $crawler->filter('form[name=search]')->form(); | |
1188 | $data = [ | |
1189 | 'search_entry[term]' => 'doMain', // the search will match an entry with 'domain' in its url | |
1190 | ]; | |
1191 | ||
1192 | $crawler = $client->submit($form, $data); | |
1193 | ||
1194 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
1195 | } | |
1196 | } |