From: Nicolas LÅ“uillet Date: Tue, 10 Jan 2017 20:25:27 +0000 (+0100) Subject: Merge pull request #2742 from wallabag/fix-og-image-false X-Git-Tag: 2.2.0~3^2~6 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=b4d81c91de537370265c7a09b963cab49af629a8;hp=e4ccd3effe8a5561d71d6c5f7c4bd1b23aa5a45b;p=github%2Fwallabag%2Fwallabag.git Merge pull request #2742 from wallabag/fix-og-image-false Avoid false preview image --- diff --git a/composer.json b/composer.json index fb6bed5b..b21c9538 100644 --- a/composer.json +++ b/composer.json @@ -84,7 +84,7 @@ "javibravo/simpleue": "^1.0", "symfony/dom-crawler": "^3.1", "friendsofsymfony/jsrouting-bundle": "^1.6", - "bdunogier/guzzle-site-authenticator": "^1.0@beta" + "bdunogier/guzzle-site-authenticator": "dev-master" }, "require-dev": { "doctrine/doctrine-fixtures-bundle": "~2.2", diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php index 0130bd2b..f222dd88 100644 --- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php +++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php @@ -88,7 +88,7 @@ class ContentProxy $entry->setDomainName($domainName); } - if (isset($content['open_graph']['og_image'])) { + if (isset($content['open_graph']['og_image']) && $content['open_graph']['og_image']) { $entry->setPreviewPicture($content['open_graph']['og_image']); } diff --git a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php index 08f4676e..2cf596d4 100644 --- a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php @@ -82,6 +82,6 @@ class SecurityControllerTest extends WallabagCoreTestCase $client->followRedirects(); $crawler = $client->request('GET', '/register'); - $this->assertContains('registration.submit', $crawler->filter('body')->extract(['_text'])[0]); + $this->assertContains('registration.submit', $client->getResponse()->getContent()); } } diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index 2ca13b91..5956b502 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php @@ -161,6 +161,47 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $this->assertEquals('1.1.1.1', $entry->getDomainName()); } + public function testWithContentAndNoOgImage() + { + $tagger = $this->getTaggerMock(); + $tagger->expects($this->once()) + ->method('tag'); + + $graby = $this->getMockBuilder('Graby\Graby') + ->setMethods(['fetchContent']) + ->disableOriginalConstructor() + ->getMock(); + + $graby->expects($this->any()) + ->method('fetchContent') + ->willReturn([ + 'html' => str_repeat('this is my content', 325), + 'title' => 'this is my title', + 'url' => 'http://1.1.1.1', + 'content_type' => 'text/html', + 'language' => 'fr', + 'status' => '200', + 'open_graph' => [ + 'og_title' => 'my OG title', + 'og_description' => 'OG desc', + 'og_image' => false, + ], + ]); + + $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger(), $this->fetchingErrorMessage); + $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); + + $this->assertEquals('http://1.1.1.1', $entry->getUrl()); + $this->assertEquals('this is my title', $entry->getTitle()); + $this->assertContains('this is my content', $entry->getContent()); + $this->assertNull($entry->getPreviewPicture()); + $this->assertEquals('text/html', $entry->getMimetype()); + $this->assertEquals('fr', $entry->getLanguage()); + $this->assertEquals('200', $entry->getHttpStatus()); + $this->assertEquals(4.0, $entry->getReadingTime()); + $this->assertEquals('1.1.1.1', $entry->getDomainName()); + } + public function testWithForcedContent() { $tagger = $this->getTaggerMock();