mirror of
https://github.com/wallabag/wallabag.git
synced 2024-12-20 22:56:30 +00:00
Avoid false preview image
If the website doesn't provide an og_image, the value will be false and so it'll be saved like that in the database. We prefer to leave it as null instead of false.
This commit is contained in:
parent
e4ccd3effe
commit
3d71d40349
2 changed files with 42 additions and 1 deletions
|
@ -88,7 +88,7 @@ class ContentProxy
|
||||||
$entry->setDomainName($domainName);
|
$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']);
|
$entry->setPreviewPicture($content['open_graph']['og_image']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -161,6 +161,47 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->assertEquals('1.1.1.1', $entry->getDomainName());
|
$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()
|
public function testWithForcedContent()
|
||||||
{
|
{
|
||||||
$tagger = $this->getTaggerMock();
|
$tagger = $this->getTaggerMock();
|
||||||
|
|
Loading…
Reference in a new issue