aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
diff options
context:
space:
mode:
authoradev <adev2000@gmail.com>2017-05-15 20:47:59 +0200
committeradev <adev2000@gmail.com>2017-05-31 16:03:54 +0200
commit7ab5eb9508921d84b4b4ec84a59135d536da748e (patch)
tree725d9fae04d07a2c0aec2d2f5a19e1b43ec7a5d1 /tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
parent4423b88c5b2c2d530b0a83a822f521a61ca4d4b8 (diff)
downloadwallabag-7ab5eb9508921d84b4b4ec84a59135d536da748e.tar.gz
wallabag-7ab5eb9508921d84b4b4ec84a59135d536da748e.tar.zst
wallabag-7ab5eb9508921d84b4b4ec84a59135d536da748e.zip
Isolated tests
Use https://github.com/dmaicher/doctrine-test-bundle to have test isolation.
Diffstat (limited to 'tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php')
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php359
1 files changed, 210 insertions, 149 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index 116e5f32..cc7b3672 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -71,6 +71,7 @@ class EntryControllerTest extends WallabagCoreTestCase
71 public function testGetNew() 71 public function testGetNew()
72 { 72 {
73 $this->logInAs('admin'); 73 $this->logInAs('admin');
74 $this->useTheme('baggy');
74 $client = $this->getClient(); 75 $client = $this->getClient();
75 76
76 $crawler = $client->request('GET', '/new'); 77 $crawler = $client->request('GET', '/new');
@@ -84,6 +85,7 @@ class EntryControllerTest extends WallabagCoreTestCase
84 public function testPostNewViaBookmarklet() 85 public function testPostNewViaBookmarklet()
85 { 86 {
86 $this->logInAs('admin'); 87 $this->logInAs('admin');
88 $this->useTheme('baggy');
87 $client = $this->getClient(); 89 $client = $this->getClient();
88 90
89 $crawler = $client->request('GET', '/'); 91 $crawler = $client->request('GET', '/');
@@ -195,6 +197,12 @@ class EntryControllerTest extends WallabagCoreTestCase
195 public function testPostNewOkUrlExist() 197 public function testPostNewOkUrlExist()
196 { 198 {
197 $this->logInAs('admin'); 199 $this->logInAs('admin');
200
201 $entry = new Entry($this->getLoggedInUser());
202 $entry->setUrl($this->url);
203 $this->getEntityManager()->persist($entry);
204 $this->getEntityManager()->flush();
205
198 $client = $this->getClient(); 206 $client = $this->getClient();
199 207
200 $crawler = $client->request('GET', '/new'); 208 $crawler = $client->request('GET', '/new');
@@ -288,7 +296,7 @@ class EntryControllerTest extends WallabagCoreTestCase
288 $tags = $entry->getTags(); 296 $tags = $entry->getTags();
289 297
290 $this->assertCount(2, $tags); 298 $this->assertCount(2, $tags);
291 $this->assertEquals('wallabag', $tags[0]->getLabel()); 299 $this->assertContains('wallabag', $tags);
292 300
293 $em->remove($entry); 301 $em->remove($entry);
294 $em->flush(); 302 $em->flush();
@@ -317,7 +325,7 @@ class EntryControllerTest extends WallabagCoreTestCase
317 $tags = $entry->getTags(); 325 $tags = $entry->getTags();
318 326
319 $this->assertCount(2, $tags); 327 $this->assertCount(2, $tags);
320 $this->assertEquals('wallabag', $tags[1]->getLabel()); 328 $this->assertContains('wallabag', $tags);
321 329
322 $em->remove($entry); 330 $em->remove($entry);
323 $em->flush(); 331 $em->flush();
@@ -364,24 +372,23 @@ class EntryControllerTest extends WallabagCoreTestCase
364 $this->assertEquals('/all/list', $client->getResponse()->getTargetUrl()); 372 $this->assertEquals('/all/list', $client->getResponse()->getTargetUrl());
365 } 373 }
366 374
367 /**
368 * @depends testPostNewOk
369 */
370 public function testView() 375 public function testView()
371 { 376 {
372 $this->logInAs('admin'); 377 $this->logInAs('admin');
373 $client = $this->getClient(); 378 $client = $this->getClient();
374 379
375 $content = $client->getContainer() 380 $entry = new Entry($this->getLoggedInUser());
376 ->get('doctrine.orm.entity_manager') 381 $entry->setUrl('http://example.com/foo');
377 ->getRepository('WallabagCoreBundle:Entry') 382 $entry->setTitle('title foo');
378 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); 383 $entry->setContent('foo bar baz');
384 $this->getEntityManager()->persist($entry);
385 $this->getEntityManager()->flush();
379 386
380 $crawler = $client->request('GET', '/view/'.$content->getId()); 387 $crawler = $client->request('GET', '/view/'.$entry->getId());
381 388
382 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 389 $this->assertEquals(200, $client->getResponse()->getStatusCode());
383 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); 390 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
384 $this->assertContains($content->getTitle(), $body[0]); 391 $this->assertContains($entry->getTitle(), $body[0]);
385 } 392 }
386 393
387 /** 394 /**
@@ -394,27 +401,23 @@ class EntryControllerTest extends WallabagCoreTestCase
394 $this->logInAs('admin'); 401 $this->logInAs('admin');
395 $client = $this->getClient(); 402 $client = $this->getClient();
396 403
397 $em = $client->getContainer() 404 $entry = new Entry($this->getLoggedInUser());
398 ->get('doctrine.orm.entity_manager'); 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();
399 411
400 $content = $em 412 $client->request('GET', '/reload/'.$entry->getId());
401 ->getRepository('WallabagCoreBundle:Entry')
402 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
403
404 // empty content
405 $content->setContent('');
406 $em->persist($content);
407 $em->flush();
408
409 $client->request('GET', '/reload/'.$content->getId());
410 413
411 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 414 $this->assertEquals(302, $client->getResponse()->getStatusCode());
412 415
413 $content = $em 416 $entry = $this->getEntityManager()
414 ->getRepository('WallabagCoreBundle:Entry') 417 ->getRepository('WallabagCoreBundle:Entry')
415 ->find($content->getId()); 418 ->find($entry->getId());
416 419
417 $this->assertNotEmpty($content->getContent()); 420 $this->assertNotEmpty($entry->getContent());
418 } 421 }
419 422
420 /** 423 /**
@@ -425,32 +428,21 @@ class EntryControllerTest extends WallabagCoreTestCase
425 $this->logInAs('admin'); 428 $this->logInAs('admin');
426 $client = $this->getClient(); 429 $client = $this->getClient();
427 430
428 $em = $client->getContainer() 431 $entry = new Entry($this->getLoggedInUser());
429 ->get('doctrine.orm.entity_manager'); 432 $entry->setUrl('http://0.0.0.0/failed.html');
430 433 $this->getEntityManager()->persist($entry);
431 $content = $em 434 $this->getEntityManager()->flush();
432 ->getRepository('WallabagCoreBundle:Entry')
433 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
434
435 // put a known failed url
436 $content->setUrl('http://0.0.0.0/failed.html');
437 $em->persist($content);
438 $em->flush();
439 435
440 $client->request('GET', '/reload/'.$content->getId()); 436 $client->request('GET', '/reload/'.$entry->getId());
441 437
442 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 438 $this->assertEquals(302, $client->getResponse()->getStatusCode());
443 439
444 // force EntityManager to clear previous entity 440 // force EntityManager to clear previous entity
445 // otherwise, retrieve the same entity will retrieve change from the previous request :0 441 // otherwise, retrieve the same entity will retrieve change from the previous request :0
446 $em->clear(); 442 $this->getEntityManager()->clear();
447 $newContent = $em 443 $newContent = $this->getEntityManager()
448 ->getRepository('WallabagCoreBundle:Entry') 444 ->getRepository('WallabagCoreBundle:Entry')
449 ->find($content->getId()); 445 ->find($entry->getId());
450
451 $newContent->setUrl($this->url);
452 $em->persist($newContent);
453 $em->flush();
454 446
455 $this->assertNotEquals($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent()); 447 $this->assertNotEquals($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent());
456 } 448 }
@@ -460,12 +452,12 @@ class EntryControllerTest extends WallabagCoreTestCase
460 $this->logInAs('admin'); 452 $this->logInAs('admin');
461 $client = $this->getClient(); 453 $client = $this->getClient();
462 454
463 $content = $client->getContainer() 455 $entry = new Entry($this->getLoggedInUser());
464 ->get('doctrine.orm.entity_manager') 456 $entry->setUrl($this->url);
465 ->getRepository('WallabagCoreBundle:Entry') 457 $this->getEntityManager()->persist($entry);
466 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); 458 $this->getEntityManager()->flush();
467 459
468 $crawler = $client->request('GET', '/edit/'.$content->getId()); 460 $crawler = $client->request('GET', '/edit/'.$entry->getId());
469 461
470 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 462 $this->assertEquals(200, $client->getResponse()->getStatusCode());
471 463
@@ -478,12 +470,12 @@ class EntryControllerTest extends WallabagCoreTestCase
478 $this->logInAs('admin'); 470 $this->logInAs('admin');
479 $client = $this->getClient(); 471 $client = $this->getClient();
480 472
481 $content = $client->getContainer() 473 $entry = new Entry($this->getLoggedInUser());
482 ->get('doctrine.orm.entity_manager') 474 $entry->setUrl($this->url);
483 ->getRepository('WallabagCoreBundle:Entry') 475 $this->getEntityManager()->persist($entry);
484 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); 476 $this->getEntityManager()->flush();
485 477
486 $crawler = $client->request('GET', '/edit/'.$content->getId()); 478 $crawler = $client->request('GET', '/edit/'.$entry->getId());
487 479
488 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 480 $this->assertEquals(200, $client->getResponse()->getStatusCode());
489 481
@@ -508,19 +500,20 @@ class EntryControllerTest extends WallabagCoreTestCase
508 $this->logInAs('admin'); 500 $this->logInAs('admin');
509 $client = $this->getClient(); 501 $client = $this->getClient();
510 502
511 $content = $client->getContainer() 503 $entry = new Entry($this->getLoggedInUser());
512 ->get('doctrine.orm.entity_manager') 504 $entry->setUrl($this->url);
513 ->getRepository('WallabagCoreBundle:Entry') 505 $this->getEntityManager()->persist($entry);
514 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); 506 $this->getEntityManager()->flush();
507 $this->getEntityManager()->clear();
515 508
516 $client->request('GET', '/archive/'.$content->getId()); 509 $client->request('GET', '/archive/'.$entry->getId());
517 510
518 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 511 $this->assertEquals(302, $client->getResponse()->getStatusCode());
519 512
520 $res = $client->getContainer() 513 $res = $client->getContainer()
521 ->get('doctrine.orm.entity_manager') 514 ->get('doctrine.orm.entity_manager')
522 ->getRepository('WallabagCoreBundle:Entry') 515 ->getRepository('WallabagCoreBundle:Entry')
523 ->find($content->getId()); 516 ->find($entry->getId());
524 517
525 $this->assertEquals($res->isArchived(), true); 518 $this->assertEquals($res->isArchived(), true);
526 } 519 }
@@ -530,19 +523,20 @@ class EntryControllerTest extends WallabagCoreTestCase
530 $this->logInAs('admin'); 523 $this->logInAs('admin');
531 $client = $this->getClient(); 524 $client = $this->getClient();
532 525
533 $content = $client->getContainer() 526 $entry = new Entry($this->getLoggedInUser());
534 ->get('doctrine.orm.entity_manager') 527 $entry->setUrl($this->url);
535 ->getRepository('WallabagCoreBundle:Entry') 528 $this->getEntityManager()->persist($entry);
536 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); 529 $this->getEntityManager()->flush();
530 $this->getEntityManager()->clear();
537 531
538 $client->request('GET', '/star/'.$content->getId()); 532 $client->request('GET', '/star/'.$entry->getId());
539 533
540 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 534 $this->assertEquals(302, $client->getResponse()->getStatusCode());
541 535
542 $res = $client->getContainer() 536 $res = $client->getContainer()
543 ->get('doctrine.orm.entity_manager') 537 ->get('doctrine.orm.entity_manager')
544 ->getRepository('WallabagCoreBundle:Entry') 538 ->getRepository('WallabagCoreBundle:Entry')
545 ->findOneById($content->getId()); 539 ->findOneById($entry->getId());
546 540
547 $this->assertEquals($res->isStarred(), true); 541 $this->assertEquals($res->isStarred(), true);
548 } 542 }
@@ -552,16 +546,16 @@ class EntryControllerTest extends WallabagCoreTestCase
552 $this->logInAs('admin'); 546 $this->logInAs('admin');
553 $client = $this->getClient(); 547 $client = $this->getClient();
554 548
555 $content = $client->getContainer() 549 $entry = new Entry($this->getLoggedInUser());
556 ->get('doctrine.orm.entity_manager') 550 $entry->setUrl($this->url);
557 ->getRepository('WallabagCoreBundle:Entry') 551 $this->getEntityManager()->persist($entry);
558 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); 552 $this->getEntityManager()->flush();
559 553
560 $client->request('GET', '/delete/'.$content->getId()); 554 $client->request('GET', '/delete/'.$entry->getId());
561 555
562 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 556 $this->assertEquals(302, $client->getResponse()->getStatusCode());
563 557
564 $client->request('GET', '/delete/'.$content->getId()); 558 $client->request('GET', '/delete/'.$entry->getId());
565 559
566 $this->assertEquals(404, $client->getResponse()->getStatusCode()); 560 $this->assertEquals(404, $client->getResponse()->getStatusCode());
567 } 561 }
@@ -627,7 +621,13 @@ class EntryControllerTest extends WallabagCoreTestCase
627 public function testFilterOnReadingTime() 621 public function testFilterOnReadingTime()
628 { 622 {
629 $this->logInAs('admin'); 623 $this->logInAs('admin');
624 $this->useTheme('baggy');
630 $client = $this->getClient(); 625 $client = $this->getClient();
626 $entry = new Entry($this->getLoggedInUser());
627 $entry->setUrl($this->url);
628 $entry->setReadingTime(22);
629 $this->getEntityManager()->persist($entry);
630 $this->getEntityManager()->flush();
631 631
632 $crawler = $client->request('GET', '/unread/list'); 632 $crawler = $client->request('GET', '/unread/list');
633 633
@@ -666,9 +666,20 @@ class EntryControllerTest extends WallabagCoreTestCase
666 public function testFilterOnReadingTimeOnlyUpper() 666 public function testFilterOnReadingTimeOnlyUpper()
667 { 667 {
668 $this->logInAs('admin'); 668 $this->logInAs('admin');
669 $this->useTheme('baggy');
669 $client = $this->getClient(); 670 $client = $this->getClient();
670 671
671 $crawler = $client->request('GET', '/unread/list'); 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]'));
672 683
673 $form = $crawler->filter('button[id=submit-filter]')->form(); 684 $form = $crawler->filter('button[id=submit-filter]')->form();
674 685
@@ -678,12 +689,13 @@ class EntryControllerTest extends WallabagCoreTestCase
678 689
679 $crawler = $client->submit($form, $data); 690 $crawler = $client->submit($form, $data);
680 691
681 $this->assertCount(3, $crawler->filter('div[class=entry]')); 692 $this->assertCount(5, $crawler->filter('div[class=entry]'));
682 } 693 }
683 694
684 public function testFilterOnReadingTimeOnlyLower() 695 public function testFilterOnReadingTimeOnlyLower()
685 { 696 {
686 $this->logInAs('admin'); 697 $this->logInAs('admin');
698 $this->useTheme('baggy');
687 $client = $this->getClient(); 699 $client = $this->getClient();
688 700
689 $crawler = $client->request('GET', '/unread/list'); 701 $crawler = $client->request('GET', '/unread/list');
@@ -696,12 +708,22 @@ class EntryControllerTest extends WallabagCoreTestCase
696 708
697 $crawler = $client->submit($form, $data); 709 $crawler = $client->submit($form, $data);
698 710
699 $this->assertCount(4, $crawler->filter('div[class=entry]')); 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]'));
700 } 721 }
701 722
702 public function testFilterOnUnreadStatus() 723 public function testFilterOnUnreadStatus()
703 { 724 {
704 $this->logInAs('admin'); 725 $this->logInAs('admin');
726 $this->useTheme('baggy');
705 $client = $this->getClient(); 727 $client = $this->getClient();
706 728
707 $crawler = $client->request('GET', '/all/list'); 729 $crawler = $client->request('GET', '/all/list');
@@ -714,12 +736,23 @@ class EntryControllerTest extends WallabagCoreTestCase
714 736
715 $crawler = $client->submit($form, $data); 737 $crawler = $client->submit($form, $data);
716 738
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
717 $this->assertCount(5, $crawler->filter('div[class=entry]')); 749 $this->assertCount(5, $crawler->filter('div[class=entry]'));
718 } 750 }
719 751
720 public function testFilterOnCreationDate() 752 public function testFilterOnCreationDate()
721 { 753 {
722 $this->logInAs('admin'); 754 $this->logInAs('admin');
755 $this->useTheme('baggy');
723 $client = $this->getClient(); 756 $client = $this->getClient();
724 757
725 $crawler = $client->request('GET', '/unread/list'); 758 $crawler = $client->request('GET', '/unread/list');
@@ -733,7 +766,7 @@ class EntryControllerTest extends WallabagCoreTestCase
733 766
734 $crawler = $client->submit($form, $data); 767 $crawler = $client->submit($form, $data);
735 768
736 $this->assertCount(6, $crawler->filter('div[class=entry]')); 769 $this->assertCount(5, $crawler->filter('div[class=entry]'));
737 770
738 $data = [ 771 $data = [
739 'entry_filter[createdAt][left_date]' => date('d/m/Y'), 772 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
@@ -742,7 +775,7 @@ class EntryControllerTest extends WallabagCoreTestCase
742 775
743 $crawler = $client->submit($form, $data); 776 $crawler = $client->submit($form, $data);
744 777
745 $this->assertCount(6, $crawler->filter('div[class=entry]')); 778 $this->assertCount(5, $crawler->filter('div[class=entry]'));
746 779
747 $data = [ 780 $data = [
748 'entry_filter[createdAt][left_date]' => '01/01/1970', 781 'entry_filter[createdAt][left_date]' => '01/01/1970',
@@ -786,6 +819,7 @@ class EntryControllerTest extends WallabagCoreTestCase
786 public function testFilterOnDomainName() 819 public function testFilterOnDomainName()
787 { 820 {
788 $this->logInAs('admin'); 821 $this->logInAs('admin');
822 $this->useTheme('baggy');
789 $client = $this->getClient(); 823 $client = $this->getClient();
790 824
791 $crawler = $client->request('GET', '/unread/list'); 825 $crawler = $client->request('GET', '/unread/list');
@@ -818,6 +852,7 @@ class EntryControllerTest extends WallabagCoreTestCase
818 public function testFilterOnStatus() 852 public function testFilterOnStatus()
819 { 853 {
820 $this->logInAs('admin'); 854 $this->logInAs('admin');
855 $this->useTheme('baggy');
821 $client = $this->getClient(); 856 $client = $this->getClient();
822 857
823 $crawler = $client->request('GET', '/unread/list'); 858 $crawler = $client->request('GET', '/unread/list');
@@ -839,6 +874,7 @@ class EntryControllerTest extends WallabagCoreTestCase
839 public function testPreviewPictureFilter() 874 public function testPreviewPictureFilter()
840 { 875 {
841 $this->logInAs('admin'); 876 $this->logInAs('admin');
877 $this->useTheme('baggy');
842 $client = $this->getClient(); 878 $client = $this->getClient();
843 879
844 $crawler = $client->request('GET', '/unread/list'); 880 $crawler = $client->request('GET', '/unread/list');
@@ -846,14 +882,21 @@ class EntryControllerTest extends WallabagCoreTestCase
846 $form['entry_filter[previewPicture]']->tick(); 882 $form['entry_filter[previewPicture]']->tick();
847 883
848 $crawler = $client->submit($form); 884 $crawler = $client->submit($form);
849 $this->assertCount(2, $crawler->filter('div[class=entry]')); 885 $this->assertCount(1, $crawler->filter('div[class=entry]'));
850 } 886 }
851 887
852 public function testFilterOnLanguage() 888 public function testFilterOnLanguage()
853 { 889 {
854 $this->logInAs('admin'); 890 $this->logInAs('admin');
891 $this->useTheme('baggy');
855 $client = $this->getClient(); 892 $client = $this->getClient();
856 893
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
857 $crawler = $client->request('GET', '/unread/list'); 900 $crawler = $client->request('GET', '/unread/list');
858 $form = $crawler->filter('button[id=submit-filter]')->form(); 901 $form = $crawler->filter('button[id=submit-filter]')->form();
859 $data = [ 902 $data = [
@@ -877,10 +920,14 @@ class EntryControllerTest extends WallabagCoreTestCase
877 $this->logInAs('admin'); 920 $this->logInAs('admin');
878 $client = $this->getClient(); 921 $client = $this->getClient();
879 922
880 $content = $client->getContainer() 923 // sharing is enabled
881 ->get('doctrine.orm.entity_manager') 924 $client->getContainer()->get('craue_config')->set('share_public', 1);
882 ->getRepository('WallabagCoreBundle:Entry') 925
883 ->findOneByUser($this->getLoggedInUserId()); 926 $content = new Entry($this->getLoggedInUser());
927 $content->setUrl($this->url);
928 $this->getEntityManager()->persist($content);
929 $this->getEntityManager()->flush();
930 $this->getEntityManager()->clear();
884 931
885 // no uid 932 // no uid
886 $client->request('GET', '/share/'.$content->getUid()); 933 $client->request('GET', '/share/'.$content->getUid());
@@ -970,6 +1017,20 @@ class EntryControllerTest extends WallabagCoreTestCase
970 $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route'; 1017 $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route';
971 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1); 1018 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
972 1019
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
973 $content = $client->getContainer() 1034 $content = $client->getContainer()
974 ->get('doctrine.orm.entity_manager') 1035 ->get('doctrine.orm.entity_manager')
975 ->getRepository('WallabagCoreBundle:Entry') 1036 ->getRepository('WallabagCoreBundle:Entry')
@@ -987,28 +1048,19 @@ class EntryControllerTest extends WallabagCoreTestCase
987 $this->logInAs('empty'); 1048 $this->logInAs('empty');
988 $client = $this->getClient(); 1049 $client = $this->getClient();
989 1050
990 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
991 $user = $em
992 ->getRepository('WallabagUserBundle:User')
993 ->find($this->getLoggedInUserId());
994
995 if (!$user) {
996 $this->markTestSkipped('No user found in db.');
997 }
998
999 // Redirect to homepage 1051 // Redirect to homepage
1000 $config = $user->getConfig(); 1052 $config = $this->getLoggedInUser()->getConfig();
1001 $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); 1053 $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE);
1002 $em->persist($config); 1054 $this->getEntityManager()->persist($config);
1003 $em->flush();
1004 1055
1005 $content = $client->getContainer() 1056 $entry = new Entry($this->getLoggedInUser());
1006 ->get('doctrine.orm.entity_manager') 1057 $entry->setUrl($this->url);
1007 ->getRepository('WallabagCoreBundle:Entry') 1058 $this->getEntityManager()->persist($entry);
1008 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
1009 1059
1010 $client->request('GET', '/view/'.$content->getId()); 1060 $this->getEntityManager()->flush();
1011 $client->request('GET', '/archive/'.$content->getId()); 1061
1062 $client->request('GET', '/view/'.$entry->getId());
1063 $client->request('GET', '/archive/'.$entry->getId());
1012 1064
1013 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 1065 $this->assertEquals(302, $client->getResponse()->getStatusCode());
1014 $this->assertEquals('/', $client->getResponse()->headers->get('location')); 1066 $this->assertEquals('/', $client->getResponse()->headers->get('location'));
@@ -1019,46 +1071,36 @@ class EntryControllerTest extends WallabagCoreTestCase
1019 $this->logInAs('empty'); 1071 $this->logInAs('empty');
1020 $client = $this->getClient(); 1072 $client = $this->getClient();
1021 1073
1022 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
1023 $user = $em
1024 ->getRepository('WallabagUserBundle:User')
1025 ->find($this->getLoggedInUserId());
1026
1027 if (!$user) {
1028 $this->markTestSkipped('No user found in db.');
1029 }
1030
1031 // Redirect to current page 1074 // Redirect to current page
1032 $config = $user->getConfig(); 1075 $config = $this->getLoggedInUser()->getConfig();
1033 $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE); 1076 $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE);
1034 $em->persist($config); 1077 $this->getEntityManager()->persist($config);
1035 $em->flush();
1036 1078
1037 $content = $client->getContainer() 1079 $entry = new Entry($this->getLoggedInUser());
1038 ->get('doctrine.orm.entity_manager') 1080 $entry->setUrl($this->url);
1039 ->getRepository('WallabagCoreBundle:Entry') 1081 $this->getEntityManager()->persist($entry);
1040 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
1041 1082
1042 $client->request('GET', '/view/'.$content->getId()); 1083 $this->getEntityManager()->flush();
1043 $client->request('GET', '/archive/'.$content->getId()); 1084
1085 $client->request('GET', '/view/'.$entry->getId());
1086 $client->request('GET', '/archive/'.$entry->getId());
1044 1087
1045 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 1088 $this->assertEquals(302, $client->getResponse()->getStatusCode());
1046 $this->assertContains('/view/'.$content->getId(), $client->getResponse()->headers->get('location')); 1089 $this->assertContains('/view/'.$entry->getId(), $client->getResponse()->headers->get('location'));
1047 } 1090 }
1048 1091
1049 public function testFilterOnHttpStatus() 1092 public function testFilterOnHttpStatus()
1050 { 1093 {
1051 $this->logInAs('admin'); 1094 $this->logInAs('admin');
1095 $this->useTheme('baggy');
1052 $client = $this->getClient(); 1096 $client = $this->getClient();
1053 1097
1054 $crawler = $client->request('GET', '/new'); 1098 $entry = new Entry($this->getLoggedInUser());
1055 $form = $crawler->filter('form[name=entry]')->form(); 1099 $entry->setUrl('http://www.lemonde.fr/incorrect-url/');
1100 $entry->setHttpStatus(404);
1101 $this->getEntityManager()->persist($entry);
1056 1102
1057 $data = [ 1103 $this->getEntityManager()->flush();
1058 'entry[url]' => 'http://www.lemonde.fr/incorrect-url/',
1059 ];
1060
1061 $client->submit($form, $data);
1062 1104
1063 $crawler = $client->request('GET', '/all/list'); 1105 $crawler = $client->request('GET', '/all/list');
1064 $form = $crawler->filter('button[id=submit-filter]')->form(); 1106 $form = $crawler->filter('button[id=submit-filter]')->form();
@@ -1071,14 +1113,17 @@ class EntryControllerTest extends WallabagCoreTestCase
1071 1113
1072 $this->assertCount(1, $crawler->filter('div[class=entry]')); 1114 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1073 1115
1074 $crawler = $client->request('GET', '/new'); 1116 $entry = new Entry($this->getLoggedInUser());
1075 $form = $crawler->filter('form[name=entry]')->form(); 1117 $entry->setUrl($this->url);
1118 $entry->setHttpStatus(200);
1119 $this->getEntityManager()->persist($entry);
1076 1120
1077 $data = [ 1121 $entry = new Entry($this->getLoggedInUser());
1078 'entry[url]' => 'http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm', 1122 $entry->setUrl('http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm');
1079 ]; 1123 $entry->setHttpStatus(200);
1124 $this->getEntityManager()->persist($entry);
1080 1125
1081 $client->submit($form, $data); 1126 $this->getEntityManager()->flush();
1082 1127
1083 $crawler = $client->request('GET', '/all/list'); 1128 $crawler = $client->request('GET', '/all/list');
1084 $form = $crawler->filter('button[id=submit-filter]')->form(); 1129 $form = $crawler->filter('button[id=submit-filter]')->form();
@@ -1106,8 +1151,15 @@ class EntryControllerTest extends WallabagCoreTestCase
1106 public function testSearch() 1151 public function testSearch()
1107 { 1152 {
1108 $this->logInAs('admin'); 1153 $this->logInAs('admin');
1154 $this->useTheme('baggy');
1109 $client = $this->getClient(); 1155 $client = $this->getClient();
1110 1156
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
1111 // Search on unread list 1163 // Search on unread list
1112 $crawler = $client->request('GET', '/unread/list'); 1164 $crawler = $client->request('GET', '/unread/list');
1113 1165
@@ -1118,35 +1170,37 @@ class EntryControllerTest extends WallabagCoreTestCase
1118 1170
1119 $crawler = $client->submit($form, $data); 1171 $crawler = $client->submit($form, $data);
1120 1172
1121 $this->assertCount(5, $crawler->filter('div[class=entry]')); 1173 $this->assertCount(4, $crawler->filter('div[class=entry]'));
1122 1174
1123 // Search on starred list 1175 // Search on starred list
1124 $crawler = $client->request('GET', '/starred/list'); 1176 $crawler = $client->request('GET', '/starred/list');
1125 1177
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
1126 $form = $crawler->filter('form[name=search]')->form(); 1185 $form = $crawler->filter('form[name=search]')->form();
1127 $data = [ 1186 $data = [
1128 'search_entry[term]' => 'title', 1187 'search_entry[term]' => 'testeur',
1129 ]; 1188 ];
1130 1189
1131 $crawler = $client->submit($form, $data); 1190 $crawler = $client->submit($form, $data);
1132 1191
1133 $this->assertCount(1, $crawler->filter('div[class=entry]')); 1192 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1134 1193
1135 // Added new article to test on archive list
1136 $crawler = $client->request('GET', '/new');
1137 $form = $crawler->filter('form[name=entry]')->form();
1138 $data = [
1139 'entry[url]' => $this->url,
1140 ];
1141 $client->submit($form, $data);
1142 $content = $client->getContainer()
1143 ->get('doctrine.orm.entity_manager')
1144 ->getRepository('WallabagCoreBundle:Entry')
1145 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
1146 $client->request('GET', '/archive/'.$content->getId());
1147
1148 $crawler = $client->request('GET', '/archive/list'); 1194 $crawler = $client->request('GET', '/archive/list');
1149 1195
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
1150 $form = $crawler->filter('form[name=search]')->form(); 1204 $form = $crawler->filter('form[name=search]')->form();
1151 $data = [ 1205 $data = [
1152 'search_entry[term]' => 'manège', 1206 'search_entry[term]' => 'manège',
@@ -1155,7 +1209,7 @@ class EntryControllerTest extends WallabagCoreTestCase
1155 $crawler = $client->submit($form, $data); 1209 $crawler = $client->submit($form, $data);
1156 1210
1157 $this->assertCount(1, $crawler->filter('div[class=entry]')); 1211 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1158 $client->request('GET', '/delete/'.$content->getId()); 1212 $client->request('GET', '/delete/'.$entry->getId());
1159 1213
1160 // test on list of all articles 1214 // test on list of all articles
1161 $crawler = $client->request('GET', '/all/list'); 1215 $crawler = $client->request('GET', '/all/list');
@@ -1170,6 +1224,13 @@ class EntryControllerTest extends WallabagCoreTestCase
1170 $this->assertCount(0, $crawler->filter('div[class=entry]')); 1224 $this->assertCount(0, $crawler->filter('div[class=entry]'));
1171 1225
1172 // test url search on list of all articles 1226 // test url search on list of all articles
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
1173 $crawler = $client->request('GET', '/all/list'); 1234 $crawler = $client->request('GET', '/all/list');
1174 1235
1175 $form = $crawler->filter('form[name=search]')->form(); 1236 $form = $crawler->filter('form[name=search]')->form();