aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php6
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php151
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php26
-rw-r--r--tests/Wallabag/CoreBundle/Controller/IgnoreOriginInstanceRuleControllerTest.php148
-rw-r--r--tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php127
-rw-r--r--tests/Wallabag/CoreBundle/Helper/RuleBasedIgnoreOriginProcessorTest.php212
6 files changed, 636 insertions, 34 deletions
diff --git a/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php b/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php
index c4bd6dac..a0e2939c 100644
--- a/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php
+++ b/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php
@@ -45,6 +45,9 @@ class ReloadEntryCommandTest extends WallabagCoreTestCase
45 $this->getEntityManager()->flush(); 45 $this->getEntityManager()->flush();
46 } 46 }
47 47
48 /**
49 * @group NetworkCalls
50 */
48 public function testRunReloadEntryCommand() 51 public function testRunReloadEntryCommand()
49 { 52 {
50 $application = new Application($this->getClient()->getKernel()); 53 $application = new Application($this->getClient()->getKernel());
@@ -70,6 +73,9 @@ class ReloadEntryCommandTest extends WallabagCoreTestCase
70 $this->assertContains('Done', $tester->getDisplay()); 73 $this->assertContains('Done', $tester->getDisplay());
71 } 74 }
72 75
76 /**
77 * @group NetworkCalls
78 */
73 public function testRunReloadEntryWithUsernameCommand() 79 public function testRunReloadEntryWithUsernameCommand()
74 { 80 {
75 $application = new Application($this->getClient()->getKernel()); 81 $application = new Application($this->getClient()->getKernel());
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
index b3b3a19a..92d22267 100644
--- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
@@ -435,7 +435,6 @@ class ConfigControllerTest extends WallabagCoreTestCase
435 public function testTaggingRuleCreation() 435 public function testTaggingRuleCreation()
436 { 436 {
437 $this->logInAs('admin'); 437 $this->logInAs('admin');
438 $this->useTheme('baggy');
439 $client = $this->getClient(); 438 $client = $this->getClient();
440 439
441 $crawler = $client->request('GET', '/config'); 440 $crawler = $client->request('GET', '/config');
@@ -457,7 +456,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
457 456
458 $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]); 457 $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]);
459 458
460 $editLink = $crawler->filter('.mode_edit')->last()->link(); 459 $editLink = $crawler->filter('div[id=set5] a.mode_edit')->last()->link();
461 460
462 $crawler = $client->click($editLink); 461 $crawler = $client->click($editLink);
463 $this->assertSame(302, $client->getResponse()->getStatusCode()); 462 $this->assertSame(302, $client->getResponse()->getStatusCode());
@@ -482,7 +481,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
482 481
483 $this->assertContains('readingTime <= 30', $crawler->filter('body')->extract(['_text'])[0]); 482 $this->assertContains('readingTime <= 30', $crawler->filter('body')->extract(['_text'])[0]);
484 483
485 $deleteLink = $crawler->filter('.delete')->last()->link(); 484 $deleteLink = $crawler->filter('div[id=set5] a.delete')->last()->link();
486 485
487 $crawler = $client->click($deleteLink); 486 $crawler = $client->click($deleteLink);
488 $this->assertSame(302, $client->getResponse()->getStatusCode()); 487 $this->assertSame(302, $client->getResponse()->getStatusCode());
@@ -574,11 +573,11 @@ class ConfigControllerTest extends WallabagCoreTestCase
574 ->getRepository('WallabagCoreBundle:TaggingRule') 573 ->getRepository('WallabagCoreBundle:TaggingRule')
575 ->findAll()[0]; 574 ->findAll()[0];
576 575
577 $crawler = $client->request('GET', '/tagging-rule/edit/' . $rule->getId()); 576 $crawler = $client->request('GET', '/tagging-rule/delete/' . $rule->getId());
578 577
579 $this->assertSame(403, $client->getResponse()->getStatusCode()); 578 $this->assertSame(403, $client->getResponse()->getStatusCode());
580 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); 579 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
581 $this->assertContains('You can not access this tagging rule', $body[0]); 580 $this->assertContains('You can not access this rule', $body[0]);
582 } 581 }
583 582
584 public function testEditingTaggingRuleFromAnOtherUser() 583 public function testEditingTaggingRuleFromAnOtherUser()
@@ -594,7 +593,144 @@ class ConfigControllerTest extends WallabagCoreTestCase
594 593
595 $this->assertSame(403, $client->getResponse()->getStatusCode()); 594 $this->assertSame(403, $client->getResponse()->getStatusCode());
596 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); 595 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
597 $this->assertContains('You can not access this tagging rule', $body[0]); 596 $this->assertContains('You can not access this rule', $body[0]);
597 }
598
599 public function testIgnoreOriginRuleCreation()
600 {
601 $this->logInAs('admin');
602 $client = $this->getClient();
603
604 $crawler = $client->request('GET', '/config');
605
606 $this->assertSame(200, $client->getResponse()->getStatusCode());
607
608 $form = $crawler->filter('button[id=ignore_origin_user_rule_save]')->form();
609
610 $data = [
611 'ignore_origin_user_rule[rule]' => 'host = "example.com"',
612 ];
613
614 $client->submit($form, $data);
615
616 $this->assertSame(302, $client->getResponse()->getStatusCode());
617
618 $crawler = $client->followRedirect();
619
620 $this->assertContains('flashes.config.notice.ignore_origin_rules_updated', $crawler->filter('body')->extract(['_text'])[0]);
621
622 $editLink = $crawler->filter('div[id=set6] a.mode_edit')->last()->link();
623
624 $crawler = $client->click($editLink);
625 $this->assertSame(302, $client->getResponse()->getStatusCode());
626 $this->assertContains('?ignore-origin-user-rule=', $client->getResponse()->headers->get('location'));
627
628 $crawler = $client->followRedirect();
629
630 $form = $crawler->filter('button[id=ignore_origin_user_rule_save]')->form();
631
632 $data = [
633 'ignore_origin_user_rule[rule]' => 'host = "example.org"',
634 ];
635
636 $client->submit($form, $data);
637
638 $this->assertSame(302, $client->getResponse()->getStatusCode());
639
640 $crawler = $client->followRedirect();
641
642 $this->assertContains('flashes.config.notice.ignore_origin_rules_updated', $crawler->filter('body')->extract(['_text'])[0]);
643
644 $this->assertContains('host = "example.org"', $crawler->filter('body')->extract(['_text'])[0]);
645
646 $deleteLink = $crawler->filter('div[id=set6] a.delete')->last()->link();
647
648 $crawler = $client->click($deleteLink);
649 $this->assertSame(302, $client->getResponse()->getStatusCode());
650
651 $crawler = $client->followRedirect();
652 $this->assertContains('flashes.config.notice.ignore_origin_rules_deleted', $crawler->filter('body')->extract(['_text'])[0]);
653 }
654
655 public function dataForIgnoreOriginRuleCreationFail()
656 {
657 return [
658 [
659 [
660 'ignore_origin_user_rule[rule]' => 'foo = "bar"',
661 ],
662 [
663 'The variable',
664 'does not exist.',
665 ],
666 ],
667 [
668 [
669 'ignore_origin_user_rule[rule]' => '_all != "none"',
670 ],
671 [
672 'The operator',
673 'does not exist.',
674 ],
675 ],
676 ];
677 }
678
679 /**
680 * @dataProvider dataForIgnoreOriginRuleCreationFail
681 */
682 public function testIgnoreOriginRuleCreationFail($data, $messages)
683 {
684 $this->logInAs('admin');
685 $client = $this->getClient();
686
687 $crawler = $client->request('GET', '/config');
688
689 $this->assertSame(200, $client->getResponse()->getStatusCode());
690
691 $form = $crawler->filter('button[id=ignore_origin_user_rule_save]')->form();
692
693 $crawler = $client->submit($form, $data);
694
695 $this->assertSame(200, $client->getResponse()->getStatusCode());
696
697 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
698
699 foreach ($messages as $message) {
700 $this->assertContains($message, $body[0]);
701 }
702 }
703
704 public function testDeletingIgnoreOriginRuleFromAnOtherUser()
705 {
706 $this->logInAs('bob');
707 $client = $this->getClient();
708
709 $rule = $client->getContainer()->get('doctrine.orm.entity_manager')
710 ->getRepository('WallabagCoreBundle:IgnoreOriginUserRule')
711 ->findAll()[0];
712
713 $crawler = $client->request('GET', '/ignore-origin-user-rule/edit/' . $rule->getId());
714
715 $this->assertSame(403, $client->getResponse()->getStatusCode());
716 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
717 $this->assertContains('You can not access this rule', $body[0]);
718 }
719
720 public function testEditingIgnoreOriginRuleFromAnOtherUser()
721 {
722 $this->logInAs('bob');
723 $client = $this->getClient();
724
725 $rule = $client->getContainer()->get('doctrine.orm.entity_manager')
726 ->getRepository('WallabagCoreBundle:IgnoreOriginUserRule')
727 ->findAll()[0];
728
729 $crawler = $client->request('GET', '/ignore-origin-user-rule/edit/' . $rule->getId());
730
731 $this->assertSame(403, $client->getResponse()->getStatusCode());
732 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
733 $this->assertContains('You can not access this rule', $body[0]);
598 } 734 }
599 735
600 public function testDemoMode() 736 public function testDemoMode()
@@ -676,6 +812,9 @@ class ConfigControllerTest extends WallabagCoreTestCase
676 $em->flush(); 812 $em->flush();
677 } 813 }
678 814
815 /**
816 * @group NetworkCalls
817 */
679 public function testDeleteAccount() 818 public function testDeleteAccount()
680 { 819 {
681 $client = $this->getClient(); 820 $client = $this->getClient();
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index 5b806830..0aa562d8 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -40,6 +40,9 @@ class EntryControllerTest extends WallabagCoreTestCase
40 $this->assertContains('login', $client->getResponse()->headers->get('location')); 40 $this->assertContains('login', $client->getResponse()->headers->get('location'));
41 } 41 }
42 42
43 /**
44 * @group NetworkCalls
45 */
43 public function testQuickstart() 46 public function testQuickstart()
44 { 47 {
45 $this->logInAs('empty'); 48 $this->logInAs('empty');
@@ -87,6 +90,9 @@ class EntryControllerTest extends WallabagCoreTestCase
87 $this->assertCount(1, $crawler->filter('form[name=entry]')); 90 $this->assertCount(1, $crawler->filter('form[name=entry]'));
88 } 91 }
89 92
93 /**
94 * @group NetworkCalls
95 */
90 public function testPostNewViaBookmarklet() 96 public function testPostNewViaBookmarklet()
91 { 97 {
92 $this->logInAs('admin'); 98 $this->logInAs('admin');
@@ -131,7 +137,7 @@ class EntryControllerTest extends WallabagCoreTestCase
131 } 137 }
132 138
133 /** 139 /**
134 * This test will require an internet connection. 140 * @group NetworkCalls
135 */ 141 */
136 public function testPostNewOk() 142 public function testPostNewOk()
137 { 143 {
@@ -169,6 +175,9 @@ class EntryControllerTest extends WallabagCoreTestCase
169 $client->getContainer()->get('craue_config')->set('store_article_headers', 0); 175 $client->getContainer()->get('craue_config')->set('store_article_headers', 0);
170 } 176 }
171 177
178 /**
179 * @group NetworkCalls
180 */
172 public function testPostWithMultipleAuthors() 181 public function testPostWithMultipleAuthors()
173 { 182 {
174 $url = 'https://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768'; 183 $url = 'https://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768';
@@ -229,6 +238,9 @@ class EntryControllerTest extends WallabagCoreTestCase
229 $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); 238 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
230 } 239 }
231 240
241 /**
242 * @group NetworkCalls
243 */
232 public function testPostNewOkUrlExistWithAccent() 244 public function testPostNewOkUrlExistWithAccent()
233 { 245 {
234 $this->logInAs('admin'); 246 $this->logInAs('admin');
@@ -265,7 +277,7 @@ class EntryControllerTest extends WallabagCoreTestCase
265 } 277 }
266 278
267 /** 279 /**
268 * This test will require an internet connection. 280 * @group NetworkCalls
269 */ 281 */
270 public function testPostNewOkUrlExistWithRedirection() 282 public function testPostNewOkUrlExistWithRedirection()
271 { 283 {
@@ -303,7 +315,7 @@ class EntryControllerTest extends WallabagCoreTestCase
303 } 315 }
304 316
305 /** 317 /**
306 * This test will require an internet connection. 318 * @group NetworkCalls
307 */ 319 */
308 public function testPostNewThatWillBeTagged() 320 public function testPostNewThatWillBeTagged()
309 { 321 {
@@ -430,7 +442,7 @@ class EntryControllerTest extends WallabagCoreTestCase
430 } 442 }
431 443
432 /** 444 /**
433 * This test will require an internet connection. 445 * @group NetworkCalls
434 */ 446 */
435 public function testReload() 447 public function testReload()
436 { 448 {
@@ -1056,6 +1068,9 @@ class EntryControllerTest extends WallabagCoreTestCase
1056 $this->assertSame(404, $client->getResponse()->getStatusCode()); 1068 $this->assertSame(404, $client->getResponse()->getStatusCode());
1057 } 1069 }
1058 1070
1071 /**
1072 * @group NetworkCalls
1073 */
1059 public function testNewEntryWithDownloadImagesEnabled() 1074 public function testNewEntryWithDownloadImagesEnabled()
1060 { 1075 {
1061 $this->downloadImagesEnabled = true; 1076 $this->downloadImagesEnabled = true;
@@ -1383,6 +1398,7 @@ class EntryControllerTest extends WallabagCoreTestCase
1383 1398
1384 /** 1399 /**
1385 * @dataProvider dataForLanguage 1400 * @dataProvider dataForLanguage
1401 * @group NetworkCalls
1386 */ 1402 */
1387 public function testLanguageValidation($url, $expectedLanguage) 1403 public function testLanguageValidation($url, $expectedLanguage)
1388 { 1404 {
@@ -1414,7 +1430,7 @@ class EntryControllerTest extends WallabagCoreTestCase
1414 } 1430 }
1415 1431
1416 /** 1432 /**
1417 * This test will require an internet connection. 1433 * @group NetworkCalls
1418 */ 1434 */
1419 public function testRestrictedArticle() 1435 public function testRestrictedArticle()
1420 { 1436 {
diff --git a/tests/Wallabag/CoreBundle/Controller/IgnoreOriginInstanceRuleControllerTest.php b/tests/Wallabag/CoreBundle/Controller/IgnoreOriginInstanceRuleControllerTest.php
new file mode 100644
index 00000000..9783cd25
--- /dev/null
+++ b/tests/Wallabag/CoreBundle/Controller/IgnoreOriginInstanceRuleControllerTest.php
@@ -0,0 +1,148 @@
1<?php
2
3namespace Tests\Wallabag\CoreBundle\Controller;
4
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6
7class IgnoreOriginInstanceRuleControllerTest extends WallabagCoreTestCase
8{
9 public function testListIgnoreOriginInstanceRule()
10 {
11 $this->logInAs('admin');
12 $client = $this->getClient();
13
14 $crawler = $client->request('GET', '/ignore-origin-instance-rules/');
15
16 $this->assertSame(200, $client->getResponse()->getStatusCode());
17
18 $body = $crawler->filter('body')->extract(['_text'])[0];
19
20 $this->assertContains('ignore_origin_instance_rule.description', $body);
21 $this->assertContains('ignore_origin_instance_rule.list.create_new_one', $body);
22 }
23
24 public function testIgnoreOriginInstanceRuleCreationEditionDeletion()
25 {
26 $this->logInAs('admin');
27 $client = $this->getClient();
28
29 // Creation
30 $crawler = $client->request('GET', '/ignore-origin-instance-rules/new');
31
32 $this->assertSame(200, $client->getResponse()->getStatusCode());
33
34 $body = $crawler->filter('body')->extract(['_text'])[0];
35
36 $this->assertContains('ignore_origin_instance_rule.new_ignore_origin_instance_rule', $body);
37 $this->assertContains('ignore_origin_instance_rule.form.back_to_list', $body);
38
39 $form = $crawler->filter('button[id=ignore_origin_instance_rule_save]')->form();
40
41 $data = [
42 'ignore_origin_instance_rule[rule]' => 'host = "foo.example.com"',
43 ];
44
45 $client->submit($form, $data);
46
47 $this->assertSame(302, $client->getResponse()->getStatusCode());
48
49 $crawler = $client->followRedirect();
50
51 $this->assertContains('flashes.ignore_origin_instance_rule.notice.added', $crawler->filter('body')->extract(['_text'])[0]);
52
53 // Edition
54 $editLink = $crawler->filter('div[id=content] table a')->last()->link();
55
56 $crawler = $client->click($editLink);
57
58 $this->assertSame(200, $client->getResponse()->getStatusCode());
59
60 $this->assertContains('foo.example.com', $crawler->filter('form[name=ignore_origin_instance_rule] input[type=text]')->extract(['value'])[0]);
61
62 $body = $crawler->filter('body')->extract(['_text'])[0];
63
64 $this->assertContains('ignore_origin_instance_rule.edit_ignore_origin_instance_rule', $body);
65 $this->assertContains('ignore_origin_instance_rule.form.back_to_list', $body);
66
67 $form = $crawler->filter('button[id=ignore_origin_instance_rule_save]')->form();
68
69 $data = [
70 'ignore_origin_instance_rule[rule]' => 'host = "bar.example.com"',
71 ];
72
73 $client->submit($form, $data);
74
75 $this->assertSame(302, $client->getResponse()->getStatusCode());
76
77 $crawler = $client->followRedirect();
78
79 $this->assertContains('flashes.ignore_origin_instance_rule.notice.updated', $crawler->filter('body')->extract(['_text'])[0]);
80
81 $editLink = $crawler->filter('div[id=content] table a')->last()->link();
82
83 $crawler = $client->click($editLink);
84
85 $this->assertSame(200, $client->getResponse()->getStatusCode());
86
87 $this->assertContains('bar.example.com', $crawler->filter('form[name=ignore_origin_instance_rule] input[type=text]')->extract(['value'])[0]);
88
89 $deleteForm = $crawler->filter('body')->selectButton('ignore_origin_instance_rule.form.delete')->form();
90
91 $client->submit($deleteForm, []);
92
93 $this->assertSame(302, $client->getResponse()->getStatusCode());
94
95 $crawler = $client->followRedirect();
96
97 $this->assertContains('flashes.ignore_origin_instance_rule.notice.deleted', $crawler->filter('body')->extract(['_text'])[0]);
98 }
99
100 public function dataForIgnoreOriginInstanceRuleCreationFail()
101 {
102 return [
103 [
104 [
105 'ignore_origin_instance_rule[rule]' => 'foo = "bar"',
106 ],
107 [
108 'The variable',
109 'does not exist.',
110 ],
111 ],
112 [
113 [
114 'ignore_origin_instance_rule[rule]' => '_all != "none"',
115 ],
116 [
117 'The operator',
118 'does not exist.',
119 ],
120 ],
121 ];
122 }
123
124 /**
125 * @dataProvider dataForIgnoreOriginInstanceRuleCreationFail
126 */
127 public function testIgnoreOriginInstanceRuleCreationFail($data, $messages)
128 {
129 $this->logInAs('admin');
130 $client = $this->getClient();
131
132 $crawler = $client->request('GET', '/ignore-origin-instance-rules/new');
133
134 $this->assertSame(200, $client->getResponse()->getStatusCode());
135
136 $form = $crawler->filter('button[id=ignore_origin_instance_rule_save]')->form();
137
138 $crawler = $client->submit($form, $data);
139
140 $this->assertSame(200, $client->getResponse()->getStatusCode());
141
142 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
143
144 foreach ($messages as $message) {
145 $this->assertContains($message, $body[0]);
146 }
147 }
148}
diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
index 9ce72c79..a65ac17c 100644
--- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
+++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
@@ -12,6 +12,7 @@ use Symfony\Component\Validator\ConstraintViolationList;
12use Symfony\Component\Validator\Validator\RecursiveValidator; 12use Symfony\Component\Validator\Validator\RecursiveValidator;
13use Wallabag\CoreBundle\Entity\Entry; 13use Wallabag\CoreBundle\Entity\Entry;
14use Wallabag\CoreBundle\Helper\ContentProxy; 14use Wallabag\CoreBundle\Helper\ContentProxy;
15use Wallabag\CoreBundle\Helper\RuleBasedIgnoreOriginProcessor;
15use Wallabag\CoreBundle\Helper\RuleBasedTagger; 16use Wallabag\CoreBundle\Helper\RuleBasedTagger;
16use Wallabag\UserBundle\Entity\User; 17use Wallabag\UserBundle\Entity\User;
17 18
@@ -25,6 +26,8 @@ class ContentProxyTest extends TestCase
25 $tagger->expects($this->once()) 26 $tagger->expects($this->once())
26 ->method('tag'); 27 ->method('tag');
27 28
29 $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock();
30
28 $graby = $this->getMockBuilder('Graby\Graby') 31 $graby = $this->getMockBuilder('Graby\Graby')
29 ->setMethods(['fetchContent']) 32 ->setMethods(['fetchContent'])
30 ->disableOriginalConstructor() 33 ->disableOriginalConstructor()
@@ -42,7 +45,7 @@ class ContentProxyTest extends TestCase
42 'language' => '', 45 'language' => '',
43 ]); 46 ]);
44 47
45 $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); 48 $proxy = new ContentProxy($graby, $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage);
46 $entry = new Entry(new User()); 49 $entry = new Entry(new User());
47 $proxy->updateEntry($entry, 'http://user@:80'); 50 $proxy->updateEntry($entry, 'http://user@:80');
48 51
@@ -62,6 +65,8 @@ class ContentProxyTest extends TestCase
62 $tagger->expects($this->once()) 65 $tagger->expects($this->once())
63 ->method('tag'); 66 ->method('tag');
64 67
68 $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock();
69
65 $graby = $this->getMockBuilder('Graby\Graby') 70 $graby = $this->getMockBuilder('Graby\Graby')
66 ->setMethods(['fetchContent']) 71 ->setMethods(['fetchContent'])
67 ->disableOriginalConstructor() 72 ->disableOriginalConstructor()
@@ -79,7 +84,7 @@ class ContentProxyTest extends TestCase
79 'language' => '', 84 'language' => '',
80 ]); 85 ]);
81 86
82 $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); 87 $proxy = new ContentProxy($graby, $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage);
83 $entry = new Entry(new User()); 88 $entry = new Entry(new User());
84 $proxy->updateEntry($entry, 'http://0.0.0.0'); 89 $proxy->updateEntry($entry, 'http://0.0.0.0');
85 90
@@ -99,6 +104,8 @@ class ContentProxyTest extends TestCase
99 $tagger->expects($this->once()) 104 $tagger->expects($this->once())
100 ->method('tag'); 105 ->method('tag');
101 106
107 $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock();
108
102 $graby = $this->getMockBuilder('Graby\Graby') 109 $graby = $this->getMockBuilder('Graby\Graby')
103 ->setMethods(['fetchContent']) 110 ->setMethods(['fetchContent'])
104 ->disableOriginalConstructor() 111 ->disableOriginalConstructor()
@@ -118,7 +125,7 @@ class ContentProxyTest extends TestCase
118 'description' => 'desc', 125 'description' => 'desc',
119 ]); 126 ]);
120 127
121 $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); 128 $proxy = new ContentProxy($graby, $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage);
122 $entry = new Entry(new User()); 129 $entry = new Entry(new User());
123 $proxy->updateEntry($entry, 'http://domain.io'); 130 $proxy->updateEntry($entry, 'http://domain.io');
124 131
@@ -139,6 +146,10 @@ class ContentProxyTest extends TestCase
139 $tagger->expects($this->once()) 146 $tagger->expects($this->once())
140 ->method('tag'); 147 ->method('tag');
141 148
149 $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock();
150 $ruleBasedIgnoreOriginProcessor->expects($this->once())
151 ->method('process');
152
142 $graby = $this->getMockBuilder('Graby\Graby') 153 $graby = $this->getMockBuilder('Graby\Graby')
143 ->setMethods(['fetchContent']) 154 ->setMethods(['fetchContent'])
144 ->disableOriginalConstructor() 155 ->disableOriginalConstructor()
@@ -159,7 +170,7 @@ class ContentProxyTest extends TestCase
159 ], 170 ],
160 ]); 171 ]);
161 172
162 $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); 173 $proxy = new ContentProxy($graby, $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage);
163 $entry = new Entry(new User()); 174 $entry = new Entry(new User());
164 $proxy->updateEntry($entry, 'http://0.0.0.0'); 175 $proxy->updateEntry($entry, 'http://0.0.0.0');
165 176
@@ -180,6 +191,10 @@ class ContentProxyTest extends TestCase
180 $tagger->expects($this->once()) 191 $tagger->expects($this->once())
181 ->method('tag'); 192 ->method('tag');
182 193
194 $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock();
195 $ruleBasedIgnoreOriginProcessor->expects($this->once())
196 ->method('process');
197
183 $graby = $this->getMockBuilder('Graby\Graby') 198 $graby = $this->getMockBuilder('Graby\Graby')
184 ->setMethods(['fetchContent']) 199 ->setMethods(['fetchContent'])
185 ->disableOriginalConstructor() 200 ->disableOriginalConstructor()
@@ -200,7 +215,7 @@ class ContentProxyTest extends TestCase
200 ], 215 ],
201 ]); 216 ]);
202 217
203 $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); 218 $proxy = new ContentProxy($graby, $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage);
204 $entry = new Entry(new User()); 219 $entry = new Entry(new User());
205 $proxy->updateEntry($entry, 'http://0.0.0.0'); 220 $proxy->updateEntry($entry, 'http://0.0.0.0');
206 221
@@ -221,6 +236,10 @@ class ContentProxyTest extends TestCase
221 $tagger->expects($this->once()) 236 $tagger->expects($this->once())
222 ->method('tag'); 237 ->method('tag');
223 238
239 $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock();
240 $ruleBasedIgnoreOriginProcessor->expects($this->once())
241 ->method('process');
242
224 $graby = $this->getMockBuilder('Graby\Graby') 243 $graby = $this->getMockBuilder('Graby\Graby')
225 ->setMethods(['fetchContent']) 244 ->setMethods(['fetchContent'])
226 ->disableOriginalConstructor() 245 ->disableOriginalConstructor()
@@ -240,7 +259,7 @@ class ContentProxyTest extends TestCase
240 'image' => null, 259 'image' => null,
241 ]); 260 ]);
242 261
243 $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); 262 $proxy = new ContentProxy($graby, $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage);
244 $entry = new Entry(new User()); 263 $entry = new Entry(new User());
245 $proxy->updateEntry($entry, 'http://0.0.0.0'); 264 $proxy->updateEntry($entry, 'http://0.0.0.0');
246 265
@@ -261,6 +280,10 @@ class ContentProxyTest extends TestCase
261 $tagger->expects($this->once()) 280 $tagger->expects($this->once())
262 ->method('tag'); 281 ->method('tag');
263 282
283 $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock();
284 $ruleBasedIgnoreOriginProcessor->expects($this->once())
285 ->method('process');
286
264 $graby = $this->getMockBuilder('Graby\Graby') 287 $graby = $this->getMockBuilder('Graby\Graby')
265 ->setMethods(['fetchContent']) 288 ->setMethods(['fetchContent'])
266 ->disableOriginalConstructor() 289 ->disableOriginalConstructor()
@@ -280,7 +303,7 @@ class ContentProxyTest extends TestCase
280 'image' => 'http://3.3.3.3/cover.jpg', 303 'image' => 'http://3.3.3.3/cover.jpg',
281 ]); 304 ]);
282 305
283 $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); 306 $proxy = new ContentProxy($graby, $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage);
284 $entry = new Entry(new User()); 307 $entry = new Entry(new User());
285 $proxy->updateEntry($entry, 'http://0.0.0.0'); 308 $proxy->updateEntry($entry, 'http://0.0.0.0');
286 309
@@ -301,6 +324,10 @@ class ContentProxyTest extends TestCase
301 $tagger->expects($this->once()) 324 $tagger->expects($this->once())
302 ->method('tag'); 325 ->method('tag');
303 326
327 $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock();
328 $ruleBasedIgnoreOriginProcessor->expects($this->once())
329 ->method('process');
330
304 $validator = $this->getValidator(false); 331 $validator = $this->getValidator(false);
305 $validator->expects($this->once()) 332 $validator->expects($this->once())
306 ->method('validate') 333 ->method('validate')
@@ -324,7 +351,7 @@ class ContentProxyTest extends TestCase
324 ], 351 ],
325 ]); 352 ]);
326 353
327 $proxy = new ContentProxy($graby, $tagger, $validator, $this->getLogger(), $this->fetchingErrorMessage); 354 $proxy = new ContentProxy($graby, $tagger, $ruleBasedIgnoreOriginProcessor, $validator, $this->getLogger(), $this->fetchingErrorMessage);
328 $entry = new Entry(new User()); 355 $entry = new Entry(new User());
329 $proxy->updateEntry($entry, 'http://0.0.0.0'); 356 $proxy->updateEntry($entry, 'http://0.0.0.0');
330 357
@@ -344,6 +371,10 @@ class ContentProxyTest extends TestCase
344 $tagger->expects($this->once()) 371 $tagger->expects($this->once())
345 ->method('tag'); 372 ->method('tag');
346 373
374 $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock();
375 $ruleBasedIgnoreOriginProcessor->expects($this->once())
376 ->method('process');
377
347 $validator = $this->getValidator(false); 378 $validator = $this->getValidator(false);
348 $validator->expects($this->exactly(2)) 379 $validator->expects($this->exactly(2))
349 ->method('validate') 380 ->method('validate')
@@ -372,7 +403,7 @@ class ContentProxyTest extends TestCase
372 'image' => 'https://', 403 'image' => 'https://',
373 ]); 404 ]);
374 405
375 $proxy = new ContentProxy($graby, $tagger, $validator, $this->getLogger(), $this->fetchingErrorMessage); 406 $proxy = new ContentProxy($graby, $tagger, $ruleBasedIgnoreOriginProcessor, $validator, $this->getLogger(), $this->fetchingErrorMessage);
376 $entry = new Entry(new User()); 407 $entry = new Entry(new User());
377 $proxy->updateEntry($entry, 'http://0.0.0.0'); 408 $proxy->updateEntry($entry, 'http://0.0.0.0');
378 409
@@ -393,7 +424,11 @@ class ContentProxyTest extends TestCase
393 $tagger->expects($this->once()) 424 $tagger->expects($this->once())
394 ->method('tag'); 425 ->method('tag');
395 426
396 $proxy = new ContentProxy((new Graby()), $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage, true); 427 $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock();
428 $ruleBasedIgnoreOriginProcessor->expects($this->once())
429 ->method('process');
430
431 $proxy = new ContentProxy((new Graby()), $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage, true);
397 $entry = new Entry(new User()); 432 $entry = new Entry(new User());
398 $proxy->updateEntry( 433 $proxy->updateEntry(
399 $entry, 434 $entry,
@@ -433,10 +468,12 @@ class ContentProxyTest extends TestCase
433 $tagger->expects($this->once()) 468 $tagger->expects($this->once())
434 ->method('tag'); 469 ->method('tag');
435 470
471 $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock();
472
436 $logHandler = new TestHandler(); 473 $logHandler = new TestHandler();
437 $logger = new Logger('test', [$logHandler]); 474 $logger = new Logger('test', [$logHandler]);
438 475
439 $proxy = new ContentProxy((new Graby()), $tagger, $this->getValidator(), $logger, $this->fetchingErrorMessage); 476 $proxy = new ContentProxy((new Graby()), $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $logger, $this->fetchingErrorMessage);
440 $entry = new Entry(new User()); 477 $entry = new Entry(new User());
441 $proxy->updateEntry( 478 $proxy->updateEntry(
442 $entry, 479 $entry,
@@ -469,11 +506,13 @@ class ContentProxyTest extends TestCase
469 $tagger->expects($this->once()) 506 $tagger->expects($this->once())
470 ->method('tag'); 507 ->method('tag');
471 508
509 $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock();
510
472 $logger = new Logger('foo'); 511 $logger = new Logger('foo');
473 $handler = new TestHandler(); 512 $handler = new TestHandler();
474 $logger->pushHandler($handler); 513 $logger->pushHandler($handler);
475 514
476 $proxy = new ContentProxy((new Graby()), $tagger, $this->getValidator(), $logger, $this->fetchingErrorMessage); 515 $proxy = new ContentProxy((new Graby()), $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $logger, $this->fetchingErrorMessage);
477 $entry = new Entry(new User()); 516 $entry = new Entry(new User());
478 $proxy->updateEntry( 517 $proxy->updateEntry(
479 $entry, 518 $entry,
@@ -512,7 +551,9 @@ class ContentProxyTest extends TestCase
512 ->method('tag') 551 ->method('tag')
513 ->will($this->throwException(new \Exception())); 552 ->will($this->throwException(new \Exception()));
514 553
515 $proxy = new ContentProxy((new Graby()), $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); 554 $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock();
555
556 $proxy = new ContentProxy((new Graby()), $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage);
516 $entry = new Entry(new User()); 557 $entry = new Entry(new User());
517 $proxy->updateEntry( 558 $proxy->updateEntry(
518 $entry, 559 $entry,
@@ -554,7 +595,9 @@ class ContentProxyTest extends TestCase
554 $tagger->expects($this->once()) 595 $tagger->expects($this->once())
555 ->method('tag'); 596 ->method('tag');
556 597
557 $proxy = new ContentProxy((new Graby()), $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); 598 $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock();
599
600 $proxy = new ContentProxy((new Graby()), $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage);
558 $entry = new Entry(new User()); 601 $entry = new Entry(new User());
559 $proxy->updateEntry( 602 $proxy->updateEntry(
560 $entry, 603 $entry,
@@ -590,6 +633,8 @@ class ContentProxyTest extends TestCase
590 $tagger->expects($this->once()) 633 $tagger->expects($this->once())
591 ->method('tag'); 634 ->method('tag');
592 635
636 $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock();
637
593 $graby = $this->getMockBuilder('Graby\Graby') 638 $graby = $this->getMockBuilder('Graby\Graby')
594 ->setMethods(['fetchContent']) 639 ->setMethods(['fetchContent'])
595 ->disableOriginalConstructor() 640 ->disableOriginalConstructor()
@@ -607,7 +652,7 @@ class ContentProxyTest extends TestCase
607 ], 652 ],
608 ]); 653 ]);
609 654
610 $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); 655 $proxy = new ContentProxy($graby, $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage);
611 $entry = new Entry(new User()); 656 $entry = new Entry(new User());
612 $proxy->updateEntry($entry, 'http://0.0.0.0'); 657 $proxy->updateEntry($entry, 'http://0.0.0.0');
613 658
@@ -631,6 +676,8 @@ class ContentProxyTest extends TestCase
631 $tagger->expects($this->once()) 676 $tagger->expects($this->once())
632 ->method('tag'); 677 ->method('tag');
633 678
679 $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock();
680
634 $graby = $this->getMockBuilder('Graby\Graby') 681 $graby = $this->getMockBuilder('Graby\Graby')
635 ->setMethods(['fetchContent']) 682 ->setMethods(['fetchContent'])
636 ->disableOriginalConstructor() 683 ->disableOriginalConstructor()
@@ -648,7 +695,7 @@ class ContentProxyTest extends TestCase
648 'language' => '', 695 'language' => '',
649 ]); 696 ]);
650 697
651 $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); 698 $proxy = new ContentProxy($graby, $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage);
652 $entry = new Entry(new User()); 699 $entry = new Entry(new User());
653 $proxy->updateEntry($entry, 'http://0.0.0.0'); 700 $proxy->updateEntry($entry, 'http://0.0.0.0');
654 701
@@ -668,6 +715,8 @@ class ContentProxyTest extends TestCase
668 $tagger->expects($this->once()) 715 $tagger->expects($this->once())
669 ->method('tag'); 716 ->method('tag');
670 717
718 $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock();
719
671 $graby = $this->getMockBuilder('Graby\Graby') 720 $graby = $this->getMockBuilder('Graby\Graby')
672 ->setMethods(['fetchContent']) 721 ->setMethods(['fetchContent'])
673 ->disableOriginalConstructor() 722 ->disableOriginalConstructor()
@@ -685,7 +734,7 @@ class ContentProxyTest extends TestCase
685 'language' => '', 734 'language' => '',
686 ]); 735 ]);
687 736
688 $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); 737 $proxy = new ContentProxy($graby, $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage);
689 $entry = new Entry(new User()); 738 $entry = new Entry(new User());
690 $proxy->updateEntry($entry, 'http://0.0.0.0'); 739 $proxy->updateEntry($entry, 'http://0.0.0.0');
691 740
@@ -704,6 +753,8 @@ class ContentProxyTest extends TestCase
704 $tagger->expects($this->once()) 753 $tagger->expects($this->once())
705 ->method('tag'); 754 ->method('tag');
706 755
756 $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock();
757
707 $graby = $this->getMockBuilder('Graby\Graby') 758 $graby = $this->getMockBuilder('Graby\Graby')
708 ->setMethods(['fetchContent']) 759 ->setMethods(['fetchContent'])
709 ->disableOriginalConstructor() 760 ->disableOriginalConstructor()
@@ -721,7 +772,7 @@ class ContentProxyTest extends TestCase
721 'language' => '', 772 'language' => '',
722 ]); 773 ]);
723 774
724 $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); 775 $proxy = new ContentProxy($graby, $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage);
725 $entry = new Entry(new User()); 776 $entry = new Entry(new User());
726 $proxy->updateEntry($entry, 'http://0.0.0.0'); 777 $proxy->updateEntry($entry, 'http://0.0.0.0');
727 778
@@ -740,6 +791,8 @@ class ContentProxyTest extends TestCase
740 $tagger->expects($this->once()) 791 $tagger->expects($this->once())
741 ->method('tag'); 792 ->method('tag');
742 793
794 $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock();
795
743 $graby = $this->getMockBuilder('Graby\Graby') 796 $graby = $this->getMockBuilder('Graby\Graby')
744 ->setMethods(['fetchContent']) 797 ->setMethods(['fetchContent'])
745 ->disableOriginalConstructor() 798 ->disableOriginalConstructor()
@@ -757,7 +810,7 @@ class ContentProxyTest extends TestCase
757 'language' => '', 810 'language' => '',
758 ]); 811 ]);
759 812
760 $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); 813 $proxy = new ContentProxy($graby, $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage);
761 $entry = new Entry(new User()); 814 $entry = new Entry(new User());
762 $proxy->updateEntry($entry, 'http://0.0.0.0'); 815 $proxy->updateEntry($entry, 'http://0.0.0.0');
763 816
@@ -776,6 +829,8 @@ class ContentProxyTest extends TestCase
776 $tagger->expects($this->once()) 829 $tagger->expects($this->once())
777 ->method('tag'); 830 ->method('tag');
778 831
832 $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock();
833
779 $graby = $this->getMockBuilder('Graby\Graby') 834 $graby = $this->getMockBuilder('Graby\Graby')
780 ->setMethods(['fetchContent']) 835 ->setMethods(['fetchContent'])
781 ->disableOriginalConstructor() 836 ->disableOriginalConstructor()
@@ -793,7 +848,7 @@ class ContentProxyTest extends TestCase
793 'language' => '', 848 'language' => '',
794 ]); 849 ]);
795 850
796 $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); 851 $proxy = new ContentProxy($graby, $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage);
797 $entry = new Entry(new User()); 852 $entry = new Entry(new User());
798 $proxy->updateEntry($entry, 'http://0.0.0.0'); 853 $proxy->updateEntry($entry, 'http://0.0.0.0');
799 854
@@ -813,6 +868,8 @@ class ContentProxyTest extends TestCase
813 $tagger->expects($this->once()) 868 $tagger->expects($this->once())
814 ->method('tag'); 869 ->method('tag');
815 870
871 $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock();
872
816 $graby = $this->getMockBuilder('Graby\Graby') 873 $graby = $this->getMockBuilder('Graby\Graby')
817 ->setMethods(['fetchContent']) 874 ->setMethods(['fetchContent'])
818 ->disableOriginalConstructor() 875 ->disableOriginalConstructor()
@@ -830,7 +887,7 @@ class ContentProxyTest extends TestCase
830 'language' => '', 887 'language' => '',
831 ]); 888 ]);
832 889
833 $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); 890 $proxy = new ContentProxy($graby, $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage);
834 $entry = new Entry(new User()); 891 $entry = new Entry(new User());
835 $proxy->updateEntry($entry, 'http://0.0.0.0'); 892 $proxy->updateEntry($entry, 'http://0.0.0.0');
836 893
@@ -850,6 +907,7 @@ class ContentProxyTest extends TestCase
850 * $expected_entry_url 907 * $expected_entry_url
851 * $expected_origin_url 908 * $expected_origin_url
852 * $expected_domain 909 * $expected_domain
910 * $processor_result
853 */ 911 */
854 public function dataForChangedUrl() 912 public function dataForChangedUrl()
855 { 913 {
@@ -861,6 +919,7 @@ class ContentProxyTest extends TestCase
861 'http://1.1.1.1', 919 'http://1.1.1.1',
862 'http://0.0.0.0', 920 'http://0.0.0.0',
863 '1.1.1.1', 921 '1.1.1.1',
922 false,
864 ], 923 ],
865 'origin already set' => [ 924 'origin already set' => [
866 'http://0.0.0.0', 925 'http://0.0.0.0',
@@ -869,6 +928,7 @@ class ContentProxyTest extends TestCase
869 'http://1.1.1.1', 928 'http://1.1.1.1',
870 'http://hello', 929 'http://hello',
871 '1.1.1.1', 930 '1.1.1.1',
931 false,
872 ], 932 ],
873 'trailing slash' => [ 933 'trailing slash' => [
874 'https://example.com/hello-world', 934 'https://example.com/hello-world',
@@ -877,6 +937,7 @@ class ContentProxyTest extends TestCase
877 'https://example.com/hello-world/', 937 'https://example.com/hello-world/',
878 null, 938 null,
879 'example.com', 939 'example.com',
940 false,
880 ], 941 ],
881 'query string in fetched content' => [ 942 'query string in fetched content' => [
882 'https://example.org/hello', 943 'https://example.org/hello',
@@ -885,6 +946,7 @@ class ContentProxyTest extends TestCase
885 'https://example.org/hello?world=1', 946 'https://example.org/hello?world=1',
886 'https://example.org/hello', 947 'https://example.org/hello',
887 'example.org', 948 'example.org',
949 false,
888 ], 950 ],
889 'fragment in fetched content' => [ 951 'fragment in fetched content' => [
890 'https://example.org/hello', 952 'https://example.org/hello',
@@ -893,6 +955,7 @@ class ContentProxyTest extends TestCase
893 'https://example.org/hello', 955 'https://example.org/hello',
894 null, 956 null,
895 'example.org', 957 'example.org',
958 false,
896 ], 959 ],
897 'fragment and query string in fetched content' => [ 960 'fragment and query string in fetched content' => [
898 'https://example.org/hello', 961 'https://example.org/hello',
@@ -901,6 +964,7 @@ class ContentProxyTest extends TestCase
901 'https://example.org/hello?foo#world', 964 'https://example.org/hello?foo#world',
902 'https://example.org/hello', 965 'https://example.org/hello',
903 'example.org', 966 'example.org',
967 false,
904 ], 968 ],
905 'different path and query string in fetch content' => [ 969 'different path and query string in fetch content' => [
906 'https://example.org/hello', 970 'https://example.org/hello',
@@ -909,6 +973,7 @@ class ContentProxyTest extends TestCase
909 'https://example.org/world?foo', 973 'https://example.org/world?foo',
910 'https://example.org/hello', 974 'https://example.org/hello',
911 'example.org', 975 'example.org',
976 false,
912 ], 977 ],
913 'feedproxy ignore list test' => [ 978 'feedproxy ignore list test' => [
914 'http://feedproxy.google.com/~r/Wallabag/~3/helloworld', 979 'http://feedproxy.google.com/~r/Wallabag/~3/helloworld',
@@ -917,6 +982,7 @@ class ContentProxyTest extends TestCase
917 'https://example.org/hello-wallabag', 982 'https://example.org/hello-wallabag',
918 null, 983 null,
919 'example.org', 984 'example.org',
985 true,
920 ], 986 ],
921 'feedproxy ignore list test with origin url already set' => [ 987 'feedproxy ignore list test with origin url already set' => [
922 'http://feedproxy.google.com/~r/Wallabag/~3/helloworld', 988 'http://feedproxy.google.com/~r/Wallabag/~3/helloworld',
@@ -925,6 +991,7 @@ class ContentProxyTest extends TestCase
925 'https://example.org/hello-wallabag', 991 'https://example.org/hello-wallabag',
926 'https://example.org/this-is-source', 992 'https://example.org/this-is-source',
927 'example.org', 993 'example.org',
994 true,
928 ], 995 ],
929 'lemonde ignore pattern test' => [ 996 'lemonde ignore pattern test' => [
930 'http://www.lemonde.fr/tiny/url', 997 'http://www.lemonde.fr/tiny/url',
@@ -933,6 +1000,7 @@ class ContentProxyTest extends TestCase
933 'http://example.com/hello-world', 1000 'http://example.com/hello-world',
934 null, 1001 null,
935 'example.com', 1002 'example.com',
1003 true,
936 ], 1004 ],
937 ]; 1005 ];
938 } 1006 }
@@ -940,13 +1008,18 @@ class ContentProxyTest extends TestCase
940 /** 1008 /**
941 * @dataProvider dataForChangedUrl 1009 * @dataProvider dataForChangedUrl
942 */ 1010 */
943 public function testWithChangedUrl($entry_url, $origin_url, $content_url, $expected_entry_url, $expected_origin_url, $expected_domain) 1011 public function testWithChangedUrl($entry_url, $origin_url, $content_url, $expected_entry_url, $expected_origin_url, $expected_domain, $processor_result)
944 { 1012 {
945 $tagger = $this->getTaggerMock(); 1013 $tagger = $this->getTaggerMock();
946 $tagger->expects($this->once()) 1014 $tagger->expects($this->once())
947 ->method('tag'); 1015 ->method('tag');
948 1016
949 $proxy = new ContentProxy((new Graby()), $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage, true); 1017 $ruleBasedIgnoreOriginProcessor = $this->getRuleBasedIgnoreOriginProcessorMock();
1018 $ruleBasedIgnoreOriginProcessor->expects($this->once())
1019 ->method('process')
1020 ->willReturn($processor_result);
1021
1022 $proxy = new ContentProxy((new Graby()), $tagger, $ruleBasedIgnoreOriginProcessor, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage, true);
950 $entry = new Entry(new User()); 1023 $entry = new Entry(new User());
951 $entry->setOriginUrl($origin_url); 1024 $entry->setOriginUrl($origin_url);
952 $proxy->updateEntry( 1025 $proxy->updateEntry(
@@ -1015,6 +1088,14 @@ class ContentProxyTest extends TestCase
1015 ->getMock(); 1088 ->getMock();
1016 } 1089 }
1017 1090
1091 private function getRuleBasedIgnoreOriginProcessorMock()
1092 {
1093 return $this->getMockBuilder(RuleBasedIgnoreOriginProcessor::class)
1094 ->setMethods(['process'])
1095 ->disableOriginalConstructor()
1096 ->getMock();
1097 }
1098
1018 private function getLogger() 1099 private function getLogger()
1019 { 1100 {
1020 return new NullLogger(); 1101 return new NullLogger();
diff --git a/tests/Wallabag/CoreBundle/Helper/RuleBasedIgnoreOriginProcessorTest.php b/tests/Wallabag/CoreBundle/Helper/RuleBasedIgnoreOriginProcessorTest.php
new file mode 100644
index 00000000..9e39bc81
--- /dev/null
+++ b/tests/Wallabag/CoreBundle/Helper/RuleBasedIgnoreOriginProcessorTest.php
@@ -0,0 +1,212 @@
1<?php
2
3namespace Tests\Wallabag\CoreBundle\Helper;
4
5use Monolog\Handler\TestHandler;
6use Monolog\Logger;
7use PHPUnit\Framework\TestCase;
8use Wallabag\CoreBundle\Entity\Config;
9use Wallabag\CoreBundle\Entity\Entry;
10use Wallabag\CoreBundle\Entity\IgnoreOriginInstanceRule;
11use Wallabag\CoreBundle\Entity\IgnoreOriginUserRule;
12use Wallabag\CoreBundle\Helper\RuleBasedIgnoreOriginProcessor;
13use Wallabag\UserBundle\Entity\User;
14
15class RuleBasedIgnoreOriginProcessorTest extends TestCase
16{
17 private $rulerz;
18 private $processor;
19 private $ignoreOriginInstanceRuleRepository;
20 private $logger;
21 private $handler;
22
23 public function setUp()
24 {
25 $this->rulerz = $this->getRulerZMock();
26 $this->logger = $this->getLogger();
27 $this->ignoreOriginInstanceRuleRepository = $this->getIgnoreOriginInstanceRuleRepositoryMock();
28 $this->handler = new TestHandler();
29 $this->logger->pushHandler($this->handler);
30
31 $this->processor = new RuleBasedIgnoreOriginProcessor($this->rulerz, $this->logger, $this->ignoreOriginInstanceRuleRepository);
32 }
33
34 public function testProcessWithNoRule()
35 {
36 $user = $this->getUser();
37 $entry = new Entry($user);
38 $entry->setUrl('http://example.com/hello-world');
39
40 $this->ignoreOriginInstanceRuleRepository
41 ->expects($this->once())
42 ->method('findAll')
43 ->willReturn([]);
44
45 $this->rulerz
46 ->expects($this->never())
47 ->method('satisfies');
48
49 $result = $this->processor->process($entry);
50
51 $this->assertFalse($result);
52 }
53
54 public function testProcessWithNoMatchingRule()
55 {
56 $userRule = $this->getIgnoreOriginUserRule('rule as string');
57 $user = $this->getUser([$userRule]);
58 $entry = new Entry($user);
59 $entry->setUrl('http://example.com/hello-world');
60
61 $this->ignoreOriginInstanceRuleRepository
62 ->expects($this->once())
63 ->method('findAll')
64 ->willReturn([]);
65
66 $this->rulerz
67 ->expects($this->once())
68 ->method('satisfies')
69 ->willReturn(false);
70
71 $result = $this->processor->process($entry);
72
73 $this->assertFalse($result);
74 }
75
76 public function testProcessWithAMatchingRule()
77 {
78 $userRule = $this->getIgnoreOriginUserRule('rule as string');
79 $user = $this->getUser([$userRule]);
80 $entry = new Entry($user);
81 $entry->setUrl('http://example.com/hello-world');
82
83 $this->ignoreOriginInstanceRuleRepository
84 ->expects($this->once())
85 ->method('findAll')
86 ->willReturn([]);
87
88 $this->rulerz
89 ->expects($this->once())
90 ->method('satisfies')
91 ->willReturn(true);
92
93 $result = $this->processor->process($entry);
94
95 $this->assertTrue($result);
96 }
97
98 public function testProcessWithAMixOfMatchingRules()
99 {
100 $userRule = $this->getIgnoreOriginUserRule('rule as string');
101 $anotherUserRule = $this->getIgnoreOriginUserRule('another rule as string');
102 $user = $this->getUser([$userRule, $anotherUserRule]);
103 $entry = new Entry($user);
104 $entry->setUrl('http://example.com/hello-world');
105
106 $this->ignoreOriginInstanceRuleRepository
107 ->expects($this->once())
108 ->method('findAll')
109 ->willReturn([]);
110
111 $this->rulerz
112 ->method('satisfies')
113 ->will($this->onConsecutiveCalls(false, true));
114
115 $result = $this->processor->process($entry);
116
117 $this->assertTrue($result);
118 }
119
120 public function testProcessWithInstanceRules()
121 {
122 $user = $this->getUser();
123 $entry = new Entry($user);
124 $entry->setUrl('http://example.com/hello-world');
125
126 $instanceRule = $this->getIgnoreOriginInstanceRule('rule as string');
127 $this->ignoreOriginInstanceRuleRepository
128 ->expects($this->once())
129 ->method('findAll')
130 ->willReturn([$instanceRule]);
131
132 $this->rulerz
133 ->expects($this->once())
134 ->method('satisfies')
135 ->willReturn(true);
136
137 $result = $this->processor->process($entry);
138
139 $this->assertTrue($result);
140 }
141
142 public function testProcessWithMixedRules()
143 {
144 $userRule = $this->getIgnoreOriginUserRule('rule as string');
145 $user = $this->getUser([$userRule]);
146 $entry = new Entry($user);
147 $entry->setUrl('http://example.com/hello-world');
148
149 $instanceRule = $this->getIgnoreOriginInstanceRule('rule as string');
150 $this->ignoreOriginInstanceRuleRepository
151 ->expects($this->once())
152 ->method('findAll')
153 ->willReturn([$instanceRule]);
154
155 $this->rulerz
156 ->method('satisfies')
157 ->will($this->onConsecutiveCalls(false, true));
158
159 $result = $this->processor->process($entry);
160
161 $this->assertTrue($result);
162 }
163
164 private function getUser(array $ignoreOriginRules = [])
165 {
166 $user = new User();
167 $config = new Config($user);
168
169 $user->setConfig($config);
170
171 foreach ($ignoreOriginRules as $rule) {
172 $config->addIgnoreOriginRule($rule);
173 }
174
175 return $user;
176 }
177
178 private function getIgnoreOriginUserRule($rule)
179 {
180 $ignoreOriginUserRule = new IgnoreOriginUserRule();
181 $ignoreOriginUserRule->setRule($rule);
182
183 return $ignoreOriginUserRule;
184 }
185
186 private function getIgnoreOriginInstanceRule($rule)
187 {
188 $ignoreOriginInstanceRule = new IgnoreOriginInstanceRule();
189 $ignoreOriginInstanceRule->setRule($rule);
190
191 return $ignoreOriginInstanceRule;
192 }
193
194 private function getRulerZMock()
195 {
196 return $this->getMockBuilder('RulerZ\RulerZ')
197 ->disableOriginalConstructor()
198 ->getMock();
199 }
200
201 private function getIgnoreOriginInstanceRuleRepositoryMock()
202 {
203 return $this->getMockBuilder('Wallabag\CoreBundle\Repository\IgnoreOriginInstanceRuleRepository')
204 ->disableOriginalConstructor()
205 ->getMock();
206 }
207
208 private function getLogger()
209 {
210 return new Logger('foo');
211 }
212}