diff options
Diffstat (limited to 'tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php')
-rw-r--r-- | tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php | 199 |
1 files changed, 152 insertions, 47 deletions
diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index 508adb1b..9ce72c79 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php | |||
@@ -36,7 +36,9 @@ class ContentProxyTest extends TestCase | |||
36 | 'html' => false, | 36 | 'html' => false, |
37 | 'title' => '', | 37 | 'title' => '', |
38 | 'url' => '', | 38 | 'url' => '', |
39 | 'content_type' => '', | 39 | 'headers' => [ |
40 | 'content-type' => '', | ||
41 | ], | ||
40 | 'language' => '', | 42 | 'language' => '', |
41 | ]); | 43 | ]); |
42 | 44 | ||
@@ -71,7 +73,9 @@ class ContentProxyTest extends TestCase | |||
71 | 'html' => false, | 73 | 'html' => false, |
72 | 'title' => '', | 74 | 'title' => '', |
73 | 'url' => '', | 75 | 'url' => '', |
74 | 'content_type' => '', | 76 | 'headers' => [ |
77 | 'content-type' => '', | ||
78 | ], | ||
75 | 'language' => '', | 79 | 'language' => '', |
76 | ]); | 80 | ]); |
77 | 81 | ||
@@ -104,15 +108,14 @@ class ContentProxyTest extends TestCase | |||
104 | ->method('fetchContent') | 108 | ->method('fetchContent') |
105 | ->willReturn([ | 109 | ->willReturn([ |
106 | 'html' => false, | 110 | 'html' => false, |
107 | 'title' => '', | 111 | 'title' => 'my title', |
108 | 'url' => '', | 112 | 'url' => '', |
109 | 'content_type' => '', | 113 | 'headers' => [ |
114 | 'content-type' => '', | ||
115 | ], | ||
110 | 'language' => '', | 116 | 'language' => '', |
111 | 'status' => '', | 117 | 'status' => '', |
112 | 'open_graph' => [ | 118 | 'description' => 'desc', |
113 | 'og_title' => 'my title', | ||
114 | 'og_description' => 'desc', | ||
115 | ], | ||
116 | ]); | 119 | ]); |
117 | 120 | ||
118 | $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); | 121 | $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); |
@@ -147,13 +150,12 @@ class ContentProxyTest extends TestCase | |||
147 | 'html' => str_repeat('this is my content', 325), | 150 | 'html' => str_repeat('this is my content', 325), |
148 | 'title' => 'this is my title', | 151 | 'title' => 'this is my title', |
149 | 'url' => 'http://1.1.1.1', | 152 | 'url' => 'http://1.1.1.1', |
150 | 'content_type' => 'text/html', | ||
151 | 'language' => 'fr', | 153 | 'language' => 'fr', |
152 | 'status' => '200', | 154 | 'status' => '200', |
153 | 'open_graph' => [ | 155 | 'description' => 'OG desc', |
154 | 'og_title' => 'my OG title', | 156 | 'image' => 'http://3.3.3.3/cover.jpg', |
155 | 'og_description' => 'OG desc', | 157 | 'headers' => [ |
156 | 'og_image' => 'http://3.3.3.3/cover.jpg', | 158 | 'content-type' => 'text/html', |
157 | ], | 159 | ], |
158 | ]); | 160 | ]); |
159 | 161 | ||
@@ -189,13 +191,12 @@ class ContentProxyTest extends TestCase | |||
189 | 'html' => str_repeat('this is my content', 325), | 191 | 'html' => str_repeat('this is my content', 325), |
190 | 'title' => 'this is my title', | 192 | 'title' => 'this is my title', |
191 | 'url' => 'http://1.1.1.1', | 193 | 'url' => 'http://1.1.1.1', |
192 | 'content_type' => 'text/html', | ||
193 | 'language' => 'fr', | 194 | 'language' => 'fr', |
194 | 'status' => '200', | 195 | 'status' => '200', |
195 | 'open_graph' => [ | 196 | 'description' => 'OG desc', |
196 | 'og_title' => 'my OG title', | 197 | 'image' => null, |
197 | 'og_description' => 'OG desc', | 198 | 'headers' => [ |
198 | 'og_image' => null, | 199 | 'content-type' => 'text/html', |
199 | ], | 200 | ], |
200 | ]); | 201 | ]); |
201 | 202 | ||
@@ -214,6 +215,86 @@ class ContentProxyTest extends TestCase | |||
214 | $this->assertSame('1.1.1.1', $entry->getDomainName()); | 215 | $this->assertSame('1.1.1.1', $entry->getDomainName()); |
215 | } | 216 | } |
216 | 217 | ||
218 | public function testWithContentAndContentImage() | ||
219 | { | ||
220 | $tagger = $this->getTaggerMock(); | ||
221 | $tagger->expects($this->once()) | ||
222 | ->method('tag'); | ||
223 | |||
224 | $graby = $this->getMockBuilder('Graby\Graby') | ||
225 | ->setMethods(['fetchContent']) | ||
226 | ->disableOriginalConstructor() | ||
227 | ->getMock(); | ||
228 | |||
229 | $graby->expects($this->any()) | ||
230 | ->method('fetchContent') | ||
231 | ->willReturn([ | ||
232 | 'html' => "<h1>Test</h1><p><img src='http://3.3.3.3/cover.jpg'/></p>", | ||
233 | 'title' => 'this is my title', | ||
234 | 'url' => 'http://1.1.1.1', | ||
235 | 'headers' => [ | ||
236 | 'content-type' => 'text/html', | ||
237 | ], | ||
238 | 'language' => 'fr', | ||
239 | 'status' => '200', | ||
240 | 'image' => null, | ||
241 | ]); | ||
242 | |||
243 | $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); | ||
244 | $entry = new Entry(new User()); | ||
245 | $proxy->updateEntry($entry, 'http://0.0.0.0'); | ||
246 | |||
247 | $this->assertSame('http://1.1.1.1', $entry->getUrl()); | ||
248 | $this->assertSame('this is my title', $entry->getTitle()); | ||
249 | $this->assertSame("<h1>Test</h1><p><img src='http://3.3.3.3/cover.jpg'/></p>", $entry->getContent()); | ||
250 | $this->assertSame('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture()); | ||
251 | $this->assertSame('text/html', $entry->getMimetype()); | ||
252 | $this->assertSame('fr', $entry->getLanguage()); | ||
253 | $this->assertSame('200', $entry->getHttpStatus()); | ||
254 | $this->assertSame(0.0, $entry->getReadingTime()); | ||
255 | $this->assertSame('1.1.1.1', $entry->getDomainName()); | ||
256 | } | ||
257 | |||
258 | public function testWithContentImageAndOgImage() | ||
259 | { | ||
260 | $tagger = $this->getTaggerMock(); | ||
261 | $tagger->expects($this->once()) | ||
262 | ->method('tag'); | ||
263 | |||
264 | $graby = $this->getMockBuilder('Graby\Graby') | ||
265 | ->setMethods(['fetchContent']) | ||
266 | ->disableOriginalConstructor() | ||
267 | ->getMock(); | ||
268 | |||
269 | $graby->expects($this->any()) | ||
270 | ->method('fetchContent') | ||
271 | ->willReturn([ | ||
272 | 'html' => "<h1>Test</h1><p><img src='http://3.3.3.3/nevermind.jpg'/></p>", | ||
273 | 'title' => 'this is my title', | ||
274 | 'url' => 'http://1.1.1.1', | ||
275 | 'headers' => [ | ||
276 | 'content-type' => 'text/html', | ||
277 | ], | ||
278 | 'language' => 'fr', | ||
279 | 'status' => '200', | ||
280 | 'image' => 'http://3.3.3.3/cover.jpg', | ||
281 | ]); | ||
282 | |||
283 | $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); | ||
284 | $entry = new Entry(new User()); | ||
285 | $proxy->updateEntry($entry, 'http://0.0.0.0'); | ||
286 | |||
287 | $this->assertSame('http://1.1.1.1', $entry->getUrl()); | ||
288 | $this->assertSame('this is my title', $entry->getTitle()); | ||
289 | $this->assertSame("<h1>Test</h1><p><img src='http://3.3.3.3/nevermind.jpg'/></p>", $entry->getContent()); | ||
290 | $this->assertSame('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture()); | ||
291 | $this->assertSame('text/html', $entry->getMimetype()); | ||
292 | $this->assertSame('fr', $entry->getLanguage()); | ||
293 | $this->assertSame('200', $entry->getHttpStatus()); | ||
294 | $this->assertSame(0.0, $entry->getReadingTime()); | ||
295 | $this->assertSame('1.1.1.1', $entry->getDomainName()); | ||
296 | } | ||
297 | |||
217 | public function testWithContentAndBadLanguage() | 298 | public function testWithContentAndBadLanguage() |
218 | { | 299 | { |
219 | $tagger = $this->getTaggerMock(); | 300 | $tagger = $this->getTaggerMock(); |
@@ -236,9 +317,11 @@ class ContentProxyTest extends TestCase | |||
236 | 'html' => str_repeat('this is my content', 325), | 317 | 'html' => str_repeat('this is my content', 325), |
237 | 'title' => 'this is my title', | 318 | 'title' => 'this is my title', |
238 | 'url' => 'http://1.1.1.1', | 319 | 'url' => 'http://1.1.1.1', |
239 | 'content_type' => 'text/html', | ||
240 | 'language' => 'dontexist', | 320 | 'language' => 'dontexist', |
241 | 'status' => '200', | 321 | 'status' => '200', |
322 | 'headers' => [ | ||
323 | 'content-type' => 'text/html', | ||
324 | ], | ||
242 | ]); | 325 | ]); |
243 | 326 | ||
244 | $proxy = new ContentProxy($graby, $tagger, $validator, $this->getLogger(), $this->fetchingErrorMessage); | 327 | $proxy = new ContentProxy($graby, $tagger, $validator, $this->getLogger(), $this->fetchingErrorMessage); |
@@ -280,14 +363,13 @@ class ContentProxyTest extends TestCase | |||
280 | 'html' => str_repeat('this is my content', 325), | 363 | 'html' => str_repeat('this is my content', 325), |
281 | 'title' => 'this is my title', | 364 | 'title' => 'this is my title', |
282 | 'url' => 'http://1.1.1.1', | 365 | 'url' => 'http://1.1.1.1', |
283 | 'content_type' => 'text/html', | 366 | 'headers' => [ |
367 | 'content-type' => 'text/html', | ||
368 | ], | ||
284 | 'language' => 'fr', | 369 | 'language' => 'fr', |
285 | 'status' => '200', | 370 | 'status' => '200', |
286 | 'open_graph' => [ | 371 | 'description' => 'OG desc', |
287 | 'og_title' => 'my OG title', | 372 | 'image' => 'https://', |
288 | 'og_description' => 'OG desc', | ||
289 | 'og_image' => 'https://', | ||
290 | ], | ||
291 | ]); | 373 | ]); |
292 | 374 | ||
293 | $proxy = new ContentProxy($graby, $tagger, $validator, $this->getLogger(), $this->fetchingErrorMessage); | 375 | $proxy = new ContentProxy($graby, $tagger, $validator, $this->getLogger(), $this->fetchingErrorMessage); |
@@ -320,12 +402,12 @@ class ContentProxyTest extends TestCase | |||
320 | 'html' => str_repeat('this is my content', 325), | 402 | 'html' => str_repeat('this is my content', 325), |
321 | 'title' => 'this is my title', | 403 | 'title' => 'this is my title', |
322 | 'url' => 'http://1.1.1.1', | 404 | 'url' => 'http://1.1.1.1', |
323 | 'content_type' => 'text/html', | ||
324 | 'language' => 'fr', | 405 | 'language' => 'fr', |
325 | 'date' => '1395635872', | 406 | 'date' => '1395635872', |
326 | 'authors' => ['Jeremy', 'Nico', 'Thomas'], | 407 | 'authors' => ['Jeremy', 'Nico', 'Thomas'], |
327 | 'all_headers' => [ | 408 | 'headers' => [ |
328 | 'Cache-Control' => 'no-cache', | 409 | 'cache-control' => 'no-cache', |
410 | 'content-type' => 'text/html', | ||
329 | ], | 411 | ], |
330 | ] | 412 | ] |
331 | ); | 413 | ); |
@@ -363,9 +445,11 @@ class ContentProxyTest extends TestCase | |||
363 | 'html' => str_repeat('this is my content', 325), | 445 | 'html' => str_repeat('this is my content', 325), |
364 | 'title' => 'this is my title', | 446 | 'title' => 'this is my title', |
365 | 'url' => 'http://1.1.1.1', | 447 | 'url' => 'http://1.1.1.1', |
366 | 'content_type' => 'text/html', | ||
367 | 'language' => 'fr', | 448 | 'language' => 'fr', |
368 | 'date' => '2016-09-08T11:55:58+0200', | 449 | 'date' => '2016-09-08T11:55:58+0200', |
450 | 'headers' => [ | ||
451 | 'content-type' => 'text/html', | ||
452 | ], | ||
369 | ] | 453 | ] |
370 | ); | 454 | ); |
371 | 455 | ||
@@ -398,9 +482,11 @@ class ContentProxyTest extends TestCase | |||
398 | 'html' => str_repeat('this is my content', 325), | 482 | 'html' => str_repeat('this is my content', 325), |
399 | 'title' => 'this is my title', | 483 | 'title' => 'this is my title', |
400 | 'url' => 'http://1.1.1.1', | 484 | 'url' => 'http://1.1.1.1', |
401 | 'content_type' => 'text/html', | ||
402 | 'language' => 'fr', | 485 | 'language' => 'fr', |
403 | 'date' => '01 02 2012', | 486 | 'date' => '01 02 2012', |
487 | 'headers' => [ | ||
488 | 'content-type' => 'text/html', | ||
489 | ], | ||
404 | ] | 490 | ] |
405 | ); | 491 | ); |
406 | 492 | ||
@@ -415,7 +501,7 @@ class ContentProxyTest extends TestCase | |||
415 | 501 | ||
416 | $records = $handler->getRecords(); | 502 | $records = $handler->getRecords(); |
417 | 503 | ||
418 | $this->assertCount(1, $records); | 504 | $this->assertCount(3, $records); |
419 | $this->assertContains('Error while defining date', $records[0]['message']); | 505 | $this->assertContains('Error while defining date', $records[0]['message']); |
420 | } | 506 | } |
421 | 507 | ||
@@ -435,8 +521,10 @@ class ContentProxyTest extends TestCase | |||
435 | 'html' => str_repeat('this is my content', 325), | 521 | 'html' => str_repeat('this is my content', 325), |
436 | 'title' => 'this is my title', | 522 | 'title' => 'this is my title', |
437 | 'url' => 'http://1.1.1.1', | 523 | 'url' => 'http://1.1.1.1', |
438 | 'content_type' => 'text/html', | ||
439 | 'language' => 'fr', | 524 | 'language' => 'fr', |
525 | 'headers' => [ | ||
526 | 'content-type' => 'text/html', | ||
527 | ], | ||
440 | ] | 528 | ] |
441 | ); | 529 | ); |
442 | 530 | ||
@@ -475,13 +563,13 @@ class ContentProxyTest extends TestCase | |||
475 | 'html' => $html, | 563 | 'html' => $html, |
476 | 'title' => 'this is my title', | 564 | 'title' => 'this is my title', |
477 | 'url' => 'http://1.1.1.1', | 565 | 'url' => 'http://1.1.1.1', |
478 | 'content_type' => 'text/html', | ||
479 | 'language' => 'fr', | 566 | 'language' => 'fr', |
480 | 'status' => '200', | 567 | 'status' => '200', |
481 | 'open_graph' => [ | 568 | //'og_title' => 'my OG title', |
482 | 'og_title' => 'my OG title', | 569 | 'description' => 'OG desc', |
483 | 'og_description' => 'OG desc', | 570 | 'image' => 'http://3.3.3.3/cover.jpg', |
484 | 'og_image' => 'http://3.3.3.3/cover.jpg', | 571 | 'headers' => [ |
572 | 'content-type' => 'text/html', | ||
485 | ], | 573 | ], |
486 | ] | 574 | ] |
487 | ); | 575 | ); |
@@ -513,9 +601,10 @@ class ContentProxyTest extends TestCase | |||
513 | 'html' => '<p><img src="http://1.1.1.1/image.jpg" /></p>', | 601 | 'html' => '<p><img src="http://1.1.1.1/image.jpg" /></p>', |
514 | 'title' => 'this is my title', | 602 | 'title' => 'this is my title', |
515 | 'url' => 'http://1.1.1.1/image.jpg', | 603 | 'url' => 'http://1.1.1.1/image.jpg', |
516 | 'content_type' => 'image/jpeg', | ||
517 | 'status' => '200', | 604 | 'status' => '200', |
518 | 'open_graph' => [], | 605 | 'headers' => [ |
606 | 'content-type' => 'image/jpeg', | ||
607 | ], | ||
519 | ]); | 608 | ]); |
520 | 609 | ||
521 | $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); | 610 | $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); |
@@ -553,7 +642,9 @@ class ContentProxyTest extends TestCase | |||
553 | 'html' => false, | 642 | 'html' => false, |
554 | 'title' => $actualTitle, | 643 | 'title' => $actualTitle, |
555 | 'url' => '', | 644 | 'url' => '', |
556 | 'content_type' => 'text/html', | 645 | 'headers' => [ |
646 | 'content-type' => 'text/html', | ||
647 | ], | ||
557 | 'language' => '', | 648 | 'language' => '', |
558 | ]); | 649 | ]); |
559 | 650 | ||
@@ -588,7 +679,9 @@ class ContentProxyTest extends TestCase | |||
588 | 'html' => false, | 679 | 'html' => false, |
589 | 'title' => $actualTitle, | 680 | 'title' => $actualTitle, |
590 | 'url' => '', | 681 | 'url' => '', |
591 | 'content_type' => 'text/html', | 682 | 'headers' => [ |
683 | 'content-type' => 'text/html', | ||
684 | ], | ||
592 | 'language' => '', | 685 | 'language' => '', |
593 | ]); | 686 | ]); |
594 | 687 | ||
@@ -622,7 +715,9 @@ class ContentProxyTest extends TestCase | |||
622 | 'html' => false, | 715 | 'html' => false, |
623 | 'title' => $actualTitle, | 716 | 'title' => $actualTitle, |
624 | 'url' => '', | 717 | 'url' => '', |
625 | 'content_type' => 'application/pdf', | 718 | 'headers' => [ |
719 | 'content-type' => 'application/pdf', | ||
720 | ], | ||
626 | 'language' => '', | 721 | 'language' => '', |
627 | ]); | 722 | ]); |
628 | 723 | ||
@@ -656,7 +751,9 @@ class ContentProxyTest extends TestCase | |||
656 | 'html' => false, | 751 | 'html' => false, |
657 | 'title' => $actualTitle, | 752 | 'title' => $actualTitle, |
658 | 'url' => '', | 753 | 'url' => '', |
659 | 'content_type' => 'application/pdf', | 754 | 'headers' => [ |
755 | 'content-type' => 'application/pdf', | ||
756 | ], | ||
660 | 'language' => '', | 757 | 'language' => '', |
661 | ]); | 758 | ]); |
662 | 759 | ||
@@ -690,7 +787,9 @@ class ContentProxyTest extends TestCase | |||
690 | 'html' => false, | 787 | 'html' => false, |
691 | 'title' => $actualTitle, | 788 | 'title' => $actualTitle, |
692 | 'url' => '', | 789 | 'url' => '', |
693 | 'content_type' => 'application/pdf', | 790 | 'headers' => [ |
791 | 'content-type' => 'application/pdf', | ||
792 | ], | ||
694 | 'language' => '', | 793 | 'language' => '', |
695 | ]); | 794 | ]); |
696 | 795 | ||
@@ -725,7 +824,9 @@ class ContentProxyTest extends TestCase | |||
725 | 'html' => false, | 824 | 'html' => false, |
726 | 'title' => $actualTitle, | 825 | 'title' => $actualTitle, |
727 | 'url' => '', | 826 | 'url' => '', |
728 | 'content_type' => 'application/pdf', | 827 | 'headers' => [ |
828 | 'content-type' => 'application/pdf', | ||
829 | ], | ||
729 | 'language' => '', | 830 | 'language' => '', |
730 | ]); | 831 | ]); |
731 | 832 | ||
@@ -855,7 +956,9 @@ class ContentProxyTest extends TestCase | |||
855 | 'html' => false, | 956 | 'html' => false, |
856 | 'title' => '', | 957 | 'title' => '', |
857 | 'url' => $content_url, | 958 | 'url' => $content_url, |
858 | 'content_type' => '', | 959 | 'headers' => [ |
960 | 'content-type' => '', | ||
961 | ], | ||
859 | 'language' => '', | 962 | 'language' => '', |
860 | ], | 963 | ], |
861 | true | 964 | true |
@@ -886,7 +989,9 @@ class ContentProxyTest extends TestCase | |||
886 | } | 989 | } |
887 | 990 | ||
888 | /** | 991 | /** |
889 | * https://stackoverflow.com/a/18506801. | 992 | * Convert hex to string. |
993 | * | ||
994 | * @see https://stackoverflow.com/a/18506801 | ||
890 | * | 995 | * |
891 | * @param $hex | 996 | * @param $hex |
892 | * | 997 | * |