mirror of
https://github.com/wallabag/wallabag.git
synced 2024-12-27 18:10:28 +00:00
Move readingTime & domainName in ContentProxy
So, everything is centralized in one place when we save a new entry.
This commit is contained in:
parent
34c2cc7a1a
commit
da3d4998c0
4 changed files with 25 additions and 7 deletions
|
@ -17,6 +17,8 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface
|
|||
{
|
||||
$entry1 = new Entry($this->getReference('admin-user'));
|
||||
$entry1->setUrl('http://0.0.0.0');
|
||||
$entry1->setReadingTime(11);
|
||||
$entry1->setDomainName('domain.io');
|
||||
$entry1->setTitle('test title entry1');
|
||||
$entry1->setContent('This is my content /o/');
|
||||
$entry1->setLanguage('en');
|
||||
|
@ -27,6 +29,8 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface
|
|||
|
||||
$entry2 = new Entry($this->getReference('admin-user'));
|
||||
$entry2->setUrl('http://0.0.0.0');
|
||||
$entry2->setReadingTime(1);
|
||||
$entry2->setDomainName('domain.io');
|
||||
$entry2->setTitle('test title entry2');
|
||||
$entry2->setContent('This is my content /o/');
|
||||
$entry2->setLanguage('fr');
|
||||
|
@ -37,6 +41,8 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface
|
|||
|
||||
$entry3 = new Entry($this->getReference('bob-user'));
|
||||
$entry3->setUrl('http://0.0.0.0');
|
||||
$entry3->setReadingTime(1);
|
||||
$entry3->setDomainName('domain.io');
|
||||
$entry3->setTitle('test title entry3');
|
||||
$entry3->setContent('This is my content /o/');
|
||||
$entry3->setLanguage('en');
|
||||
|
@ -55,6 +61,8 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface
|
|||
|
||||
$entry4 = new Entry($this->getReference('admin-user'));
|
||||
$entry4->setUrl('http://0.0.0.0');
|
||||
$entry4->setReadingTime(12);
|
||||
$entry4->setDomainName('domain.io');
|
||||
$entry4->setTitle('test title entry4');
|
||||
$entry4->setContent('This is my content /o/');
|
||||
$entry4->setLanguage('en');
|
||||
|
@ -73,6 +81,8 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface
|
|||
|
||||
$entry5 = new Entry($this->getReference('admin-user'));
|
||||
$entry5->setUrl('http://0.0.0.0');
|
||||
$entry5->setReadingTime(12);
|
||||
$entry5->setDomainName('domain.io');
|
||||
$entry5->setTitle('test title entry5');
|
||||
$entry5->setContent('This is my content /o/');
|
||||
$entry5->setStarred(true);
|
||||
|
@ -84,6 +94,8 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface
|
|||
|
||||
$entry6 = new Entry($this->getReference('admin-user'));
|
||||
$entry6->setUrl('http://0.0.0.0');
|
||||
$entry6->setReadingTime(12);
|
||||
$entry6->setDomainName('domain.io');
|
||||
$entry6->setTitle('test title entry6');
|
||||
$entry6->setContent('This is my content /o/');
|
||||
$entry6->setArchived(true);
|
||||
|
|
|
@ -7,7 +7,6 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Hateoas\Configuration\Annotation as Hateoas;
|
||||
use JMS\Serializer\Annotation\XmlRoot;
|
||||
use Wallabag\CoreBundle\Tools\Utils;
|
||||
|
||||
/**
|
||||
* Entry.
|
||||
|
@ -279,8 +278,6 @@ class Entry
|
|||
public function setContent($content)
|
||||
{
|
||||
$this->content = $content;
|
||||
$this->readingTime = Utils::getReadingTime($content);
|
||||
$this->domainName = parse_url($this->url, PHP_URL_HOST);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Wallabag\CoreBundle\Helper;
|
|||
|
||||
use Graby\Graby;
|
||||
use Wallabag\CoreBundle\Entity\Entry;
|
||||
use Wallabag\CoreBundle\Tools\Utils;
|
||||
|
||||
/**
|
||||
* This kind of proxy class take care of getting the content from an url
|
||||
|
@ -51,6 +52,8 @@ class ContentProxy
|
|||
$entry->setContent($html);
|
||||
$entry->setLanguage($content['language']);
|
||||
$entry->setMimetype($content['content_type']);
|
||||
$entry->setReadingTime(Utils::getReadingTime($html));
|
||||
$entry->setDomainName(parse_url($entry->getUrl(), PHP_URL_HOST));
|
||||
|
||||
if (isset($content['open_graph']['og_image'])) {
|
||||
$entry->setPreviewPicture($content['open_graph']['og_image']);
|
||||
|
|
|
@ -35,6 +35,8 @@ class ContentProxyTest extends KernelTestCase
|
|||
$this->assertEmpty($entry->getPreviewPicture());
|
||||
$this->assertEmpty($entry->getMimetype());
|
||||
$this->assertEmpty($entry->getLanguage());
|
||||
$this->assertEquals(0.0, $entry->getReadingTime());
|
||||
$this->assertEquals('0.0.0.0', $entry->getDomainName());
|
||||
}
|
||||
|
||||
public function testWithEmptyContentButOG()
|
||||
|
@ -59,14 +61,16 @@ class ContentProxyTest extends KernelTestCase
|
|||
));
|
||||
|
||||
$proxy = new ContentProxy($graby);
|
||||
$entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0');
|
||||
$entry = $proxy->updateEntry(new Entry(new User()), 'http://domain.io');
|
||||
|
||||
$this->assertEquals('http://0.0.0.0', $entry->getUrl());
|
||||
$this->assertEquals('http://domain.io', $entry->getUrl());
|
||||
$this->assertEquals('my title', $entry->getTitle());
|
||||
$this->assertEquals('<p>Unable to retrieve readable content.</p><p><i>But we found a short description: </i></p>desc', $entry->getContent());
|
||||
$this->assertEmpty($entry->getPreviewPicture());
|
||||
$this->assertEmpty($entry->getLanguage());
|
||||
$this->assertEmpty($entry->getMimetype());
|
||||
$this->assertEquals(0.0, $entry->getReadingTime());
|
||||
$this->assertEquals('domain.io', $entry->getDomainName());
|
||||
}
|
||||
|
||||
public function testWithContent()
|
||||
|
@ -79,7 +83,7 @@ class ContentProxyTest extends KernelTestCase
|
|||
$graby->expects($this->any())
|
||||
->method('fetchContent')
|
||||
->willReturn(array(
|
||||
'html' => 'this is my content',
|
||||
'html' => str_repeat('this is my content', 325),
|
||||
'title' => 'this is my title',
|
||||
'url' => 'http://1.1.1.1',
|
||||
'content_type' => 'text/html',
|
||||
|
@ -96,9 +100,11 @@ class ContentProxyTest extends KernelTestCase
|
|||
|
||||
$this->assertEquals('http://1.1.1.1', $entry->getUrl());
|
||||
$this->assertEquals('this is my title', $entry->getTitle());
|
||||
$this->assertEquals('this is my content', $entry->getContent());
|
||||
$this->assertContains('this is my content', $entry->getContent());
|
||||
$this->assertEquals('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture());
|
||||
$this->assertEquals('text/html', $entry->getMimetype());
|
||||
$this->assertEquals('fr', $entry->getLanguage());
|
||||
$this->assertEquals(4.0, $entry->getReadingTime());
|
||||
$this->assertEquals('1.1.1.1', $entry->getDomainName());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue