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