diff options
Diffstat (limited to 'tests/Wallabag/CoreBundle')
-rw-r--r-- | tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php | 137 | ||||
-rw-r--r-- | tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php | 123 |
2 files changed, 115 insertions, 145 deletions
diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index c7caac1d..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 | ||
@@ -231,14 +232,12 @@ class ContentProxyTest extends TestCase | |||
231 | 'html' => "<h1>Test</h1><p><img src='http://3.3.3.3/cover.jpg'/></p>", | 232 | 'html' => "<h1>Test</h1><p><img src='http://3.3.3.3/cover.jpg'/></p>", |
232 | 'title' => 'this is my title', | 233 | 'title' => 'this is my title', |
233 | 'url' => 'http://1.1.1.1', | 234 | 'url' => 'http://1.1.1.1', |
234 | 'content_type' => 'text/html', | 235 | 'headers' => [ |
236 | 'content-type' => 'text/html', | ||
237 | ], | ||
235 | 'language' => 'fr', | 238 | 'language' => 'fr', |
236 | 'status' => '200', | 239 | 'status' => '200', |
237 | 'open_graph' => [ | 240 | 'image' => null, |
238 | 'og_title' => 'my OG title', | ||
239 | 'og_description' => 'OG desc', | ||
240 | 'og_image' => null, | ||
241 | ], | ||
242 | ]); | 241 | ]); |
243 | 242 | ||
244 | $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); | 243 | $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); |
@@ -273,14 +272,12 @@ class ContentProxyTest extends TestCase | |||
273 | 'html' => "<h1>Test</h1><p><img src='http://3.3.3.3/nevermind.jpg'/></p>", | 272 | 'html' => "<h1>Test</h1><p><img src='http://3.3.3.3/nevermind.jpg'/></p>", |
274 | 'title' => 'this is my title', | 273 | 'title' => 'this is my title', |
275 | 'url' => 'http://1.1.1.1', | 274 | 'url' => 'http://1.1.1.1', |
276 | 'content_type' => 'text/html', | 275 | 'headers' => [ |
276 | 'content-type' => 'text/html', | ||
277 | ], | ||
277 | 'language' => 'fr', | 278 | 'language' => 'fr', |
278 | 'status' => '200', | 279 | 'status' => '200', |
279 | 'open_graph' => [ | 280 | 'image' => 'http://3.3.3.3/cover.jpg', |
280 | 'og_title' => 'my OG title', | ||
281 | 'og_description' => 'OG desc', | ||
282 | 'og_image' => 'http://3.3.3.3/cover.jpg', | ||
283 | ], | ||
284 | ]); | 281 | ]); |
285 | 282 | ||
286 | $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); | 283 | $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); |
@@ -320,9 +317,11 @@ class ContentProxyTest extends TestCase | |||
320 | 'html' => str_repeat('this is my content', 325), | 317 | 'html' => str_repeat('this is my content', 325), |
321 | 'title' => 'this is my title', | 318 | 'title' => 'this is my title', |
322 | 'url' => 'http://1.1.1.1', | 319 | 'url' => 'http://1.1.1.1', |
323 | 'content_type' => 'text/html', | ||
324 | 'language' => 'dontexist', | 320 | 'language' => 'dontexist', |
325 | 'status' => '200', | 321 | 'status' => '200', |
322 | 'headers' => [ | ||
323 | 'content-type' => 'text/html', | ||
324 | ], | ||
326 | ]); | 325 | ]); |
327 | 326 | ||
328 | $proxy = new ContentProxy($graby, $tagger, $validator, $this->getLogger(), $this->fetchingErrorMessage); | 327 | $proxy = new ContentProxy($graby, $tagger, $validator, $this->getLogger(), $this->fetchingErrorMessage); |
@@ -364,14 +363,13 @@ class ContentProxyTest extends TestCase | |||
364 | 'html' => str_repeat('this is my content', 325), | 363 | 'html' => str_repeat('this is my content', 325), |
365 | 'title' => 'this is my title', | 364 | 'title' => 'this is my title', |
366 | 'url' => 'http://1.1.1.1', | 365 | 'url' => 'http://1.1.1.1', |
367 | 'content_type' => 'text/html', | 366 | 'headers' => [ |
367 | 'content-type' => 'text/html', | ||
368 | ], | ||
368 | 'language' => 'fr', | 369 | 'language' => 'fr', |
369 | 'status' => '200', | 370 | 'status' => '200', |
370 | 'open_graph' => [ | 371 | 'description' => 'OG desc', |
371 | 'og_title' => 'my OG title', | 372 | 'image' => 'https://', |
372 | 'og_description' => 'OG desc', | ||
373 | 'og_image' => 'https://', | ||
374 | ], | ||
375 | ]); | 373 | ]); |
376 | 374 | ||
377 | $proxy = new ContentProxy($graby, $tagger, $validator, $this->getLogger(), $this->fetchingErrorMessage); | 375 | $proxy = new ContentProxy($graby, $tagger, $validator, $this->getLogger(), $this->fetchingErrorMessage); |
@@ -404,12 +402,12 @@ class ContentProxyTest extends TestCase | |||
404 | 'html' => str_repeat('this is my content', 325), | 402 | 'html' => str_repeat('this is my content', 325), |
405 | 'title' => 'this is my title', | 403 | 'title' => 'this is my title', |
406 | 'url' => 'http://1.1.1.1', | 404 | 'url' => 'http://1.1.1.1', |
407 | 'content_type' => 'text/html', | ||
408 | 'language' => 'fr', | 405 | 'language' => 'fr', |
409 | 'date' => '1395635872', | 406 | 'date' => '1395635872', |
410 | 'authors' => ['Jeremy', 'Nico', 'Thomas'], | 407 | 'authors' => ['Jeremy', 'Nico', 'Thomas'], |
411 | 'all_headers' => [ | 408 | 'headers' => [ |
412 | 'Cache-Control' => 'no-cache', | 409 | 'cache-control' => 'no-cache', |
410 | 'content-type' => 'text/html', | ||
413 | ], | 411 | ], |
414 | ] | 412 | ] |
415 | ); | 413 | ); |
@@ -447,9 +445,11 @@ class ContentProxyTest extends TestCase | |||
447 | 'html' => str_repeat('this is my content', 325), | 445 | 'html' => str_repeat('this is my content', 325), |
448 | 'title' => 'this is my title', | 446 | 'title' => 'this is my title', |
449 | 'url' => 'http://1.1.1.1', | 447 | 'url' => 'http://1.1.1.1', |
450 | 'content_type' => 'text/html', | ||
451 | 'language' => 'fr', | 448 | 'language' => 'fr', |
452 | 'date' => '2016-09-08T11:55:58+0200', | 449 | 'date' => '2016-09-08T11:55:58+0200', |
450 | 'headers' => [ | ||
451 | 'content-type' => 'text/html', | ||
452 | ], | ||
453 | ] | 453 | ] |
454 | ); | 454 | ); |
455 | 455 | ||
@@ -482,9 +482,11 @@ class ContentProxyTest extends TestCase | |||
482 | 'html' => str_repeat('this is my content', 325), | 482 | 'html' => str_repeat('this is my content', 325), |
483 | 'title' => 'this is my title', | 483 | 'title' => 'this is my title', |
484 | 'url' => 'http://1.1.1.1', | 484 | 'url' => 'http://1.1.1.1', |
485 | 'content_type' => 'text/html', | ||
486 | 'language' => 'fr', | 485 | 'language' => 'fr', |
487 | 'date' => '01 02 2012', | 486 | 'date' => '01 02 2012', |
487 | 'headers' => [ | ||
488 | 'content-type' => 'text/html', | ||
489 | ], | ||
488 | ] | 490 | ] |
489 | ); | 491 | ); |
490 | 492 | ||
@@ -519,8 +521,10 @@ class ContentProxyTest extends TestCase | |||
519 | 'html' => str_repeat('this is my content', 325), | 521 | 'html' => str_repeat('this is my content', 325), |
520 | 'title' => 'this is my title', | 522 | 'title' => 'this is my title', |
521 | 'url' => 'http://1.1.1.1', | 523 | 'url' => 'http://1.1.1.1', |
522 | 'content_type' => 'text/html', | ||
523 | 'language' => 'fr', | 524 | 'language' => 'fr', |
525 | 'headers' => [ | ||
526 | 'content-type' => 'text/html', | ||
527 | ], | ||
524 | ] | 528 | ] |
525 | ); | 529 | ); |
526 | 530 | ||
@@ -559,13 +563,13 @@ class ContentProxyTest extends TestCase | |||
559 | 'html' => $html, | 563 | 'html' => $html, |
560 | 'title' => 'this is my title', | 564 | 'title' => 'this is my title', |
561 | 'url' => 'http://1.1.1.1', | 565 | 'url' => 'http://1.1.1.1', |
562 | 'content_type' => 'text/html', | ||
563 | 'language' => 'fr', | 566 | 'language' => 'fr', |
564 | 'status' => '200', | 567 | 'status' => '200', |
565 | 'open_graph' => [ | 568 | //'og_title' => 'my OG title', |
566 | 'og_title' => 'my OG title', | 569 | 'description' => 'OG desc', |
567 | 'og_description' => 'OG desc', | 570 | 'image' => 'http://3.3.3.3/cover.jpg', |
568 | 'og_image' => 'http://3.3.3.3/cover.jpg', | 571 | 'headers' => [ |
572 | 'content-type' => 'text/html', | ||
569 | ], | 573 | ], |
570 | ] | 574 | ] |
571 | ); | 575 | ); |
@@ -597,9 +601,10 @@ class ContentProxyTest extends TestCase | |||
597 | '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>', |
598 | 'title' => 'this is my title', | 602 | 'title' => 'this is my title', |
599 | 'url' => 'http://1.1.1.1/image.jpg', | 603 | 'url' => 'http://1.1.1.1/image.jpg', |
600 | 'content_type' => 'image/jpeg', | ||
601 | 'status' => '200', | 604 | 'status' => '200', |
602 | 'open_graph' => [], | 605 | 'headers' => [ |
606 | 'content-type' => 'image/jpeg', | ||
607 | ], | ||
603 | ]); | 608 | ]); |
604 | 609 | ||
605 | $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); | 610 | $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); |
@@ -637,7 +642,9 @@ class ContentProxyTest extends TestCase | |||
637 | 'html' => false, | 642 | 'html' => false, |
638 | 'title' => $actualTitle, | 643 | 'title' => $actualTitle, |
639 | 'url' => '', | 644 | 'url' => '', |
640 | 'content_type' => 'text/html', | 645 | 'headers' => [ |
646 | 'content-type' => 'text/html', | ||
647 | ], | ||
641 | 'language' => '', | 648 | 'language' => '', |
642 | ]); | 649 | ]); |
643 | 650 | ||
@@ -672,7 +679,9 @@ class ContentProxyTest extends TestCase | |||
672 | 'html' => false, | 679 | 'html' => false, |
673 | 'title' => $actualTitle, | 680 | 'title' => $actualTitle, |
674 | 'url' => '', | 681 | 'url' => '', |
675 | 'content_type' => 'text/html', | 682 | 'headers' => [ |
683 | 'content-type' => 'text/html', | ||
684 | ], | ||
676 | 'language' => '', | 685 | 'language' => '', |
677 | ]); | 686 | ]); |
678 | 687 | ||
@@ -706,7 +715,9 @@ class ContentProxyTest extends TestCase | |||
706 | 'html' => false, | 715 | 'html' => false, |
707 | 'title' => $actualTitle, | 716 | 'title' => $actualTitle, |
708 | 'url' => '', | 717 | 'url' => '', |
709 | 'content_type' => 'application/pdf', | 718 | 'headers' => [ |
719 | 'content-type' => 'application/pdf', | ||
720 | ], | ||
710 | 'language' => '', | 721 | 'language' => '', |
711 | ]); | 722 | ]); |
712 | 723 | ||
@@ -740,7 +751,9 @@ class ContentProxyTest extends TestCase | |||
740 | 'html' => false, | 751 | 'html' => false, |
741 | 'title' => $actualTitle, | 752 | 'title' => $actualTitle, |
742 | 'url' => '', | 753 | 'url' => '', |
743 | 'content_type' => 'application/pdf', | 754 | 'headers' => [ |
755 | 'content-type' => 'application/pdf', | ||
756 | ], | ||
744 | 'language' => '', | 757 | 'language' => '', |
745 | ]); | 758 | ]); |
746 | 759 | ||
@@ -774,7 +787,9 @@ class ContentProxyTest extends TestCase | |||
774 | 'html' => false, | 787 | 'html' => false, |
775 | 'title' => $actualTitle, | 788 | 'title' => $actualTitle, |
776 | 'url' => '', | 789 | 'url' => '', |
777 | 'content_type' => 'application/pdf', | 790 | 'headers' => [ |
791 | 'content-type' => 'application/pdf', | ||
792 | ], | ||
778 | 'language' => '', | 793 | 'language' => '', |
779 | ]); | 794 | ]); |
780 | 795 | ||
@@ -809,7 +824,9 @@ class ContentProxyTest extends TestCase | |||
809 | 'html' => false, | 824 | 'html' => false, |
810 | 'title' => $actualTitle, | 825 | 'title' => $actualTitle, |
811 | 'url' => '', | 826 | 'url' => '', |
812 | 'content_type' => 'application/pdf', | 827 | 'headers' => [ |
828 | 'content-type' => 'application/pdf', | ||
829 | ], | ||
813 | 'language' => '', | 830 | 'language' => '', |
814 | ]); | 831 | ]); |
815 | 832 | ||
@@ -939,7 +956,9 @@ class ContentProxyTest extends TestCase | |||
939 | 'html' => false, | 956 | 'html' => false, |
940 | 'title' => '', | 957 | 'title' => '', |
941 | 'url' => $content_url, | 958 | 'url' => $content_url, |
942 | 'content_type' => '', | 959 | 'headers' => [ |
960 | 'content-type' => '', | ||
961 | ], | ||
943 | 'language' => '', | 962 | 'language' => '', |
944 | ], | 963 | ], |
945 | true | 964 | true |
@@ -970,7 +989,9 @@ class ContentProxyTest extends TestCase | |||
970 | } | 989 | } |
971 | 990 | ||
972 | /** | 991 | /** |
973 | * https://stackoverflow.com/a/18506801. | 992 | * Convert hex to string. |
993 | * | ||
994 | * @see https://stackoverflow.com/a/18506801 | ||
974 | * | 995 | * |
975 | * @param $hex | 996 | * @param $hex |
976 | * | 997 | * |
diff --git a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php index cda5f843..3c720425 100644 --- a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php +++ b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php | |||
@@ -2,10 +2,8 @@ | |||
2 | 2 | ||
3 | namespace Tests\Wallabag\CoreBundle\Helper; | 3 | namespace Tests\Wallabag\CoreBundle\Helper; |
4 | 4 | ||
5 | use GuzzleHttp\Client; | 5 | use GuzzleHttp\Psr7\Response; |
6 | use GuzzleHttp\Message\Response; | 6 | use Http\Mock\Client as HttpMockClient; |
7 | use GuzzleHttp\Stream\Stream; | ||
8 | use GuzzleHttp\Subscriber\Mock; | ||
9 | use Monolog\Handler\TestHandler; | 7 | use Monolog\Handler\TestHandler; |
10 | use Monolog\Logger; | 8 | use Monolog\Logger; |
11 | use PHPUnit\Framework\TestCase; | 9 | use PHPUnit\Framework\TestCase; |
@@ -32,18 +30,14 @@ class DownloadImagesTest extends TestCase | |||
32 | */ | 30 | */ |
33 | public function testProcessHtml($html, $url) | 31 | public function testProcessHtml($html, $url) |
34 | { | 32 | { |
35 | $client = new Client(); | 33 | $httpMockClient = new HttpMockClient(); |
36 | 34 | ||
37 | $mock = new Mock([ | 35 | $httpMockClient->addResponse(new Response(200, ['content-type' => 'image/png'], file_get_contents(__DIR__ . '/../fixtures/unnamed.png'))); |
38 | new Response(200, ['content-type' => 'image/png'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/unnamed.png'))), | ||
39 | ]); | ||
40 | |||
41 | $client->getEmitter()->attach($mock); | ||
42 | 36 | ||
43 | $logHandler = new TestHandler(); | 37 | $logHandler = new TestHandler(); |
44 | $logger = new Logger('test', [$logHandler]); | 38 | $logger = new Logger('test', [$logHandler]); |
45 | 39 | ||
46 | $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); | 40 | $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); |
47 | 41 | ||
48 | $res = $download->processHtml(123, $html, $url); | 42 | $res = $download->processHtml(123, $html, $url); |
49 | 43 | ||
@@ -53,18 +47,13 @@ class DownloadImagesTest extends TestCase | |||
53 | 47 | ||
54 | public function testProcessHtmlWithBadImage() | 48 | public function testProcessHtmlWithBadImage() |
55 | { | 49 | { |
56 | $client = new Client(); | 50 | $httpMockClient = new HttpMockClient(); |
57 | 51 | $httpMockClient->addResponse(new Response(200, ['content-type' => 'application/json'], '')); | |
58 | $mock = new Mock([ | ||
59 | new Response(200, ['content-type' => 'application/json'], Stream::factory('')), | ||
60 | ]); | ||
61 | |||
62 | $client->getEmitter()->attach($mock); | ||
63 | 52 | ||
64 | $logHandler = new TestHandler(); | 53 | $logHandler = new TestHandler(); |
65 | $logger = new Logger('test', [$logHandler]); | 54 | $logger = new Logger('test', [$logHandler]); |
66 | 55 | ||
67 | $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); | 56 | $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); |
68 | $res = $download->processHtml(123, '<div><img src="http://i.imgur.com/T9qgcHc.jpg" /></div>', 'http://imgur.com/gallery/WxtWY'); | 57 | $res = $download->processHtml(123, '<div><img src="http://i.imgur.com/T9qgcHc.jpg" /></div>', 'http://imgur.com/gallery/WxtWY'); |
69 | 58 | ||
70 | $this->assertContains('http://i.imgur.com/T9qgcHc.jpg', $res, 'Image were not replace because of content-type'); | 59 | $this->assertContains('http://i.imgur.com/T9qgcHc.jpg', $res, 'Image were not replace because of content-type'); |
@@ -85,18 +74,13 @@ class DownloadImagesTest extends TestCase | |||
85 | */ | 74 | */ |
86 | public function testProcessSingleImage($header, $extension) | 75 | public function testProcessSingleImage($header, $extension) |
87 | { | 76 | { |
88 | $client = new Client(); | 77 | $httpMockClient = new HttpMockClient(); |
89 | 78 | $httpMockClient->addResponse(new Response(200, ['content-type' => $header], file_get_contents(__DIR__ . '/../fixtures/unnamed.png'))); | |
90 | $mock = new Mock([ | ||
91 | new Response(200, ['content-type' => $header], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/unnamed.png'))), | ||
92 | ]); | ||
93 | |||
94 | $client->getEmitter()->attach($mock); | ||
95 | 79 | ||
96 | $logHandler = new TestHandler(); | 80 | $logHandler = new TestHandler(); |
97 | $logger = new Logger('test', [$logHandler]); | 81 | $logger = new Logger('test', [$logHandler]); |
98 | 82 | ||
99 | $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); | 83 | $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); |
100 | $res = $download->processSingleImage(123, 'T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); | 84 | $res = $download->processSingleImage(123, 'T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); |
101 | 85 | ||
102 | $this->assertContains('/assets/images/9/b/9b0ead26/ebe60399.' . $extension, $res); | 86 | $this->assertContains('/assets/images/9/b/9b0ead26/ebe60399.' . $extension, $res); |
@@ -104,18 +88,13 @@ class DownloadImagesTest extends TestCase | |||
104 | 88 | ||
105 | public function testProcessSingleImageWithBadUrl() | 89 | public function testProcessSingleImageWithBadUrl() |
106 | { | 90 | { |
107 | $client = new Client(); | 91 | $httpMockClient = new HttpMockClient(); |
108 | 92 | $httpMockClient->addResponse(new Response(404, [])); | |
109 | $mock = new Mock([ | ||
110 | new Response(404, []), | ||
111 | ]); | ||
112 | |||
113 | $client->getEmitter()->attach($mock); | ||
114 | 93 | ||
115 | $logHandler = new TestHandler(); | 94 | $logHandler = new TestHandler(); |
116 | $logger = new Logger('test', [$logHandler]); | 95 | $logger = new Logger('test', [$logHandler]); |
117 | 96 | ||
118 | $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); | 97 | $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); |
119 | $res = $download->processSingleImage(123, 'T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); | 98 | $res = $download->processSingleImage(123, 'T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); |
120 | 99 | ||
121 | $this->assertFalse($res, 'Image can not be found, so it will not be replaced'); | 100 | $this->assertFalse($res, 'Image can not be found, so it will not be replaced'); |
@@ -123,18 +102,13 @@ class DownloadImagesTest extends TestCase | |||
123 | 102 | ||
124 | public function testProcessSingleImageWithBadImage() | 103 | public function testProcessSingleImageWithBadImage() |
125 | { | 104 | { |
126 | $client = new Client(); | 105 | $httpMockClient = new HttpMockClient(); |
127 | 106 | $httpMockClient->addResponse(new Response(200, ['content-type' => 'image/png'], '')); | |
128 | $mock = new Mock([ | ||
129 | new Response(200, ['content-type' => 'image/png'], Stream::factory('')), | ||
130 | ]); | ||
131 | |||
132 | $client->getEmitter()->attach($mock); | ||
133 | 107 | ||
134 | $logHandler = new TestHandler(); | 108 | $logHandler = new TestHandler(); |
135 | $logger = new Logger('test', [$logHandler]); | 109 | $logger = new Logger('test', [$logHandler]); |
136 | 110 | ||
137 | $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); | 111 | $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); |
138 | $res = $download->processSingleImage(123, 'http://i.imgur.com/T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); | 112 | $res = $download->processSingleImage(123, 'http://i.imgur.com/T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); |
139 | 113 | ||
140 | $this->assertFalse($res, 'Image can not be loaded, so it will not be replaced'); | 114 | $this->assertFalse($res, 'Image can not be loaded, so it will not be replaced'); |
@@ -142,18 +116,13 @@ class DownloadImagesTest extends TestCase | |||
142 | 116 | ||
143 | public function testProcessSingleImageFailAbsolute() | 117 | public function testProcessSingleImageFailAbsolute() |
144 | { | 118 | { |
145 | $client = new Client(); | 119 | $httpMockClient = new HttpMockClient(); |
146 | 120 | $httpMockClient->addResponse(new Response(200, ['content-type' => 'image/png'], file_get_contents(__DIR__ . '/../fixtures/unnamed.png'))); | |
147 | $mock = new Mock([ | ||
148 | new Response(200, ['content-type' => 'image/png'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/unnamed.png'))), | ||
149 | ]); | ||
150 | |||
151 | $client->getEmitter()->attach($mock); | ||
152 | 121 | ||
153 | $logHandler = new TestHandler(); | 122 | $logHandler = new TestHandler(); |
154 | $logger = new Logger('test', [$logHandler]); | 123 | $logger = new Logger('test', [$logHandler]); |
155 | 124 | ||
156 | $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); | 125 | $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); |
157 | $res = $download->processSingleImage(123, '/i.imgur.com/T9qgcHc.jpg', 'imgur.com/gallery/WxtWY'); | 126 | $res = $download->processSingleImage(123, '/i.imgur.com/T9qgcHc.jpg', 'imgur.com/gallery/WxtWY'); |
158 | 127 | ||
159 | $this->assertFalse($res, 'Absolute image can not be determined, so it will not be replaced'); | 128 | $this->assertFalse($res, 'Absolute image can not be determined, so it will not be replaced'); |
@@ -161,18 +130,13 @@ class DownloadImagesTest extends TestCase | |||
161 | 130 | ||
162 | public function testProcessRealImage() | 131 | public function testProcessRealImage() |
163 | { | 132 | { |
164 | $client = new Client(); | 133 | $httpMockClient = new HttpMockClient(); |
165 | 134 | $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))); | |
166 | $mock = new Mock([ | ||
167 | new Response(200, ['content-type' => null], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), | ||
168 | ]); | ||
169 | |||
170 | $client->getEmitter()->attach($mock); | ||
171 | 135 | ||
172 | $logHandler = new TestHandler(); | 136 | $logHandler = new TestHandler(); |
173 | $logger = new Logger('test', [$logHandler]); | 137 | $logger = new Logger('test', [$logHandler]); |
174 | 138 | ||
175 | $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); | 139 | $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); |
176 | 140 | ||
177 | $res = $download->processSingleImage( | 141 | $res = $download->processSingleImage( |
178 | 123, | 142 | 123, |
@@ -186,20 +150,15 @@ class DownloadImagesTest extends TestCase | |||
186 | 150 | ||
187 | public function testProcessImageWithSrcset() | 151 | public function testProcessImageWithSrcset() |
188 | { | 152 | { |
189 | $client = new Client(); | 153 | $httpMockClient = new HttpMockClient(); |
190 | 154 | $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))); | |
191 | $mock = new Mock([ | 155 | $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))); |
192 | new Response(200, ['content-type' => 'image/jpeg'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), | 156 | $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))); |
193 | new Response(200, ['content-type' => 'image/jpeg'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), | ||
194 | new Response(200, ['content-type' => 'image/jpeg'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), | ||
195 | ]); | ||
196 | |||
197 | $client->getEmitter()->attach($mock); | ||
198 | 157 | ||
199 | $logHandler = new TestHandler(); | 158 | $logHandler = new TestHandler(); |
200 | $logger = new Logger('test', [$logHandler]); | 159 | $logger = new Logger('test', [$logHandler]); |
201 | 160 | ||
202 | $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); | 161 | $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); |
203 | $res = $download->processHtml(123, '<p><img class="alignnone wp-image-1153" src="http://piketty.blog.lemonde.fr/files/2017/10/F1FR-530x375.jpg" alt="" width="628" height="444" srcset="http://piketty.blog.lemonde.fr/files/2017/10/F1FR-530x375.jpg 530w, http://piketty.blog.lemonde.fr/files/2017/10/F1FR-768x543.jpg 768w, http://piketty.blog.lemonde.fr/files/2017/10/F1FR-900x636.jpg 900w" sizes="(max-width: 628px) 100vw, 628px" /></p>', 'http://piketty.blog.lemonde.fr/2017/10/12/budget-2018-la-jeunesse-sacrifiee/'); | 162 | $res = $download->processHtml(123, '<p><img class="alignnone wp-image-1153" src="http://piketty.blog.lemonde.fr/files/2017/10/F1FR-530x375.jpg" alt="" width="628" height="444" srcset="http://piketty.blog.lemonde.fr/files/2017/10/F1FR-530x375.jpg 530w, http://piketty.blog.lemonde.fr/files/2017/10/F1FR-768x543.jpg 768w, http://piketty.blog.lemonde.fr/files/2017/10/F1FR-900x636.jpg 900w" sizes="(max-width: 628px) 100vw, 628px" /></p>', 'http://piketty.blog.lemonde.fr/2017/10/12/budget-2018-la-jeunesse-sacrifiee/'); |
204 | 163 | ||
205 | $this->assertNotContains('http://piketty.blog.lemonde.fr/', $res, 'Image srcset attribute were not replaced'); | 164 | $this->assertNotContains('http://piketty.blog.lemonde.fr/', $res, 'Image srcset attribute were not replaced'); |
@@ -207,20 +166,15 @@ class DownloadImagesTest extends TestCase | |||
207 | 166 | ||
208 | public function testProcessImageWithTrickySrcset() | 167 | public function testProcessImageWithTrickySrcset() |
209 | { | 168 | { |
210 | $client = new Client(); | 169 | $httpMockClient = new HttpMockClient(); |
211 | 170 | $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))); | |
212 | $mock = new Mock([ | 171 | $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))); |
213 | new Response(200, ['content-type' => 'image/jpeg'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), | 172 | $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))); |
214 | new Response(200, ['content-type' => 'image/jpeg'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), | ||
215 | new Response(200, ['content-type' => 'image/jpeg'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), | ||
216 | ]); | ||
217 | |||
218 | $client->getEmitter()->attach($mock); | ||
219 | 173 | ||
220 | $logHandler = new TestHandler(); | 174 | $logHandler = new TestHandler(); |
221 | $logger = new Logger('test', [$logHandler]); | 175 | $logger = new Logger('test', [$logHandler]); |
222 | 176 | ||
223 | $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); | 177 | $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); |
224 | $res = $download->processHtml(123, '<figure id="post-257260" class="align-none media-257260"><img src="https://cdn.css-tricks.com/wp-content/uploads/2017/08/the-critical-request.png" srcset="https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_1000,f_auto,q_auto/v1501594717/the-critical-request_bqdfaa.png 1000w, https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_200,f_auto,q_auto/v1501594717/the-critical-request_bqdfaa.png 200w" sizes="(min-width: 1850px) calc( (100vw - 555px) / 3 ) | 178 | $res = $download->processHtml(123, '<figure id="post-257260" class="align-none media-257260"><img src="https://cdn.css-tricks.com/wp-content/uploads/2017/08/the-critical-request.png" srcset="https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_1000,f_auto,q_auto/v1501594717/the-critical-request_bqdfaa.png 1000w, https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_200,f_auto,q_auto/v1501594717/the-critical-request_bqdfaa.png 200w" sizes="(min-width: 1850px) calc( (100vw - 555px) / 3 ) |
225 | (min-width: 1251px) calc( (100vw - 530px) / 2 ) | 179 | (min-width: 1251px) calc( (100vw - 530px) / 2 ) |
226 | (min-width: 1086px) calc(100vw - 480px) | 180 | (min-width: 1086px) calc(100vw - 480px) |
@@ -232,18 +186,13 @@ class DownloadImagesTest extends TestCase | |||
232 | 186 | ||
233 | public function testProcessImageWithNullPath() | 187 | public function testProcessImageWithNullPath() |
234 | { | 188 | { |
235 | $client = new Client(); | 189 | $httpMockClient = new HttpMockClient(); |
236 | 190 | $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))); | |
237 | $mock = new Mock([ | ||
238 | new Response(200, ['content-type' => null], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), | ||
239 | ]); | ||
240 | |||
241 | $client->getEmitter()->attach($mock); | ||
242 | 191 | ||
243 | $logHandler = new TestHandler(); | 192 | $logHandler = new TestHandler(); |
244 | $logger = new Logger('test', [$logHandler]); | 193 | $logger = new Logger('test', [$logHandler]); |
245 | 194 | ||
246 | $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); | 195 | $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); |
247 | 196 | ||
248 | $res = $download->processSingleImage( | 197 | $res = $download->processSingleImage( |
249 | 123, | 198 | 123, |