aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/Wallabag/CoreBundle/Helper/ContentProxy.php5
-rw-r--r--tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php35
2 files changed, 36 insertions, 4 deletions
diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
index 2a650e97..5622cc83 100644
--- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php
+++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
@@ -127,10 +127,7 @@ class ContentProxy
127 127
128 // if content is an image, define it as a preview too 128 // if content is an image, define it as a preview too
129 if (!empty($content['content_type']) && in_array($this->mimeGuesser->guess($content['content_type']), ['jpeg', 'jpg', 'gif', 'png'], true)) { 129 if (!empty($content['content_type']) && in_array($this->mimeGuesser->guess($content['content_type']), ['jpeg', 'jpg', 'gif', 'png'], true)) {
130 $this->validateAndSetPreviewPicture( 130 $this->updatePreviewPicture($entry, $content['url']);
131 $entry,
132 $content['url']
133 );
134 } 131 }
135 132
136 if (!empty($content['content_type'])) { 133 if (!empty($content['content_type'])) {
diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
index f394b947..c0b68d53 100644
--- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
+++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
@@ -495,6 +495,41 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
495 $this->assertSame('1.1.1.1', $entry->getDomainName()); 495 $this->assertSame('1.1.1.1', $entry->getDomainName());
496 } 496 }
497 497
498 public function testWithImageAsContent()
499 {
500 $tagger = $this->getTaggerMock();
501 $tagger->expects($this->once())
502 ->method('tag');
503
504 $graby = $this->getMockBuilder('Graby\Graby')
505 ->setMethods(['fetchContent'])
506 ->disableOriginalConstructor()
507 ->getMock();
508
509 $graby->expects($this->any())
510 ->method('fetchContent')
511 ->willReturn([
512 'html' => '<p><img src="http://1.1.1.1/image.jpg" /></p>',
513 'title' => 'this is my title',
514 'url' => 'http://1.1.1.1/image.jpg',
515 'content_type' => 'image/jpeg',
516 'status' => '200',
517 'open_graph' => [],
518 ]);
519
520 $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage);
521 $entry = new Entry(new User());
522 $proxy->updateEntry($entry, 'http://0.0.0.0');
523
524 $this->assertEquals('http://1.1.1.1/image.jpg', $entry->getUrl());
525 $this->assertEquals('this is my title', $entry->getTitle());
526 $this->assertContains('http://1.1.1.1/image.jpg', $entry->getContent());
527 $this->assertSame('http://1.1.1.1/image.jpg', $entry->getPreviewPicture());
528 $this->assertEquals('image/jpeg', $entry->getMimetype());
529 $this->assertEquals('200', $entry->getHttpStatus());
530 $this->assertEquals('1.1.1.1', $entry->getDomainName());
531 }
532
498 private function getTaggerMock() 533 private function getTaggerMock()
499 { 534 {
500 return $this->getMockBuilder(RuleBasedTagger::class) 535 return $this->getMockBuilder(RuleBasedTagger::class)