]>
Commit | Line | Data |
---|---|---|
93fd4692 NL |
1 | <?php |
2 | ||
23634d5d | 3 | namespace Tests\Wallabag\CoreBundle\Controller; |
93fd4692 | 4 | |
23634d5d | 5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
2863bf2a | 6 | use Wallabag\CoreBundle\Entity\Entry; |
93fd4692 | 7 | |
769e19dc | 8 | class EntryControllerTest extends WallabagCoreTestCase |
93fd4692 | 9 | { |
02d17813 JB |
10 | public $url = 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html'; |
11 | ||
3b815d2d J |
12 | public function testLogin() |
13 | { | |
14 | $client = $this->getClient(); | |
15 | ||
eb3bd7ef | 16 | $client->request('GET', '/new'); |
3b815d2d J |
17 | |
18 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
19 | $this->assertContains('login', $client->getResponse()->headers->get('location')); | |
20 | } | |
21 | ||
5c072d2b NL |
22 | public function testQuickstart() |
23 | { | |
24 | $this->logInAs('empty'); | |
25 | $client = $this->getClient(); | |
26 | ||
27 | $client->request('GET', '/unread/list'); | |
4f9cf232 | 28 | $crawler = $client->followRedirect(); |
5c072d2b NL |
29 | |
30 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
4094ea47 | 31 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
4f9cf232 | 32 | $this->assertContains('quickstart.intro.paragraph_1', $body[0]); |
5c072d2b NL |
33 | |
34 | // Test if quickstart is disabled when user has 1 entry | |
35 | $crawler = $client->request('GET', '/new'); | |
36 | ||
37 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
38 | ||
0d42217e | 39 | $form = $crawler->filter('form[name=entry]')->form(); |
5c072d2b | 40 | |
4094ea47 | 41 | $data = [ |
78833672 | 42 | 'entry[url]' => $this->url, |
4094ea47 | 43 | ]; |
5c072d2b NL |
44 | |
45 | $client->submit($form, $data); | |
46 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
47 | $client->followRedirect(); | |
48 | ||
4f9cf232 | 49 | $crawler = $client->request('GET', '/unread/list'); |
4094ea47 | 50 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
4f9cf232 | 51 | $this->assertContains('entry.list.number_on_the_page', $body[0]); |
5c072d2b NL |
52 | } |
53 | ||
9c0c8820 | 54 | public function testGetNew() |
93fd4692 | 55 | { |
eb3bd7ef | 56 | $this->logInAs('admin'); |
3b815d2d | 57 | $client = $this->getClient(); |
93fd4692 | 58 | |
aa6e27cf | 59 | $crawler = $client->request('GET', '/new'); |
93fd4692 NL |
60 | |
61 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
9c0c8820 J |
62 | |
63 | $this->assertCount(1, $crawler->filter('input[type=url]')); | |
0d42217e | 64 | $this->assertCount(1, $crawler->filter('form[name=entry]')); |
9c0c8820 J |
65 | } |
66 | ||
880a0e1c NL |
67 | public function testPostNewViaBookmarklet() |
68 | { | |
69 | $this->logInAs('admin'); | |
70 | $client = $this->getClient(); | |
71 | ||
72 | $crawler = $client->request('GET', '/'); | |
73 | ||
74 | $this->assertCount(4, $crawler->filter('div[class=entry]')); | |
75 | ||
76 | // Good URL | |
4094ea47 | 77 | $client->request('GET', '/bookmarklet', ['url' => $this->url]); |
880a0e1c | 78 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
5c072d2b | 79 | $client->followRedirect(); |
880a0e1c NL |
80 | $crawler = $client->request('GET', '/'); |
81 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
82 | ||
83 | $em = $client->getContainer() | |
84 | ->get('doctrine.orm.entity_manager'); | |
85 | $entry = $em | |
86 | ->getRepository('WallabagCoreBundle:Entry') | |
78833672 | 87 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); |
880a0e1c NL |
88 | $em->remove($entry); |
89 | $em->flush(); | |
90 | } | |
91 | ||
9c0c8820 J |
92 | public function testPostNewEmpty() |
93 | { | |
eb3bd7ef | 94 | $this->logInAs('admin'); |
3b815d2d | 95 | $client = $this->getClient(); |
9c0c8820 J |
96 | |
97 | $crawler = $client->request('GET', '/new'); | |
98 | ||
99 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
100 | ||
0d42217e | 101 | $form = $crawler->filter('form[name=entry]')->form(); |
9c0c8820 J |
102 | |
103 | $crawler = $client->submit($form); | |
104 | ||
105 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
4094ea47 | 106 | $this->assertCount(1, $alert = $crawler->filter('form ul li')->extract(['_text'])); |
9c0c8820 J |
107 | $this->assertEquals('This value should not be blank.', $alert[0]); |
108 | } | |
109 | ||
8a493541 | 110 | /** |
75c48e3a | 111 | * This test will require an internet connection. |
8a493541 | 112 | */ |
9c0c8820 J |
113 | public function testPostNewOk() |
114 | { | |
eb3bd7ef | 115 | $this->logInAs('admin'); |
3b815d2d | 116 | $client = $this->getClient(); |
9c0c8820 J |
117 | |
118 | $crawler = $client->request('GET', '/new'); | |
119 | ||
120 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
121 | ||
0d42217e | 122 | $form = $crawler->filter('form[name=entry]')->form(); |
9c0c8820 | 123 | |
4094ea47 | 124 | $data = [ |
02d17813 | 125 | 'entry[url]' => $this->url, |
4094ea47 | 126 | ]; |
9c0c8820 J |
127 | |
128 | $client->submit($form, $data); | |
129 | ||
130 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
131 | ||
a0d6ccc5 JB |
132 | $content = $client->getContainer() |
133 | ->get('doctrine.orm.entity_manager') | |
134 | ->getRepository('WallabagCoreBundle:Entry') | |
135 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | |
136 | ||
137 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); | |
138 | $this->assertEquals($this->url, $content->getUrl()); | |
139 | $this->assertContains('Google', $content->getTitle()); | |
140 | } | |
9c0c8820 | 141 | |
a0d6ccc5 JB |
142 | public function testPostNewOkUrlExist() |
143 | { | |
144 | $this->logInAs('admin'); | |
145 | $client = $this->getClient(); | |
146 | ||
147 | $crawler = $client->request('GET', '/new'); | |
148 | ||
149 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
150 | ||
0d42217e | 151 | $form = $crawler->filter('form[name=entry]')->form(); |
a0d6ccc5 | 152 | |
4094ea47 | 153 | $data = [ |
a0d6ccc5 | 154 | 'entry[url]' => $this->url, |
4094ea47 | 155 | ]; |
19ca0b2f JB |
156 | |
157 | $client->submit($form, $data); | |
158 | ||
159 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
160 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); | |
161 | } | |
162 | ||
163 | public function testPostNewOkUrlExistWithAccent() | |
164 | { | |
165 | $this->logInAs('admin'); | |
166 | $client = $this->getClient(); | |
167 | ||
168 | $url = 'http://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing'; | |
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 | $crawler = $client->request('GET', '/new'); | |
183 | ||
184 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
185 | ||
186 | $form = $crawler->filter('form[name=entry]')->form(); | |
187 | ||
188 | $data = [ | |
189 | 'entry[url]' => $url, | |
190 | ]; | |
a0d6ccc5 JB |
191 | |
192 | $client->submit($form, $data); | |
193 | ||
194 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
195 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); | |
9c0c8820 J |
196 | } |
197 | ||
958671a7 KG |
198 | /** |
199 | * This test will require an internet connection. | |
200 | */ | |
3be04745 | 201 | public function testPostNewThatWillBeTagged() |
958671a7 KG |
202 | { |
203 | $this->logInAs('admin'); | |
204 | $client = $this->getClient(); | |
205 | ||
206 | $crawler = $client->request('GET', '/new'); | |
207 | ||
208 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
209 | ||
0d42217e | 210 | $form = $crawler->filter('form[name=entry]')->form(); |
958671a7 | 211 | |
4094ea47 | 212 | $data = [ |
958671a7 | 213 | 'entry[url]' => $url = 'https://github.com/wallabag/wallabag', |
4094ea47 | 214 | ]; |
958671a7 KG |
215 | |
216 | $client->submit($form, $data); | |
217 | ||
218 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
3be04745 | 219 | $this->assertContains('/', $client->getResponse()->getTargetUrl()); |
958671a7 KG |
220 | |
221 | $em = $client->getContainer() | |
222 | ->get('doctrine.orm.entity_manager'); | |
223 | $entry = $em | |
224 | ->getRepository('WallabagCoreBundle:Entry') | |
225 | ->findOneByUrl($url); | |
69edb774 KG |
226 | $tags = $entry->getTags(); |
227 | ||
228 | $this->assertCount(1, $tags); | |
229 | $this->assertEquals('wallabag', $tags[0]->getLabel()); | |
958671a7 KG |
230 | |
231 | $em->remove($entry); | |
232 | $em->flush(); | |
3be04745 JB |
233 | |
234 | // and now re-submit it to test the cascade persistence for tags after entry removal | |
235 | // related https://github.com/wallabag/wallabag/issues/2121 | |
236 | $crawler = $client->request('GET', '/new'); | |
237 | ||
238 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
239 | ||
240 | $form = $crawler->filter('form[name=entry]')->form(); | |
241 | ||
242 | $data = [ | |
243 | 'entry[url]' => $url = 'https://github.com/wallabag/wallabag/tree/master', | |
244 | ]; | |
245 | ||
246 | $client->submit($form, $data); | |
247 | ||
248 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
249 | $this->assertContains('/', $client->getResponse()->getTargetUrl()); | |
250 | ||
251 | $entry = $em | |
252 | ->getRepository('WallabagCoreBundle:Entry') | |
253 | ->findOneByUrl($url); | |
254 | ||
255 | $tags = $entry->getTags(); | |
256 | ||
257 | $this->assertCount(1, $tags); | |
258 | $this->assertEquals('wallabag', $tags[0]->getLabel()); | |
259 | ||
260 | $em->remove($entry); | |
261 | $em->flush(); | |
958671a7 KG |
262 | } |
263 | ||
9c0c8820 J |
264 | public function testArchive() |
265 | { | |
eb3bd7ef | 266 | $this->logInAs('admin'); |
3b815d2d | 267 | $client = $this->getClient(); |
9c0c8820 | 268 | |
9fb6ac83 | 269 | $client->request('GET', '/archive/list'); |
9c0c8820 J |
270 | |
271 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
272 | } | |
273 | ||
d5d16121 NL |
274 | public function testUntagged() |
275 | { | |
276 | $this->logInAs('admin'); | |
277 | $client = $this->getClient(); | |
278 | ||
279 | $client->request('GET', '/untagged/list'); | |
280 | ||
281 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
282 | } | |
283 | ||
9c0c8820 J |
284 | public function testStarred() |
285 | { | |
eb3bd7ef | 286 | $this->logInAs('admin'); |
3b815d2d | 287 | $client = $this->getClient(); |
9c0c8820 | 288 | |
9fb6ac83 | 289 | $client->request('GET', '/starred/list'); |
9c0c8820 J |
290 | |
291 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
292 | } | |
293 | ||
671a2b88 ML |
294 | public function testRangeException() |
295 | { | |
296 | $this->logInAs('admin'); | |
297 | $client = $this->getClient(); | |
298 | ||
299 | $client->request('GET', '/all/list/900'); | |
300 | ||
1880da74 NL |
301 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
302 | $this->assertEquals('/all/list', $client->getResponse()->getTargetUrl()); | |
671a2b88 ML |
303 | } |
304 | ||
8a493541 JB |
305 | /** |
306 | * @depends testPostNewOk | |
307 | */ | |
9c0c8820 J |
308 | public function testView() |
309 | { | |
eb3bd7ef | 310 | $this->logInAs('admin'); |
3b815d2d | 311 | $client = $this->getClient(); |
9c0c8820 J |
312 | |
313 | $content = $client->getContainer() | |
314 | ->get('doctrine.orm.entity_manager') | |
315 | ->getRepository('WallabagCoreBundle:Entry') | |
78833672 | 316 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); |
9c0c8820 | 317 | |
4f9cf232 | 318 | $crawler = $client->request('GET', '/view/'.$content->getId()); |
9c0c8820 J |
319 | |
320 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
4094ea47 | 321 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
4f9cf232 | 322 | $this->assertContains($content->getTitle(), $body[0]); |
93fd4692 | 323 | } |
eb3bd7ef | 324 | |
831b02aa JB |
325 | /** |
326 | * @depends testPostNewOk | |
327 | * | |
328 | * This test will require an internet connection. | |
329 | */ | |
330 | public function testReload() | |
331 | { | |
332 | $this->logInAs('admin'); | |
333 | $client = $this->getClient(); | |
334 | ||
335 | $content = $client->getContainer() | |
336 | ->get('doctrine.orm.entity_manager') | |
337 | ->getRepository('WallabagCoreBundle:Entry') | |
78833672 | 338 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); |
831b02aa JB |
339 | |
340 | // empty content | |
341 | $content->setContent(''); | |
342 | $client->getContainer()->get('doctrine.orm.entity_manager')->persist($content); | |
343 | $client->getContainer()->get('doctrine.orm.entity_manager')->flush(); | |
344 | ||
345 | $client->request('GET', '/reload/'.$content->getId()); | |
346 | ||
347 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
348 | ||
349 | $content = $client->getContainer() | |
350 | ->get('doctrine.orm.entity_manager') | |
351 | ->getRepository('WallabagCoreBundle:Entry') | |
78833672 | 352 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); |
831b02aa JB |
353 | |
354 | $this->assertNotEmpty($content->getContent()); | |
355 | } | |
356 | ||
82d6d9cb JB |
357 | public function testEdit() |
358 | { | |
359 | $this->logInAs('admin'); | |
360 | $client = $this->getClient(); | |
361 | ||
362 | $content = $client->getContainer() | |
363 | ->get('doctrine.orm.entity_manager') | |
364 | ->getRepository('WallabagCoreBundle:Entry') | |
78833672 | 365 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); |
82d6d9cb JB |
366 | |
367 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | |
368 | ||
369 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
370 | ||
371 | $this->assertCount(1, $crawler->filter('input[id=entry_title]')); | |
372 | $this->assertCount(1, $crawler->filter('button[id=entry_save]')); | |
373 | } | |
374 | ||
375 | public function testEditUpdate() | |
376 | { | |
377 | $this->logInAs('admin'); | |
378 | $client = $this->getClient(); | |
379 | ||
380 | $content = $client->getContainer() | |
381 | ->get('doctrine.orm.entity_manager') | |
382 | ->getRepository('WallabagCoreBundle:Entry') | |
78833672 | 383 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); |
82d6d9cb JB |
384 | |
385 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | |
386 | ||
387 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
388 | ||
389 | $form = $crawler->filter('button[type=submit]')->form(); | |
390 | ||
4094ea47 | 391 | $data = [ |
82d6d9cb | 392 | 'entry[title]' => 'My updated title hehe :)', |
4094ea47 | 393 | ]; |
82d6d9cb JB |
394 | |
395 | $client->submit($form, $data); | |
396 | ||
397 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
398 | ||
399 | $crawler = $client->followRedirect(); | |
400 | ||
4094ea47 | 401 | $this->assertGreaterThan(1, $alert = $crawler->filter('div[id=article] h1')->extract(['_text'])); |
82d6d9cb JB |
402 | $this->assertContains('My updated title hehe :)', $alert[0]); |
403 | } | |
404 | ||
eb3bd7ef J |
405 | public function testToggleArchive() |
406 | { | |
407 | $this->logInAs('admin'); | |
408 | $client = $this->getClient(); | |
409 | ||
410 | $content = $client->getContainer() | |
411 | ->get('doctrine.orm.entity_manager') | |
412 | ->getRepository('WallabagCoreBundle:Entry') | |
78833672 | 413 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); |
eb3bd7ef J |
414 | |
415 | $client->request('GET', '/archive/'.$content->getId()); | |
416 | ||
417 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
418 | ||
419 | $res = $client->getContainer() | |
420 | ->get('doctrine.orm.entity_manager') | |
421 | ->getRepository('WallabagCoreBundle:Entry') | |
159986c4 | 422 | ->find($content->getId()); |
eb3bd7ef J |
423 | |
424 | $this->assertEquals($res->isArchived(), true); | |
425 | } | |
426 | ||
427 | public function testToggleStar() | |
428 | { | |
429 | $this->logInAs('admin'); | |
430 | $client = $this->getClient(); | |
431 | ||
432 | $content = $client->getContainer() | |
433 | ->get('doctrine.orm.entity_manager') | |
434 | ->getRepository('WallabagCoreBundle:Entry') | |
78833672 | 435 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); |
eb3bd7ef J |
436 | |
437 | $client->request('GET', '/star/'.$content->getId()); | |
438 | ||
439 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
440 | ||
441 | $res = $client->getContainer() | |
442 | ->get('doctrine.orm.entity_manager') | |
443 | ->getRepository('WallabagCoreBundle:Entry') | |
444 | ->findOneById($content->getId()); | |
445 | ||
446 | $this->assertEquals($res->isStarred(), true); | |
447 | } | |
448 | ||
449 | public function testDelete() | |
450 | { | |
451 | $this->logInAs('admin'); | |
452 | $client = $this->getClient(); | |
453 | ||
454 | $content = $client->getContainer() | |
455 | ->get('doctrine.orm.entity_manager') | |
456 | ->getRepository('WallabagCoreBundle:Entry') | |
78833672 | 457 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); |
eb3bd7ef J |
458 | |
459 | $client->request('GET', '/delete/'.$content->getId()); | |
460 | ||
461 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
462 | ||
1d147791 | 463 | $client->request('GET', '/delete/'.$content->getId()); |
eb3bd7ef | 464 | |
1d147791 | 465 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); |
eb3bd7ef | 466 | } |
3d2b2d62 | 467 | |
2863bf2a JB |
468 | /** |
469 | * It will create a new entry. | |
470 | * Browse to it. | |
471 | * Then remove it. | |
472 | * | |
473 | * And it'll check that user won't be redirected to the view page of the content when it had been removed | |
474 | */ | |
475 | public function testViewAndDelete() | |
476 | { | |
477 | $this->logInAs('admin'); | |
478 | $client = $this->getClient(); | |
479 | ||
480 | // add a new content to be removed later | |
481 | $user = $client->getContainer() | |
482 | ->get('doctrine.orm.entity_manager') | |
483 | ->getRepository('WallabagUserBundle:User') | |
484 | ->findOneByUserName('admin'); | |
485 | ||
486 | $content = new Entry($user); | |
487 | $content->setUrl('http://1.1.1.1/entry'); | |
488 | $content->setReadingTime(12); | |
489 | $content->setDomainName('domain.io'); | |
490 | $content->setMimetype('text/html'); | |
491 | $content->setTitle('test title entry'); | |
492 | $content->setContent('This is my content /o/'); | |
493 | $content->setArchived(true); | |
494 | $content->setLanguage('fr'); | |
495 | ||
496 | $client->getContainer() | |
497 | ->get('doctrine.orm.entity_manager') | |
498 | ->persist($content); | |
499 | $client->getContainer() | |
500 | ->get('doctrine.orm.entity_manager') | |
501 | ->flush(); | |
502 | ||
503 | $client->request('GET', '/view/'.$content->getId()); | |
504 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
505 | ||
506 | $client->request('GET', '/delete/'.$content->getId()); | |
507 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
508 | ||
509 | $client->followRedirect(); | |
510 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
511 | } | |
512 | ||
3d2b2d62 J |
513 | public function testViewOtherUserEntry() |
514 | { | |
159986c4 | 515 | $this->logInAs('admin'); |
3d2b2d62 J |
516 | $client = $this->getClient(); |
517 | ||
518 | $content = $client->getContainer() | |
519 | ->get('doctrine.orm.entity_manager') | |
520 | ->getRepository('WallabagCoreBundle:Entry') | |
159986c4 | 521 | ->findOneByUsernameAndNotArchived('bob'); |
3d2b2d62 | 522 | |
159986c4 | 523 | $client->request('GET', '/view/'.$content->getId()); |
3d2b2d62 J |
524 | |
525 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | |
526 | } | |
26864574 | 527 | |
3f357ee2 | 528 | public function testFilterOnReadingTime() |
26864574 NL |
529 | { |
530 | $this->logInAs('admin'); | |
531 | $client = $this->getClient(); | |
532 | ||
533 | $crawler = $client->request('GET', '/unread/list'); | |
534 | ||
535 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
536 | ||
4094ea47 | 537 | $data = [ |
d6a9e139 NL |
538 | 'entry_filter[readingTime][right_number]' => 22, |
539 | 'entry_filter[readingTime][left_number]' => 22, | |
4094ea47 | 540 | ]; |
26864574 NL |
541 | |
542 | $crawler = $client->submit($form, $data); | |
543 | ||
544 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
545 | } | |
ab2c93c7 | 546 | |
95859e54 JB |
547 | public function testFilterOnReadingTimeOnlyUpper() |
548 | { | |
549 | $this->logInAs('admin'); | |
550 | $client = $this->getClient(); | |
551 | ||
552 | $crawler = $client->request('GET', '/unread/list'); | |
553 | ||
554 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
555 | ||
556 | $data = [ | |
557 | 'entry_filter[readingTime][right_number]' => 22, | |
558 | ]; | |
559 | ||
560 | $crawler = $client->submit($form, $data); | |
561 | ||
562 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | |
563 | } | |
564 | ||
565 | public function testFilterOnReadingTimeOnlyLower() | |
566 | { | |
567 | $this->logInAs('admin'); | |
568 | $client = $this->getClient(); | |
569 | ||
570 | $crawler = $client->request('GET', '/unread/list'); | |
571 | ||
572 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
573 | ||
574 | $data = [ | |
575 | 'entry_filter[readingTime][left_number]' => 22, | |
576 | ]; | |
577 | ||
578 | $crawler = $client->submit($form, $data); | |
579 | ||
580 | $this->assertCount(4, $crawler->filter('div[class=entry]')); | |
581 | } | |
582 | ||
30334567 DB |
583 | public function testFilterOnUnreadStatus() |
584 | { | |
585 | $this->logInAs('admin'); | |
586 | $client = $this->getClient(); | |
587 | ||
588 | $crawler = $client->request('GET', '/all/list'); | |
589 | ||
590 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
591 | ||
592 | $data = [ | |
593 | 'entry_filter[isUnread]' => true, | |
594 | ]; | |
595 | ||
596 | $crawler = $client->submit($form, $data); | |
597 | ||
598 | $this->assertCount(4, $crawler->filter('div[class=entry]')); | |
599 | } | |
600 | ||
3f357ee2 NL |
601 | public function testFilterOnCreationDate() |
602 | { | |
603 | $this->logInAs('admin'); | |
604 | $client = $this->getClient(); | |
605 | ||
606 | $crawler = $client->request('GET', '/unread/list'); | |
607 | ||
608 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
609 | ||
4094ea47 | 610 | $data = [ |
3f357ee2 | 611 | 'entry_filter[createdAt][left_date]' => date('d/m/Y'), |
8ce32af6 | 612 | 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')), |
4094ea47 | 613 | ]; |
3f357ee2 NL |
614 | |
615 | $crawler = $client->submit($form, $data); | |
616 | ||
e1779760 | 617 | $this->assertCount(5, $crawler->filter('div[class=entry]')); |
3f357ee2 | 618 | |
4094ea47 | 619 | $data = [ |
f90af145 JB |
620 | 'entry_filter[createdAt][left_date]' => date('d/m/Y'), |
621 | 'entry_filter[createdAt][right_date]' => date('d/m/Y'), | |
4094ea47 | 622 | ]; |
f90af145 JB |
623 | |
624 | $crawler = $client->submit($form, $data); | |
625 | ||
626 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
627 | ||
4094ea47 | 628 | $data = [ |
3f357ee2 | 629 | 'entry_filter[createdAt][left_date]' => '01/01/1970', |
8ce32af6 | 630 | 'entry_filter[createdAt][right_date]' => '01/01/1970', |
4094ea47 | 631 | ]; |
3f357ee2 NL |
632 | |
633 | $crawler = $client->submit($form, $data); | |
634 | ||
635 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
3f357ee2 NL |
636 | } |
637 | ||
ab2c93c7 NL |
638 | public function testPaginationWithFilter() |
639 | { | |
640 | $this->logInAs('admin'); | |
641 | $client = $this->getClient(); | |
ab2c93c7 NL |
642 | $crawler = $client->request('GET', '/config'); |
643 | ||
644 | $form = $crawler->filter('button[id=config_save]')->form(); | |
645 | ||
4094ea47 | 646 | $data = [ |
ab2c93c7 | 647 | 'config[items_per_page]' => '1', |
4094ea47 | 648 | ]; |
ab2c93c7 NL |
649 | |
650 | $client->submit($form, $data); | |
651 | ||
76cd8dbb | 652 | $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D='; |
ab2c93c7 | 653 | |
5c072d2b | 654 | $client->request('GET', 'unread/list'.$parameters); |
ab2c93c7 NL |
655 | |
656 | $this->assertContains($parameters, $client->getResponse()->getContent()); | |
e1779760 NL |
657 | |
658 | // reset pagination | |
659 | $crawler = $client->request('GET', '/config'); | |
660 | $form = $crawler->filter('button[id=config_save]')->form(); | |
4094ea47 | 661 | $data = [ |
e1779760 | 662 | 'config[items_per_page]' => '12', |
4094ea47 | 663 | ]; |
e1779760 | 664 | $client->submit($form, $data); |
ab2c93c7 | 665 | } |
443cecd2 NL |
666 | |
667 | public function testFilterOnDomainName() | |
668 | { | |
669 | $this->logInAs('admin'); | |
670 | $client = $this->getClient(); | |
671 | ||
672 | $crawler = $client->request('GET', '/unread/list'); | |
673 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
4094ea47 | 674 | $data = [ |
02d17813 | 675 | 'entry_filter[domainName]' => 'domain', |
4094ea47 | 676 | ]; |
443cecd2 NL |
677 | |
678 | $crawler = $client->submit($form, $data); | |
02d17813 | 679 | $this->assertCount(5, $crawler->filter('div[class=entry]')); |
443cecd2 NL |
680 | |
681 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
4094ea47 | 682 | $data = [ |
8ce32af6 | 683 | 'entry_filter[domainName]' => 'wallabag', |
4094ea47 | 684 | ]; |
443cecd2 NL |
685 | |
686 | $crawler = $client->submit($form, $data); | |
687 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
688 | } | |
e1779760 NL |
689 | |
690 | public function testFilterOnStatus() | |
691 | { | |
692 | $this->logInAs('admin'); | |
693 | $client = $this->getClient(); | |
694 | ||
695 | $crawler = $client->request('GET', '/unread/list'); | |
696 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
697 | $form['entry_filter[isArchived]']->tick(); | |
698 | $form['entry_filter[isStarred]']->untick(); | |
699 | ||
700 | $crawler = $client->submit($form); | |
159986c4 | 701 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
e1779760 NL |
702 | |
703 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
704 | $form['entry_filter[isArchived]']->untick(); | |
705 | $form['entry_filter[isStarred]']->tick(); | |
706 | ||
707 | $crawler = $client->submit($form); | |
02d17813 | 708 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
e1779760 | 709 | } |
497e0cad NL |
710 | |
711 | public function testPreviewPictureFilter() | |
712 | { | |
713 | $this->logInAs('admin'); | |
714 | $client = $this->getClient(); | |
715 | ||
716 | $crawler = $client->request('GET', '/unread/list'); | |
717 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
718 | $form['entry_filter[previewPicture]']->tick(); | |
719 | ||
720 | $crawler = $client->submit($form); | |
721 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
722 | } | |
d4ebe5c5 JB |
723 | |
724 | public function testFilterOnLanguage() | |
725 | { | |
726 | $this->logInAs('admin'); | |
727 | $client = $this->getClient(); | |
728 | ||
729 | $crawler = $client->request('GET', '/unread/list'); | |
730 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
4094ea47 | 731 | $data = [ |
159986c4 | 732 | 'entry_filter[language]' => 'fr', |
4094ea47 | 733 | ]; |
d4ebe5c5 JB |
734 | |
735 | $crawler = $client->submit($form, $data); | |
02d17813 | 736 | $this->assertCount(2, $crawler->filter('div[class=entry]')); |
d4ebe5c5 JB |
737 | |
738 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
4094ea47 | 739 | $data = [ |
d4ebe5c5 | 740 | 'entry_filter[language]' => 'en', |
4094ea47 | 741 | ]; |
d4ebe5c5 JB |
742 | |
743 | $crawler = $client->submit($form, $data); | |
744 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | |
745 | } | |
a7e2218e NL |
746 | |
747 | public function testCache() | |
748 | { | |
749 | $this->logInAs('admin'); | |
750 | $client = $this->getClient(); | |
751 | ||
752 | $content = $client->getContainer() | |
753 | ->get('doctrine.orm.entity_manager') | |
754 | ->getRepository('WallabagCoreBundle:Entry') | |
755 | ->findOneByUser($this->getLoggedInUserId()); | |
756 | ||
eddda878 | 757 | // no uuid |
a7e2218e | 758 | $client->request('GET', '/share/'.$content->getUuid()); |
eddda878 JB |
759 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); |
760 | ||
761 | // generating the uuid | |
762 | $client->request('GET', '/share/'.$content->getId()); | |
763 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
764 | ||
765 | // follow link with uuid | |
766 | $crawler = $client->followRedirect(); | |
767 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
768 | $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control')); | |
769 | $this->assertContains('public', $client->getResponse()->headers->get('cache-control')); | |
770 | $this->assertContains('s-maxage=25200', $client->getResponse()->headers->get('cache-control')); | |
a7e2218e NL |
771 | $this->assertNotContains('no-cache', $client->getResponse()->headers->get('cache-control')); |
772 | ||
eddda878 JB |
773 | // sharing is now disabled |
774 | $client->getContainer()->get('craue_config')->set('share_public', 0); | |
775 | $client->request('GET', '/share/'.$content->getUuid()); | |
776 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | |
777 | ||
a7e2218e NL |
778 | $client->request('GET', '/view/'.$content->getId()); |
779 | $this->assertContains('no-cache', $client->getResponse()->headers->get('cache-control')); | |
eddda878 JB |
780 | |
781 | // removing the share | |
782 | $client->request('GET', '/share/delete/'.$content->getId()); | |
783 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
784 | ||
785 | // share is now disable | |
786 | $client->request('GET', '/share/'.$content->getUuid()); | |
787 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | |
a7e2218e | 788 | } |
93fd4692 | 789 | } |