aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/CoreBundle/Helper
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/CoreBundle/Helper')
-rw-r--r--tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php213
-rw-r--r--tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php123
-rw-r--r--tests/Wallabag/CoreBundle/Helper/RedirectTest.php5
3 files changed, 199 insertions, 142 deletions
diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
index 3dd9273c..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
@@ -163,7 +165,7 @@ class ContentProxyTest extends TestCase
163 165
164 $this->assertSame('http://1.1.1.1', $entry->getUrl()); 166 $this->assertSame('http://1.1.1.1', $entry->getUrl());
165 $this->assertSame('this is my title', $entry->getTitle()); 167 $this->assertSame('this is my title', $entry->getTitle());
166 $this->assertContains('this is my content', $entry->getContent()); 168 $this->assertContains('content', $entry->getContent());
167 $this->assertSame('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture()); 169 $this->assertSame('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture());
168 $this->assertSame('text/html', $entry->getMimetype()); 170 $this->assertSame('text/html', $entry->getMimetype());
169 $this->assertSame('fr', $entry->getLanguage()); 171 $this->assertSame('fr', $entry->getLanguage());
@@ -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
@@ -205,7 +206,7 @@ class ContentProxyTest extends TestCase
205 206
206 $this->assertSame('http://1.1.1.1', $entry->getUrl()); 207 $this->assertSame('http://1.1.1.1', $entry->getUrl());
207 $this->assertSame('this is my title', $entry->getTitle()); 208 $this->assertSame('this is my title', $entry->getTitle());
208 $this->assertContains('this is my content', $entry->getContent()); 209 $this->assertContains('content', $entry->getContent());
209 $this->assertNull($entry->getPreviewPicture()); 210 $this->assertNull($entry->getPreviewPicture());
210 $this->assertSame('text/html', $entry->getMimetype()); 211 $this->assertSame('text/html', $entry->getMimetype());
211 $this->assertSame('fr', $entry->getLanguage()); 212 $this->assertSame('fr', $entry->getLanguage());
@@ -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);
@@ -247,7 +330,7 @@ class ContentProxyTest extends TestCase
247 330
248 $this->assertSame('http://1.1.1.1', $entry->getUrl()); 331 $this->assertSame('http://1.1.1.1', $entry->getUrl());
249 $this->assertSame('this is my title', $entry->getTitle()); 332 $this->assertSame('this is my title', $entry->getTitle());
250 $this->assertContains('this is my content', $entry->getContent()); 333 $this->assertContains('content', $entry->getContent());
251 $this->assertSame('text/html', $entry->getMimetype()); 334 $this->assertSame('text/html', $entry->getMimetype());
252 $this->assertNull($entry->getLanguage()); 335 $this->assertNull($entry->getLanguage());
253 $this->assertSame('200', $entry->getHttpStatus()); 336 $this->assertSame('200', $entry->getHttpStatus());
@@ -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);
@@ -296,7 +378,7 @@ class ContentProxyTest extends TestCase
296 378
297 $this->assertSame('http://1.1.1.1', $entry->getUrl()); 379 $this->assertSame('http://1.1.1.1', $entry->getUrl());
298 $this->assertSame('this is my title', $entry->getTitle()); 380 $this->assertSame('this is my title', $entry->getTitle());
299 $this->assertContains('this is my content', $entry->getContent()); 381 $this->assertContains('content', $entry->getContent());
300 $this->assertNull($entry->getPreviewPicture()); 382 $this->assertNull($entry->getPreviewPicture());
301 $this->assertSame('text/html', $entry->getMimetype()); 383 $this->assertSame('text/html', $entry->getMimetype());
302 $this->assertSame('fr', $entry->getLanguage()); 384 $this->assertSame('fr', $entry->getLanguage());
@@ -320,19 +402,19 @@ 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 );
332 414
333 $this->assertSame('http://1.1.1.1', $entry->getUrl()); 415 $this->assertSame('http://1.1.1.1', $entry->getUrl());
334 $this->assertSame('this is my title', $entry->getTitle()); 416 $this->assertSame('this is my title', $entry->getTitle());
335 $this->assertContains('this is my content', $entry->getContent()); 417 $this->assertContains('content', $entry->getContent());
336 $this->assertSame('text/html', $entry->getMimetype()); 418 $this->assertSame('text/html', $entry->getMimetype());
337 $this->assertSame('fr', $entry->getLanguage()); 419 $this->assertSame('fr', $entry->getLanguage());
338 $this->assertSame(4.0, $entry->getReadingTime()); 420 $this->assertSame(4.0, $entry->getReadingTime());
@@ -363,15 +445,17 @@ 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
372 $this->assertSame('http://1.1.1.1', $entry->getUrl()); 456 $this->assertSame('http://1.1.1.1', $entry->getUrl());
373 $this->assertSame('this is my title', $entry->getTitle()); 457 $this->assertSame('this is my title', $entry->getTitle());
374 $this->assertContains('this is my content', $entry->getContent()); 458 $this->assertContains('content', $entry->getContent());
375 $this->assertSame('text/html', $entry->getMimetype()); 459 $this->assertSame('text/html', $entry->getMimetype());
376 $this->assertSame('fr', $entry->getLanguage()); 460 $this->assertSame('fr', $entry->getLanguage());
377 $this->assertSame(4.0, $entry->getReadingTime()); 461 $this->assertSame(4.0, $entry->getReadingTime());
@@ -398,15 +482,17 @@ 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
407 $this->assertSame('http://1.1.1.1', $entry->getUrl()); 493 $this->assertSame('http://1.1.1.1', $entry->getUrl());
408 $this->assertSame('this is my title', $entry->getTitle()); 494 $this->assertSame('this is my title', $entry->getTitle());
409 $this->assertContains('this is my content', $entry->getContent()); 495 $this->assertContains('content', $entry->getContent());
410 $this->assertSame('text/html', $entry->getMimetype()); 496 $this->assertSame('text/html', $entry->getMimetype());
411 $this->assertSame('fr', $entry->getLanguage()); 497 $this->assertSame('fr', $entry->getLanguage());
412 $this->assertSame(4.0, $entry->getReadingTime()); 498 $this->assertSame(4.0, $entry->getReadingTime());
@@ -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 *
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
3namespace Tests\Wallabag\CoreBundle\Helper; 3namespace Tests\Wallabag\CoreBundle\Helper;
4 4
5use GuzzleHttp\Client; 5use GuzzleHttp\Psr7\Response;
6use GuzzleHttp\Message\Response; 6use Http\Mock\Client as HttpMockClient;
7use GuzzleHttp\Stream\Stream;
8use GuzzleHttp\Subscriber\Mock;
9use Monolog\Handler\TestHandler; 7use Monolog\Handler\TestHandler;
10use Monolog\Logger; 8use Monolog\Logger;
11use PHPUnit\Framework\TestCase; 9use 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,
diff --git a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php
index 04e1a59c..021efa46 100644
--- a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php
+++ b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php
@@ -17,6 +17,9 @@ class RedirectTest extends TestCase
17 /** @var Redirect */ 17 /** @var Redirect */
18 private $redirect; 18 private $redirect;
19 19
20 /** @var UsernamePasswordToken */
21 private $token;
22
20 public function setUp() 23 public function setUp()
21 { 24 {
22 $this->routerMock = $this->getMockBuilder('Symfony\Component\Routing\Router') 25 $this->routerMock = $this->getMockBuilder('Symfony\Component\Routing\Router')
@@ -39,7 +42,7 @@ class RedirectTest extends TestCase
39 $config = new Config($user); 42 $config = new Config($user);
40 $config->setTheme('material'); 43 $config->setTheme('material');
41 $config->setItemsPerPage(30); 44 $config->setItemsPerPage(30);
42 $config->setReadingSpeed(1); 45 $config->setReadingSpeed(200);
43 $config->setLanguage('en'); 46 $config->setLanguage('en');
44 $config->setPocketConsumerKey('xxxxx'); 47 $config->setPocketConsumerKey('xxxxx');
45 $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE); 48 $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE);