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