diff options
Diffstat (limited to 'tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php')
-rw-r--r-- | tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | 515 |
1 files changed, 349 insertions, 166 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 7db4cf1f..8f5c372d 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | |||
@@ -8,8 +8,24 @@ use Wallabag\CoreBundle\Entity\Entry; | |||
8 | 8 | ||
9 | class EntryControllerTest extends WallabagCoreTestCase | 9 | class EntryControllerTest extends WallabagCoreTestCase |
10 | { | 10 | { |
11 | public $downloadImagesEnabled = false; | ||
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 | 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 | 13 | ||
14 | /** | ||
15 | * @after | ||
16 | * | ||
17 | * Ensure download_images_enabled is disabled after each script | ||
18 | */ | ||
19 | public function tearDownImagesEnabled() | ||
20 | { | ||
21 | if ($this->downloadImagesEnabled) { | ||
22 | $client = static::createClient(); | ||
23 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); | ||
24 | |||
25 | $this->downloadImagesEnabled = false; | ||
26 | } | ||
27 | } | ||
28 | |||
13 | public function testLogin() | 29 | public function testLogin() |
14 | { | 30 | { |
15 | $client = $this->getClient(); | 31 | $client = $this->getClient(); |
@@ -55,6 +71,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
55 | public function testGetNew() | 71 | public function testGetNew() |
56 | { | 72 | { |
57 | $this->logInAs('admin'); | 73 | $this->logInAs('admin'); |
74 | $this->useTheme('baggy'); | ||
58 | $client = $this->getClient(); | 75 | $client = $this->getClient(); |
59 | 76 | ||
60 | $crawler = $client->request('GET', '/new'); | 77 | $crawler = $client->request('GET', '/new'); |
@@ -68,6 +85,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
68 | public function testPostNewViaBookmarklet() | 85 | public function testPostNewViaBookmarklet() |
69 | { | 86 | { |
70 | $this->logInAs('admin'); | 87 | $this->logInAs('admin'); |
88 | $this->useTheme('baggy'); | ||
71 | $client = $this->getClient(); | 89 | $client = $this->getClient(); |
72 | 90 | ||
73 | $crawler = $client->request('GET', '/'); | 91 | $crawler = $client->request('GET', '/'); |
@@ -135,14 +153,58 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
135 | ->getRepository('WallabagCoreBundle:Entry') | 153 | ->getRepository('WallabagCoreBundle:Entry') |
136 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 154 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); |
137 | 155 | ||
156 | $author = $content->getPublishedBy(); | ||
157 | |||
138 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); | 158 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); |
139 | $this->assertEquals($this->url, $content->getUrl()); | 159 | $this->assertEquals($this->url, $content->getUrl()); |
140 | $this->assertContains('Google', $content->getTitle()); | 160 | $this->assertContains('Google', $content->getTitle()); |
161 | $this->assertEquals('fr', $content->getLanguage()); | ||
162 | $this->assertEquals('2015-03-28 15:37:39', $content->getPublishedAt()->format('Y-m-d H:i:s')); | ||
163 | $this->assertEquals('Morgane Tual', $author[0]); | ||
164 | $this->assertArrayHasKey('x-varnish1', $content->getHeaders()); | ||
165 | } | ||
166 | |||
167 | public function testPostWithMultipleAuthors() | ||
168 | { | ||
169 | $url = 'http://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768'; | ||
170 | $this->logInAs('admin'); | ||
171 | $client = $this->getClient(); | ||
172 | |||
173 | $crawler = $client->request('GET', '/new'); | ||
174 | |||
175 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
176 | |||
177 | $form = $crawler->filter('form[name=entry]')->form(); | ||
178 | |||
179 | $data = [ | ||
180 | 'entry[url]' => $url, | ||
181 | ]; | ||
182 | |||
183 | $client->submit($form, $data); | ||
184 | |||
185 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
186 | |||
187 | $content = $client->getContainer() | ||
188 | ->get('doctrine.orm.entity_manager') | ||
189 | ->getRepository('WallabagCoreBundle:Entry') | ||
190 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | ||
191 | |||
192 | $authors = $content->getPublishedBy(); | ||
193 | $this->assertEquals('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s')); | ||
194 | $this->assertEquals('fr', $content->getLanguage()); | ||
195 | $this->assertEquals('Raphaël Balenieri, correspondant à Pékin', $authors[0]); | ||
196 | $this->assertEquals('Frédéric Autran, correspondant à New York', $authors[1]); | ||
141 | } | 197 | } |
142 | 198 | ||
143 | public function testPostNewOkUrlExist() | 199 | public function testPostNewOkUrlExist() |
144 | { | 200 | { |
145 | $this->logInAs('admin'); | 201 | $this->logInAs('admin'); |
202 | |||
203 | $entry = new Entry($this->getLoggedInUser()); | ||
204 | $entry->setUrl($this->url); | ||
205 | $this->getEntityManager()->persist($entry); | ||
206 | $this->getEntityManager()->flush(); | ||
207 | |||
146 | $client = $this->getClient(); | 208 | $client = $this->getClient(); |
147 | 209 | ||
148 | $crawler = $client->request('GET', '/new'); | 210 | $crawler = $client->request('GET', '/new'); |
@@ -194,15 +256,6 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
194 | 256 | ||
195 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 257 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
196 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); | 258 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); |
197 | |||
198 | $em = $client->getContainer() | ||
199 | ->get('doctrine.orm.entity_manager'); | ||
200 | $entry = $em | ||
201 | ->getRepository('WallabagCoreBundle:Entry') | ||
202 | ->findOneByUrl(urldecode($url)); | ||
203 | |||
204 | $em->remove($entry); | ||
205 | $em->flush(); | ||
206 | } | 259 | } |
207 | 260 | ||
208 | /** | 261 | /** |
@@ -235,8 +288,9 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
235 | ->findOneByUrl($url); | 288 | ->findOneByUrl($url); |
236 | $tags = $entry->getTags(); | 289 | $tags = $entry->getTags(); |
237 | 290 | ||
238 | $this->assertCount(1, $tags); | 291 | $this->assertCount(2, $tags); |
239 | $this->assertEquals('wallabag', $tags[0]->getLabel()); | 292 | $this->assertContains('wallabag', $tags); |
293 | $this->assertEquals('en', $entry->getLanguage()); | ||
240 | 294 | ||
241 | $em->remove($entry); | 295 | $em->remove($entry); |
242 | $em->flush(); | 296 | $em->flush(); |
@@ -264,8 +318,8 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
264 | 318 | ||
265 | $tags = $entry->getTags(); | 319 | $tags = $entry->getTags(); |
266 | 320 | ||
267 | $this->assertCount(1, $tags); | 321 | $this->assertCount(2, $tags); |
268 | $this->assertEquals('wallabag', $tags[0]->getLabel()); | 322 | $this->assertContains('wallabag', $tags); |
269 | 323 | ||
270 | $em->remove($entry); | 324 | $em->remove($entry); |
271 | $em->flush(); | 325 | $em->flush(); |
@@ -312,29 +366,26 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
312 | $this->assertEquals('/all/list', $client->getResponse()->getTargetUrl()); | 366 | $this->assertEquals('/all/list', $client->getResponse()->getTargetUrl()); |
313 | } | 367 | } |
314 | 368 | ||
315 | /** | ||
316 | * @depends testPostNewOk | ||
317 | */ | ||
318 | public function testView() | 369 | public function testView() |
319 | { | 370 | { |
320 | $this->logInAs('admin'); | 371 | $this->logInAs('admin'); |
321 | $client = $this->getClient(); | 372 | $client = $this->getClient(); |
322 | 373 | ||
323 | $content = $client->getContainer() | 374 | $entry = new Entry($this->getLoggedInUser()); |
324 | ->get('doctrine.orm.entity_manager') | 375 | $entry->setUrl('http://example.com/foo'); |
325 | ->getRepository('WallabagCoreBundle:Entry') | 376 | $entry->setTitle('title foo'); |
326 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 377 | $entry->setContent('foo bar baz'); |
378 | $this->getEntityManager()->persist($entry); | ||
379 | $this->getEntityManager()->flush(); | ||
327 | 380 | ||
328 | $crawler = $client->request('GET', '/view/'.$content->getId()); | 381 | $crawler = $client->request('GET', '/view/'.$entry->getId()); |
329 | 382 | ||
330 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 383 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
331 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | 384 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
332 | $this->assertContains($content->getTitle(), $body[0]); | 385 | $this->assertContains($entry->getTitle(), $body[0]); |
333 | } | 386 | } |
334 | 387 | ||
335 | /** | 388 | /** |
336 | * @depends testPostNewOk | ||
337 | * | ||
338 | * This test will require an internet connection. | 389 | * This test will require an internet connection. |
339 | */ | 390 | */ |
340 | public function testReload() | 391 | public function testReload() |
@@ -342,63 +393,45 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
342 | $this->logInAs('admin'); | 393 | $this->logInAs('admin'); |
343 | $client = $this->getClient(); | 394 | $client = $this->getClient(); |
344 | 395 | ||
345 | $em = $client->getContainer() | 396 | $entry = new Entry($this->getLoggedInUser()); |
346 | ->get('doctrine.orm.entity_manager'); | 397 | $entry->setUrl($this->url); |
398 | $entry->setTitle('title foo'); | ||
399 | $entry->setContent(''); | ||
400 | $this->getEntityManager()->persist($entry); | ||
401 | $this->getEntityManager()->flush(); | ||
402 | $this->getEntityManager()->clear(); | ||
347 | 403 | ||
348 | $content = $em | 404 | $client->request('GET', '/reload/'.$entry->getId()); |
349 | ->getRepository('WallabagCoreBundle:Entry') | ||
350 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | ||
351 | |||
352 | // empty content | ||
353 | $content->setContent(''); | ||
354 | $em->persist($content); | ||
355 | $em->flush(); | ||
356 | |||
357 | $client->request('GET', '/reload/'.$content->getId()); | ||
358 | 405 | ||
359 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 406 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
360 | 407 | ||
361 | $content = $em | 408 | $entry = $this->getEntityManager() |
362 | ->getRepository('WallabagCoreBundle:Entry') | 409 | ->getRepository('WallabagCoreBundle:Entry') |
363 | ->find($content->getId()); | 410 | ->find($entry->getId()); |
364 | 411 | ||
365 | $this->assertNotEmpty($content->getContent()); | 412 | $this->assertNotEmpty($entry->getContent()); |
366 | } | 413 | } |
367 | 414 | ||
368 | /** | ||
369 | * @depends testPostNewOk | ||
370 | */ | ||
371 | public function testReloadWithFetchingFailed() | 415 | public function testReloadWithFetchingFailed() |
372 | { | 416 | { |
373 | $this->logInAs('admin'); | 417 | $this->logInAs('admin'); |
374 | $client = $this->getClient(); | 418 | $client = $this->getClient(); |
375 | 419 | ||
376 | $em = $client->getContainer() | 420 | $entry = new Entry($this->getLoggedInUser()); |
377 | ->get('doctrine.orm.entity_manager'); | 421 | $entry->setUrl('http://0.0.0.0/failed.html'); |
378 | 422 | $this->getEntityManager()->persist($entry); | |
379 | $content = $em | 423 | $this->getEntityManager()->flush(); |
380 | ->getRepository('WallabagCoreBundle:Entry') | ||
381 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | ||
382 | 424 | ||
383 | // put a known failed url | 425 | $client->request('GET', '/reload/'.$entry->getId()); |
384 | $content->setUrl('http://0.0.0.0/failed.html'); | ||
385 | $em->persist($content); | ||
386 | $em->flush(); | ||
387 | |||
388 | $client->request('GET', '/reload/'.$content->getId()); | ||
389 | 426 | ||
390 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 427 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
391 | 428 | ||
392 | // force EntityManager to clear previous entity | 429 | // force EntityManager to clear previous entity |
393 | // otherwise, retrieve the same entity will retrieve change from the previous request :0 | 430 | // otherwise, retrieve the same entity will retrieve change from the previous request :0 |
394 | $em->clear(); | 431 | $this->getEntityManager()->clear(); |
395 | $newContent = $em | 432 | $newContent = $this->getEntityManager() |
396 | ->getRepository('WallabagCoreBundle:Entry') | 433 | ->getRepository('WallabagCoreBundle:Entry') |
397 | ->find($content->getId()); | 434 | ->find($entry->getId()); |
398 | |||
399 | $newContent->setUrl($this->url); | ||
400 | $em->persist($newContent); | ||
401 | $em->flush(); | ||
402 | 435 | ||
403 | $this->assertNotEquals($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent()); | 436 | $this->assertNotEquals($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent()); |
404 | } | 437 | } |
@@ -408,12 +441,12 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
408 | $this->logInAs('admin'); | 441 | $this->logInAs('admin'); |
409 | $client = $this->getClient(); | 442 | $client = $this->getClient(); |
410 | 443 | ||
411 | $content = $client->getContainer() | 444 | $entry = new Entry($this->getLoggedInUser()); |
412 | ->get('doctrine.orm.entity_manager') | 445 | $entry->setUrl($this->url); |
413 | ->getRepository('WallabagCoreBundle:Entry') | 446 | $this->getEntityManager()->persist($entry); |
414 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 447 | $this->getEntityManager()->flush(); |
415 | 448 | ||
416 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | 449 | $crawler = $client->request('GET', '/edit/'.$entry->getId()); |
417 | 450 | ||
418 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 451 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
419 | 452 | ||
@@ -426,12 +459,12 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
426 | $this->logInAs('admin'); | 459 | $this->logInAs('admin'); |
427 | $client = $this->getClient(); | 460 | $client = $this->getClient(); |
428 | 461 | ||
429 | $content = $client->getContainer() | 462 | $entry = new Entry($this->getLoggedInUser()); |
430 | ->get('doctrine.orm.entity_manager') | 463 | $entry->setUrl($this->url); |
431 | ->getRepository('WallabagCoreBundle:Entry') | 464 | $this->getEntityManager()->persist($entry); |
432 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 465 | $this->getEntityManager()->flush(); |
433 | 466 | ||
434 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | 467 | $crawler = $client->request('GET', '/edit/'.$entry->getId()); |
435 | 468 | ||
436 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 469 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
437 | 470 | ||
@@ -456,19 +489,20 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
456 | $this->logInAs('admin'); | 489 | $this->logInAs('admin'); |
457 | $client = $this->getClient(); | 490 | $client = $this->getClient(); |
458 | 491 | ||
459 | $content = $client->getContainer() | 492 | $entry = new Entry($this->getLoggedInUser()); |
460 | ->get('doctrine.orm.entity_manager') | 493 | $entry->setUrl($this->url); |
461 | ->getRepository('WallabagCoreBundle:Entry') | 494 | $this->getEntityManager()->persist($entry); |
462 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 495 | $this->getEntityManager()->flush(); |
496 | $this->getEntityManager()->clear(); | ||
463 | 497 | ||
464 | $client->request('GET', '/archive/'.$content->getId()); | 498 | $client->request('GET', '/archive/'.$entry->getId()); |
465 | 499 | ||
466 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 500 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
467 | 501 | ||
468 | $res = $client->getContainer() | 502 | $res = $client->getContainer() |
469 | ->get('doctrine.orm.entity_manager') | 503 | ->get('doctrine.orm.entity_manager') |
470 | ->getRepository('WallabagCoreBundle:Entry') | 504 | ->getRepository('WallabagCoreBundle:Entry') |
471 | ->find($content->getId()); | 505 | ->find($entry->getId()); |
472 | 506 | ||
473 | $this->assertEquals($res->isArchived(), true); | 507 | $this->assertEquals($res->isArchived(), true); |
474 | } | 508 | } |
@@ -478,19 +512,20 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
478 | $this->logInAs('admin'); | 512 | $this->logInAs('admin'); |
479 | $client = $this->getClient(); | 513 | $client = $this->getClient(); |
480 | 514 | ||
481 | $content = $client->getContainer() | 515 | $entry = new Entry($this->getLoggedInUser()); |
482 | ->get('doctrine.orm.entity_manager') | 516 | $entry->setUrl($this->url); |
483 | ->getRepository('WallabagCoreBundle:Entry') | 517 | $this->getEntityManager()->persist($entry); |
484 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 518 | $this->getEntityManager()->flush(); |
519 | $this->getEntityManager()->clear(); | ||
485 | 520 | ||
486 | $client->request('GET', '/star/'.$content->getId()); | 521 | $client->request('GET', '/star/'.$entry->getId()); |
487 | 522 | ||
488 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 523 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
489 | 524 | ||
490 | $res = $client->getContainer() | 525 | $res = $client->getContainer() |
491 | ->get('doctrine.orm.entity_manager') | 526 | ->get('doctrine.orm.entity_manager') |
492 | ->getRepository('WallabagCoreBundle:Entry') | 527 | ->getRepository('WallabagCoreBundle:Entry') |
493 | ->findOneById($content->getId()); | 528 | ->findOneById($entry->getId()); |
494 | 529 | ||
495 | $this->assertEquals($res->isStarred(), true); | 530 | $this->assertEquals($res->isStarred(), true); |
496 | } | 531 | } |
@@ -500,16 +535,16 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
500 | $this->logInAs('admin'); | 535 | $this->logInAs('admin'); |
501 | $client = $this->getClient(); | 536 | $client = $this->getClient(); |
502 | 537 | ||
503 | $content = $client->getContainer() | 538 | $entry = new Entry($this->getLoggedInUser()); |
504 | ->get('doctrine.orm.entity_manager') | 539 | $entry->setUrl($this->url); |
505 | ->getRepository('WallabagCoreBundle:Entry') | 540 | $this->getEntityManager()->persist($entry); |
506 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 541 | $this->getEntityManager()->flush(); |
507 | 542 | ||
508 | $client->request('GET', '/delete/'.$content->getId()); | 543 | $client->request('GET', '/delete/'.$entry->getId()); |
509 | 544 | ||
510 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 545 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
511 | 546 | ||
512 | $client->request('GET', '/delete/'.$content->getId()); | 547 | $client->request('GET', '/delete/'.$entry->getId()); |
513 | 548 | ||
514 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | 549 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); |
515 | } | 550 | } |
@@ -575,7 +610,13 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
575 | public function testFilterOnReadingTime() | 610 | public function testFilterOnReadingTime() |
576 | { | 611 | { |
577 | $this->logInAs('admin'); | 612 | $this->logInAs('admin'); |
613 | $this->useTheme('baggy'); | ||
578 | $client = $this->getClient(); | 614 | $client = $this->getClient(); |
615 | $entry = new Entry($this->getLoggedInUser()); | ||
616 | $entry->setUrl($this->url); | ||
617 | $entry->setReadingTime(22); | ||
618 | $this->getEntityManager()->persist($entry); | ||
619 | $this->getEntityManager()->flush(); | ||
579 | 620 | ||
580 | $crawler = $client->request('GET', '/unread/list'); | 621 | $crawler = $client->request('GET', '/unread/list'); |
581 | 622 | ||
@@ -614,9 +655,20 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
614 | public function testFilterOnReadingTimeOnlyUpper() | 655 | public function testFilterOnReadingTimeOnlyUpper() |
615 | { | 656 | { |
616 | $this->logInAs('admin'); | 657 | $this->logInAs('admin'); |
658 | $this->useTheme('baggy'); | ||
617 | $client = $this->getClient(); | 659 | $client = $this->getClient(); |
618 | 660 | ||
619 | $crawler = $client->request('GET', '/unread/list'); | 661 | $crawler = $client->request('GET', '/all/list'); |
662 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | ||
663 | |||
664 | $entry = new Entry($this->getLoggedInUser()); | ||
665 | $entry->setUrl($this->url); | ||
666 | $entry->setReadingTime(23); | ||
667 | $this->getEntityManager()->persist($entry); | ||
668 | $this->getEntityManager()->flush(); | ||
669 | |||
670 | $crawler = $client->request('GET', '/all/list'); | ||
671 | $this->assertCount(6, $crawler->filter('div[class=entry]')); | ||
620 | 672 | ||
621 | $form = $crawler->filter('button[id=submit-filter]')->form(); | 673 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
622 | 674 | ||
@@ -626,12 +678,13 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
626 | 678 | ||
627 | $crawler = $client->submit($form, $data); | 679 | $crawler = $client->submit($form, $data); |
628 | 680 | ||
629 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | 681 | $this->assertCount(5, $crawler->filter('div[class=entry]')); |
630 | } | 682 | } |
631 | 683 | ||
632 | public function testFilterOnReadingTimeOnlyLower() | 684 | public function testFilterOnReadingTimeOnlyLower() |
633 | { | 685 | { |
634 | $this->logInAs('admin'); | 686 | $this->logInAs('admin'); |
687 | $this->useTheme('baggy'); | ||
635 | $client = $this->getClient(); | 688 | $client = $this->getClient(); |
636 | 689 | ||
637 | $crawler = $client->request('GET', '/unread/list'); | 690 | $crawler = $client->request('GET', '/unread/list'); |
@@ -644,12 +697,22 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
644 | 697 | ||
645 | $crawler = $client->submit($form, $data); | 698 | $crawler = $client->submit($form, $data); |
646 | 699 | ||
647 | $this->assertCount(4, $crawler->filter('div[class=entry]')); | 700 | $this->assertCount(0, $crawler->filter('div[class=entry]')); |
701 | |||
702 | $entry = new Entry($this->getLoggedInUser()); | ||
703 | $entry->setUrl($this->url); | ||
704 | $entry->setReadingTime(23); | ||
705 | $this->getEntityManager()->persist($entry); | ||
706 | $this->getEntityManager()->flush(); | ||
707 | |||
708 | $crawler = $client->submit($form, $data); | ||
709 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | ||
648 | } | 710 | } |
649 | 711 | ||
650 | public function testFilterOnUnreadStatus() | 712 | public function testFilterOnUnreadStatus() |
651 | { | 713 | { |
652 | $this->logInAs('admin'); | 714 | $this->logInAs('admin'); |
715 | $this->useTheme('baggy'); | ||
653 | $client = $this->getClient(); | 716 | $client = $this->getClient(); |
654 | 717 | ||
655 | $crawler = $client->request('GET', '/all/list'); | 718 | $crawler = $client->request('GET', '/all/list'); |
@@ -663,11 +726,22 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
663 | $crawler = $client->submit($form, $data); | 726 | $crawler = $client->submit($form, $data); |
664 | 727 | ||
665 | $this->assertCount(4, $crawler->filter('div[class=entry]')); | 728 | $this->assertCount(4, $crawler->filter('div[class=entry]')); |
729 | |||
730 | $entry = new Entry($this->getLoggedInUser()); | ||
731 | $entry->setUrl($this->url); | ||
732 | $entry->setArchived(false); | ||
733 | $this->getEntityManager()->persist($entry); | ||
734 | $this->getEntityManager()->flush(); | ||
735 | |||
736 | $crawler = $client->submit($form, $data); | ||
737 | |||
738 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | ||
666 | } | 739 | } |
667 | 740 | ||
668 | public function testFilterOnCreationDate() | 741 | public function testFilterOnCreationDate() |
669 | { | 742 | { |
670 | $this->logInAs('admin'); | 743 | $this->logInAs('admin'); |
744 | $this->useTheme('baggy'); | ||
671 | $client = $this->getClient(); | 745 | $client = $this->getClient(); |
672 | 746 | ||
673 | $crawler = $client->request('GET', '/unread/list'); | 747 | $crawler = $client->request('GET', '/unread/list'); |
@@ -734,6 +808,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
734 | public function testFilterOnDomainName() | 808 | public function testFilterOnDomainName() |
735 | { | 809 | { |
736 | $this->logInAs('admin'); | 810 | $this->logInAs('admin'); |
811 | $this->useTheme('baggy'); | ||
737 | $client = $this->getClient(); | 812 | $client = $this->getClient(); |
738 | 813 | ||
739 | $crawler = $client->request('GET', '/unread/list'); | 814 | $crawler = $client->request('GET', '/unread/list'); |
@@ -766,6 +841,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
766 | public function testFilterOnStatus() | 841 | public function testFilterOnStatus() |
767 | { | 842 | { |
768 | $this->logInAs('admin'); | 843 | $this->logInAs('admin'); |
844 | $this->useTheme('baggy'); | ||
769 | $client = $this->getClient(); | 845 | $client = $this->getClient(); |
770 | 846 | ||
771 | $crawler = $client->request('GET', '/unread/list'); | 847 | $crawler = $client->request('GET', '/unread/list'); |
@@ -787,6 +863,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
787 | public function testPreviewPictureFilter() | 863 | public function testPreviewPictureFilter() |
788 | { | 864 | { |
789 | $this->logInAs('admin'); | 865 | $this->logInAs('admin'); |
866 | $this->useTheme('baggy'); | ||
790 | $client = $this->getClient(); | 867 | $client = $this->getClient(); |
791 | 868 | ||
792 | $crawler = $client->request('GET', '/unread/list'); | 869 | $crawler = $client->request('GET', '/unread/list'); |
@@ -800,8 +877,15 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
800 | public function testFilterOnLanguage() | 877 | public function testFilterOnLanguage() |
801 | { | 878 | { |
802 | $this->logInAs('admin'); | 879 | $this->logInAs('admin'); |
880 | $this->useTheme('baggy'); | ||
803 | $client = $this->getClient(); | 881 | $client = $this->getClient(); |
804 | 882 | ||
883 | $entry = new Entry($this->getLoggedInUser()); | ||
884 | $entry->setUrl($this->url); | ||
885 | $entry->setLanguage('fr'); | ||
886 | $this->getEntityManager()->persist($entry); | ||
887 | $this->getEntityManager()->flush(); | ||
888 | |||
805 | $crawler = $client->request('GET', '/unread/list'); | 889 | $crawler = $client->request('GET', '/unread/list'); |
806 | $form = $crawler->filter('button[id=submit-filter]')->form(); | 890 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
807 | $data = [ | 891 | $data = [ |
@@ -809,7 +893,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
809 | ]; | 893 | ]; |
810 | 894 | ||
811 | $crawler = $client->submit($form, $data); | 895 | $crawler = $client->submit($form, $data); |
812 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | 896 | $this->assertCount(3, $crawler->filter('div[class=entry]')); |
813 | 897 | ||
814 | $form = $crawler->filter('button[id=submit-filter]')->form(); | 898 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
815 | $data = [ | 899 | $data = [ |
@@ -825,10 +909,14 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
825 | $this->logInAs('admin'); | 909 | $this->logInAs('admin'); |
826 | $client = $this->getClient(); | 910 | $client = $this->getClient(); |
827 | 911 | ||
828 | $content = $client->getContainer() | 912 | // sharing is enabled |
829 | ->get('doctrine.orm.entity_manager') | 913 | $client->getContainer()->get('craue_config')->set('share_public', 1); |
830 | ->getRepository('WallabagCoreBundle:Entry') | 914 | |
831 | ->findOneByUser($this->getLoggedInUserId()); | 915 | $content = new Entry($this->getLoggedInUser()); |
916 | $content->setUrl($this->url); | ||
917 | $this->getEntityManager()->persist($content); | ||
918 | $this->getEntityManager()->flush(); | ||
919 | $this->getEntityManager()->clear(); | ||
832 | 920 | ||
833 | // no uid | 921 | // no uid |
834 | $client->request('GET', '/share/'.$content->getUid()); | 922 | $client->request('GET', '/share/'.$content->getUid()); |
@@ -869,6 +957,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
869 | 957 | ||
870 | public function testNewEntryWithDownloadImagesEnabled() | 958 | public function testNewEntryWithDownloadImagesEnabled() |
871 | { | 959 | { |
960 | $this->downloadImagesEnabled = true; | ||
872 | $this->logInAs('admin'); | 961 | $this->logInAs('admin'); |
873 | $client = $this->getClient(); | 962 | $client = $this->getClient(); |
874 | 963 | ||
@@ -899,7 +988,8 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
899 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry); | 988 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry); |
900 | $this->assertEquals($url, $entry->getUrl()); | 989 | $this->assertEquals($url, $entry->getUrl()); |
901 | $this->assertContains('Perpignan', $entry->getTitle()); | 990 | $this->assertContains('Perpignan', $entry->getTitle()); |
902 | $this->assertContains('/d9bc0fcd.jpeg', $entry->getContent()); | 991 | // instead of checking for the filename (which might change) check that the image is now local |
992 | $this->assertContains('https://your-wallabag-url-instance.com/assets/images/', $entry->getContent()); | ||
903 | 993 | ||
904 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); | 994 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); |
905 | } | 995 | } |
@@ -909,12 +999,27 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
909 | */ | 999 | */ |
910 | public function testRemoveEntryWithDownloadImagesEnabled() | 1000 | public function testRemoveEntryWithDownloadImagesEnabled() |
911 | { | 1001 | { |
1002 | $this->downloadImagesEnabled = true; | ||
912 | $this->logInAs('admin'); | 1003 | $this->logInAs('admin'); |
913 | $client = $this->getClient(); | 1004 | $client = $this->getClient(); |
914 | 1005 | ||
915 | $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route'; | 1006 | $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route'; |
916 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 1); | 1007 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 1); |
917 | 1008 | ||
1009 | $crawler = $client->request('GET', '/new'); | ||
1010 | |||
1011 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
1012 | |||
1013 | $form = $crawler->filter('form[name=entry]')->form(); | ||
1014 | |||
1015 | $data = [ | ||
1016 | 'entry[url]' => $url, | ||
1017 | ]; | ||
1018 | |||
1019 | $client->submit($form, $data); | ||
1020 | |||
1021 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
1022 | |||
918 | $content = $client->getContainer() | 1023 | $content = $client->getContainer() |
919 | ->get('doctrine.orm.entity_manager') | 1024 | ->get('doctrine.orm.entity_manager') |
920 | ->getRepository('WallabagCoreBundle:Entry') | 1025 | ->getRepository('WallabagCoreBundle:Entry') |
@@ -932,28 +1037,19 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
932 | $this->logInAs('empty'); | 1037 | $this->logInAs('empty'); |
933 | $client = $this->getClient(); | 1038 | $client = $this->getClient(); |
934 | 1039 | ||
935 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
936 | $user = $em | ||
937 | ->getRepository('WallabagUserBundle:User') | ||
938 | ->find($this->getLoggedInUserId()); | ||
939 | |||
940 | if (!$user) { | ||
941 | $this->markTestSkipped('No user found in db.'); | ||
942 | } | ||
943 | |||
944 | // Redirect to homepage | 1040 | // Redirect to homepage |
945 | $config = $user->getConfig(); | 1041 | $config = $this->getLoggedInUser()->getConfig(); |
946 | $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); | 1042 | $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); |
947 | $em->persist($config); | 1043 | $this->getEntityManager()->persist($config); |
948 | $em->flush(); | ||
949 | 1044 | ||
950 | $content = $client->getContainer() | 1045 | $entry = new Entry($this->getLoggedInUser()); |
951 | ->get('doctrine.orm.entity_manager') | 1046 | $entry->setUrl($this->url); |
952 | ->getRepository('WallabagCoreBundle:Entry') | 1047 | $this->getEntityManager()->persist($entry); |
953 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | ||
954 | 1048 | ||
955 | $client->request('GET', '/view/'.$content->getId()); | 1049 | $this->getEntityManager()->flush(); |
956 | $client->request('GET', '/archive/'.$content->getId()); | 1050 | |
1051 | $client->request('GET', '/view/'.$entry->getId()); | ||
1052 | $client->request('GET', '/archive/'.$entry->getId()); | ||
957 | 1053 | ||
958 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 1054 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
959 | $this->assertEquals('/', $client->getResponse()->headers->get('location')); | 1055 | $this->assertEquals('/', $client->getResponse()->headers->get('location')); |
@@ -964,46 +1060,36 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
964 | $this->logInAs('empty'); | 1060 | $this->logInAs('empty'); |
965 | $client = $this->getClient(); | 1061 | $client = $this->getClient(); |
966 | 1062 | ||
967 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
968 | $user = $em | ||
969 | ->getRepository('WallabagUserBundle:User') | ||
970 | ->find($this->getLoggedInUserId()); | ||
971 | |||
972 | if (!$user) { | ||
973 | $this->markTestSkipped('No user found in db.'); | ||
974 | } | ||
975 | |||
976 | // Redirect to current page | 1063 | // Redirect to current page |
977 | $config = $user->getConfig(); | 1064 | $config = $this->getLoggedInUser()->getConfig(); |
978 | $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE); | 1065 | $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE); |
979 | $em->persist($config); | 1066 | $this->getEntityManager()->persist($config); |
980 | $em->flush(); | ||
981 | 1067 | ||
982 | $content = $client->getContainer() | 1068 | $entry = new Entry($this->getLoggedInUser()); |
983 | ->get('doctrine.orm.entity_manager') | 1069 | $entry->setUrl($this->url); |
984 | ->getRepository('WallabagCoreBundle:Entry') | 1070 | $this->getEntityManager()->persist($entry); |
985 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | ||
986 | 1071 | ||
987 | $client->request('GET', '/view/'.$content->getId()); | 1072 | $this->getEntityManager()->flush(); |
988 | $client->request('GET', '/archive/'.$content->getId()); | 1073 | |
1074 | $client->request('GET', '/view/'.$entry->getId()); | ||
1075 | $client->request('GET', '/archive/'.$entry->getId()); | ||
989 | 1076 | ||
990 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 1077 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
991 | $this->assertContains('/view/'.$content->getId(), $client->getResponse()->headers->get('location')); | 1078 | $this->assertContains('/view/'.$entry->getId(), $client->getResponse()->headers->get('location')); |
992 | } | 1079 | } |
993 | 1080 | ||
994 | public function testFilterOnHttpStatus() | 1081 | public function testFilterOnHttpStatus() |
995 | { | 1082 | { |
996 | $this->logInAs('admin'); | 1083 | $this->logInAs('admin'); |
1084 | $this->useTheme('baggy'); | ||
997 | $client = $this->getClient(); | 1085 | $client = $this->getClient(); |
998 | 1086 | ||
999 | $crawler = $client->request('GET', '/new'); | 1087 | $entry = new Entry($this->getLoggedInUser()); |
1000 | $form = $crawler->filter('form[name=entry]')->form(); | 1088 | $entry->setUrl('http://www.lemonde.fr/incorrect-url/'); |
1001 | 1089 | $entry->setHttpStatus(404); | |
1002 | $data = [ | 1090 | $this->getEntityManager()->persist($entry); |
1003 | 'entry[url]' => 'http://www.lemonde.fr/incorrect-url/', | ||
1004 | ]; | ||
1005 | 1091 | ||
1006 | $client->submit($form, $data); | 1092 | $this->getEntityManager()->flush(); |
1007 | 1093 | ||
1008 | $crawler = $client->request('GET', '/all/list'); | 1094 | $crawler = $client->request('GET', '/all/list'); |
1009 | $form = $crawler->filter('button[id=submit-filter]')->form(); | 1095 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
@@ -1016,14 +1102,17 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1016 | 1102 | ||
1017 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | 1103 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
1018 | 1104 | ||
1019 | $crawler = $client->request('GET', '/new'); | 1105 | $entry = new Entry($this->getLoggedInUser()); |
1020 | $form = $crawler->filter('form[name=entry]')->form(); | 1106 | $entry->setUrl($this->url); |
1107 | $entry->setHttpStatus(200); | ||
1108 | $this->getEntityManager()->persist($entry); | ||
1021 | 1109 | ||
1022 | $data = [ | 1110 | $entry = new Entry($this->getLoggedInUser()); |
1023 | 'entry[url]' => 'http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm', | 1111 | $entry->setUrl('http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm'); |
1024 | ]; | 1112 | $entry->setHttpStatus(200); |
1113 | $this->getEntityManager()->persist($entry); | ||
1025 | 1114 | ||
1026 | $client->submit($form, $data); | 1115 | $this->getEntityManager()->flush(); |
1027 | 1116 | ||
1028 | $crawler = $client->request('GET', '/all/list'); | 1117 | $crawler = $client->request('GET', '/all/list'); |
1029 | $form = $crawler->filter('button[id=submit-filter]')->form(); | 1118 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
@@ -1034,7 +1123,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1034 | 1123 | ||
1035 | $crawler = $client->submit($form, $data); | 1124 | $crawler = $client->submit($form, $data); |
1036 | 1125 | ||
1037 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | 1126 | $this->assertCount(2, $crawler->filter('div[class=entry]')); |
1038 | 1127 | ||
1039 | $crawler = $client->request('GET', '/all/list'); | 1128 | $crawler = $client->request('GET', '/all/list'); |
1040 | $form = $crawler->filter('button[id=submit-filter]')->form(); | 1129 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
@@ -1045,14 +1134,21 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1045 | 1134 | ||
1046 | $crawler = $client->submit($form, $data); | 1135 | $crawler = $client->submit($form, $data); |
1047 | 1136 | ||
1048 | $this->assertCount(7, $crawler->filter('div[class=entry]')); | 1137 | $this->assertCount(8, $crawler->filter('div[class=entry]')); |
1049 | } | 1138 | } |
1050 | 1139 | ||
1051 | public function testSearch() | 1140 | public function testSearch() |
1052 | { | 1141 | { |
1053 | $this->logInAs('admin'); | 1142 | $this->logInAs('admin'); |
1143 | $this->useTheme('baggy'); | ||
1054 | $client = $this->getClient(); | 1144 | $client = $this->getClient(); |
1055 | 1145 | ||
1146 | $entry = new Entry($this->getLoggedInUser()); | ||
1147 | $entry->setUrl($this->url); | ||
1148 | $entry->setTitle('test'); | ||
1149 | $this->getEntityManager()->persist($entry); | ||
1150 | $this->getEntityManager()->flush(); | ||
1151 | |||
1056 | // Search on unread list | 1152 | // Search on unread list |
1057 | $crawler = $client->request('GET', '/unread/list'); | 1153 | $crawler = $client->request('GET', '/unread/list'); |
1058 | 1154 | ||
@@ -1063,35 +1159,37 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1063 | 1159 | ||
1064 | $crawler = $client->submit($form, $data); | 1160 | $crawler = $client->submit($form, $data); |
1065 | 1161 | ||
1066 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | 1162 | $this->assertCount(4, $crawler->filter('div[class=entry]')); |
1067 | 1163 | ||
1068 | // Search on starred list | 1164 | // Search on starred list |
1069 | $crawler = $client->request('GET', '/starred/list'); | 1165 | $crawler = $client->request('GET', '/starred/list'); |
1070 | 1166 | ||
1167 | $entry = new Entry($this->getLoggedInUser()); | ||
1168 | $entry->setUrl('http://localhost/foo/bar'); | ||
1169 | $entry->setTitle('testeur'); | ||
1170 | $entry->setStarred(true); | ||
1171 | $this->getEntityManager()->persist($entry); | ||
1172 | $this->getEntityManager()->flush(); | ||
1173 | |||
1071 | $form = $crawler->filter('form[name=search]')->form(); | 1174 | $form = $crawler->filter('form[name=search]')->form(); |
1072 | $data = [ | 1175 | $data = [ |
1073 | 'search_entry[term]' => 'title', | 1176 | 'search_entry[term]' => 'testeur', |
1074 | ]; | 1177 | ]; |
1075 | 1178 | ||
1076 | $crawler = $client->submit($form, $data); | 1179 | $crawler = $client->submit($form, $data); |
1077 | 1180 | ||
1078 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | 1181 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
1079 | 1182 | ||
1080 | // Added new article to test on archive list | ||
1081 | $crawler = $client->request('GET', '/new'); | ||
1082 | $form = $crawler->filter('form[name=entry]')->form(); | ||
1083 | $data = [ | ||
1084 | 'entry[url]' => $this->url, | ||
1085 | ]; | ||
1086 | $client->submit($form, $data); | ||
1087 | $content = $client->getContainer() | ||
1088 | ->get('doctrine.orm.entity_manager') | ||
1089 | ->getRepository('WallabagCoreBundle:Entry') | ||
1090 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | ||
1091 | $client->request('GET', '/archive/'.$content->getId()); | ||
1092 | |||
1093 | $crawler = $client->request('GET', '/archive/list'); | 1183 | $crawler = $client->request('GET', '/archive/list'); |
1094 | 1184 | ||
1185 | // Added new article to test on archive list | ||
1186 | $entry = new Entry($this->getLoggedInUser()); | ||
1187 | $entry->setUrl('http://0.0.0.0/foo/baz/qux'); | ||
1188 | $entry->setTitle('Le manège'); | ||
1189 | $entry->setArchived(true); | ||
1190 | $this->getEntityManager()->persist($entry); | ||
1191 | $this->getEntityManager()->flush(); | ||
1192 | |||
1095 | $form = $crawler->filter('form[name=search]')->form(); | 1193 | $form = $crawler->filter('form[name=search]')->form(); |
1096 | $data = [ | 1194 | $data = [ |
1097 | 'search_entry[term]' => 'manège', | 1195 | 'search_entry[term]' => 'manège', |
@@ -1100,7 +1198,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1100 | $crawler = $client->submit($form, $data); | 1198 | $crawler = $client->submit($form, $data); |
1101 | 1199 | ||
1102 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | 1200 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
1103 | $client->request('GET', '/delete/'.$content->getId()); | 1201 | $client->request('GET', '/delete/'.$entry->getId()); |
1104 | 1202 | ||
1105 | // test on list of all articles | 1203 | // test on list of all articles |
1106 | $crawler = $client->request('GET', '/all/list'); | 1204 | $crawler = $client->request('GET', '/all/list'); |
@@ -1115,6 +1213,13 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1115 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | 1213 | $this->assertCount(0, $crawler->filter('div[class=entry]')); |
1116 | 1214 | ||
1117 | // test url search on list of all articles | 1215 | // test url search on list of all articles |
1216 | $entry = new Entry($this->getLoggedInUser()); | ||
1217 | $entry->setUrl('http://domain/qux'); | ||
1218 | $entry->setTitle('Le manège'); | ||
1219 | $entry->setArchived(true); | ||
1220 | $this->getEntityManager()->persist($entry); | ||
1221 | $this->getEntityManager()->flush(); | ||
1222 | |||
1118 | $crawler = $client->request('GET', '/all/list'); | 1223 | $crawler = $client->request('GET', '/all/list'); |
1119 | 1224 | ||
1120 | $form = $crawler->filter('form[name=search]')->form(); | 1225 | $form = $crawler->filter('form[name=search]')->form(); |
@@ -1138,4 +1243,82 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1138 | 1243 | ||
1139 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | 1244 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
1140 | } | 1245 | } |
1246 | |||
1247 | public function dataForLanguage() | ||
1248 | { | ||
1249 | return [ | ||
1250 | 'ru' => [ | ||
1251 | 'https://www.pravda.ru/world/09-06-2017/1337283-qatar-0/', | ||
1252 | 'ru', | ||
1253 | ], | ||
1254 | 'fr-FR' => [ | ||
1255 | 'http://www.zataz.com/90-des-dossiers-medicaux-des-coreens-du-sud-vendus-a-des-entreprises-privees/', | ||
1256 | 'fr_FR', | ||
1257 | ], | ||
1258 | 'de' => [ | ||
1259 | 'http://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html', | ||
1260 | 'de', | ||
1261 | ], | ||
1262 | 'it' => [ | ||
1263 | 'http://www.ansa.it/sito/notizie/mondo/europa/2017/06/08/voto-gb-seggi-aperti-misure-sicurezza-rafforzate_0cb71f7f-e23b-4d5f-95ca-bc12296419f0.html', | ||
1264 | 'it', | ||
1265 | ], | ||
1266 | 'zh_CN' => [ | ||
1267 | 'http://www.hao123.com/shequ?__noscript__-=1', | ||
1268 | 'zh_CN', | ||
1269 | ], | ||
1270 | 'de_AT' => [ | ||
1271 | 'https://buy.garmin.com/de-AT/AT/catalog/product/compareResult.ep?compareProduct=112885&compareProduct=36728', | ||
1272 | 'de_AT', | ||
1273 | ], | ||
1274 | 'ru_RU' => [ | ||
1275 | 'http://netler.ru/ikt/windows-error-reporting.htm', | ||
1276 | 'ru_RU', | ||
1277 | ], | ||
1278 | 'pt_BR' => [ | ||
1279 | 'http://precodoscombustiveis.com.br/postos/cidade/4121/pr/maringa', | ||
1280 | 'pt_BR', | ||
1281 | ], | ||
1282 | 'fucked_list_of_languages' => [ | ||
1283 | 'http://geocatalog.webservice-energy.org/geonetwork/srv/eng/main.home', | ||
1284 | '', | ||
1285 | ], | ||
1286 | 'es-ES' => [ | ||
1287 | 'http://www.muylinux.com/2015/04/17/odf-reino-unido-microsoft-google', | ||
1288 | 'es_ES', | ||
1289 | ], | ||
1290 | ]; | ||
1291 | } | ||
1292 | |||
1293 | /** | ||
1294 | * @dataProvider dataForLanguage | ||
1295 | */ | ||
1296 | public function testLanguageValidation($url, $expectedLanguage) | ||
1297 | { | ||
1298 | $this->logInAs('admin'); | ||
1299 | $client = $this->getClient(); | ||
1300 | |||
1301 | $crawler = $client->request('GET', '/new'); | ||
1302 | |||
1303 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
1304 | |||
1305 | $form = $crawler->filter('form[name=entry]')->form(); | ||
1306 | |||
1307 | $data = [ | ||
1308 | 'entry[url]' => $url, | ||
1309 | ]; | ||
1310 | |||
1311 | $client->submit($form, $data); | ||
1312 | |||
1313 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
1314 | |||
1315 | $content = $client->getContainer() | ||
1316 | ->get('doctrine.orm.entity_manager') | ||
1317 | ->getRepository('WallabagCoreBundle:Entry') | ||
1318 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | ||
1319 | |||
1320 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); | ||
1321 | $this->assertEquals($url, $content->getUrl()); | ||
1322 | $this->assertEquals($expectedLanguage, $content->getLanguage()); | ||
1323 | } | ||
1141 | } | 1324 | } |