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