aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php12
-rw-r--r--src/Wallabag/CoreBundle/Entity/Entry.php3
-rw-r--r--src/Wallabag/CoreBundle/Helper/ContentProxy.php3
-rw-r--r--src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php14
4 files changed, 25 insertions, 7 deletions
diff --git a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php
index dd316194..b4b685f9 100644
--- a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php
+++ b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php
@@ -17,6 +17,8 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface
17 { 17 {
18 $entry1 = new Entry($this->getReference('admin-user')); 18 $entry1 = new Entry($this->getReference('admin-user'));
19 $entry1->setUrl('http://0.0.0.0'); 19 $entry1->setUrl('http://0.0.0.0');
20 $entry1->setReadingTime(11);
21 $entry1->setDomainName('domain.io');
20 $entry1->setTitle('test title entry1'); 22 $entry1->setTitle('test title entry1');
21 $entry1->setContent('This is my content /o/'); 23 $entry1->setContent('This is my content /o/');
22 $entry1->setLanguage('en'); 24 $entry1->setLanguage('en');
@@ -27,6 +29,8 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface
27 29
28 $entry2 = new Entry($this->getReference('admin-user')); 30 $entry2 = new Entry($this->getReference('admin-user'));
29 $entry2->setUrl('http://0.0.0.0'); 31 $entry2->setUrl('http://0.0.0.0');
32 $entry2->setReadingTime(1);
33 $entry2->setDomainName('domain.io');
30 $entry2->setTitle('test title entry2'); 34 $entry2->setTitle('test title entry2');
31 $entry2->setContent('This is my content /o/'); 35 $entry2->setContent('This is my content /o/');
32 $entry2->setLanguage('fr'); 36 $entry2->setLanguage('fr');
@@ -37,6 +41,8 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface
37 41
38 $entry3 = new Entry($this->getReference('bob-user')); 42 $entry3 = new Entry($this->getReference('bob-user'));
39 $entry3->setUrl('http://0.0.0.0'); 43 $entry3->setUrl('http://0.0.0.0');
44 $entry3->setReadingTime(1);
45 $entry3->setDomainName('domain.io');
40 $entry3->setTitle('test title entry3'); 46 $entry3->setTitle('test title entry3');
41 $entry3->setContent('This is my content /o/'); 47 $entry3->setContent('This is my content /o/');
42 $entry3->setLanguage('en'); 48 $entry3->setLanguage('en');
@@ -55,6 +61,8 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface
55 61
56 $entry4 = new Entry($this->getReference('admin-user')); 62 $entry4 = new Entry($this->getReference('admin-user'));
57 $entry4->setUrl('http://0.0.0.0'); 63 $entry4->setUrl('http://0.0.0.0');
64 $entry4->setReadingTime(12);
65 $entry4->setDomainName('domain.io');
58 $entry4->setTitle('test title entry4'); 66 $entry4->setTitle('test title entry4');
59 $entry4->setContent('This is my content /o/'); 67 $entry4->setContent('This is my content /o/');
60 $entry4->setLanguage('en'); 68 $entry4->setLanguage('en');
@@ -73,6 +81,8 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface
73 81
74 $entry5 = new Entry($this->getReference('admin-user')); 82 $entry5 = new Entry($this->getReference('admin-user'));
75 $entry5->setUrl('http://0.0.0.0'); 83 $entry5->setUrl('http://0.0.0.0');
84 $entry5->setReadingTime(12);
85 $entry5->setDomainName('domain.io');
76 $entry5->setTitle('test title entry5'); 86 $entry5->setTitle('test title entry5');
77 $entry5->setContent('This is my content /o/'); 87 $entry5->setContent('This is my content /o/');
78 $entry5->setStarred(true); 88 $entry5->setStarred(true);
@@ -84,6 +94,8 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface
84 94
85 $entry6 = new Entry($this->getReference('admin-user')); 95 $entry6 = new Entry($this->getReference('admin-user'));
86 $entry6->setUrl('http://0.0.0.0'); 96 $entry6->setUrl('http://0.0.0.0');
97 $entry6->setReadingTime(12);
98 $entry6->setDomainName('domain.io');
87 $entry6->setTitle('test title entry6'); 99 $entry6->setTitle('test title entry6');
88 $entry6->setContent('This is my content /o/'); 100 $entry6->setContent('This is my content /o/');
89 $entry6->setArchived(true); 101 $entry6->setArchived(true);
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php
index 7108889e..9e81ba12 100644
--- a/src/Wallabag/CoreBundle/Entity/Entry.php
+++ b/src/Wallabag/CoreBundle/Entity/Entry.php
@@ -7,7 +7,6 @@ use Doctrine\ORM\Mapping as ORM;
7use Symfony\Component\Validator\Constraints as Assert; 7use Symfony\Component\Validator\Constraints as Assert;
8use Hateoas\Configuration\Annotation as Hateoas; 8use Hateoas\Configuration\Annotation as Hateoas;
9use JMS\Serializer\Annotation\XmlRoot; 9use JMS\Serializer\Annotation\XmlRoot;
10use Wallabag\CoreBundle\Tools\Utils;
11 10
12/** 11/**
13 * Entry. 12 * Entry.
@@ -279,8 +278,6 @@ class Entry
279 public function setContent($content) 278 public function setContent($content)
280 { 279 {
281 $this->content = $content; 280 $this->content = $content;
282 $this->readingTime = Utils::getReadingTime($content);
283 $this->domainName = parse_url($this->url, PHP_URL_HOST);
284 281
285 return $this; 282 return $this;
286 } 283 }
diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
index 3de8828f..7fb41393 100644
--- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php
+++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
@@ -4,6 +4,7 @@ namespace Wallabag\CoreBundle\Helper;
4 4
5use Graby\Graby; 5use Graby\Graby;
6use Wallabag\CoreBundle\Entity\Entry; 6use Wallabag\CoreBundle\Entity\Entry;
7use Wallabag\CoreBundle\Tools\Utils;
7 8
8/** 9/**
9 * This kind of proxy class take care of getting the content from an url 10 * This kind of proxy class take care of getting the content from an url
@@ -51,6 +52,8 @@ class ContentProxy
51 $entry->setContent($html); 52 $entry->setContent($html);
52 $entry->setLanguage($content['language']); 53 $entry->setLanguage($content['language']);
53 $entry->setMimetype($content['content_type']); 54 $entry->setMimetype($content['content_type']);
55 $entry->setReadingTime(Utils::getReadingTime($html));
56 $entry->setDomainName(parse_url($entry->getUrl(), PHP_URL_HOST));
54 57
55 if (isset($content['open_graph']['og_image'])) { 58 if (isset($content['open_graph']['og_image'])) {
56 $entry->setPreviewPicture($content['open_graph']['og_image']); 59 $entry->setPreviewPicture($content['open_graph']['og_image']);
diff --git a/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php b/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php
index 30065d6b..0d338389 100644
--- a/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php
+++ b/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php
@@ -35,6 +35,8 @@ class ContentProxyTest extends KernelTestCase
35 $this->assertEmpty($entry->getPreviewPicture()); 35 $this->assertEmpty($entry->getPreviewPicture());
36 $this->assertEmpty($entry->getMimetype()); 36 $this->assertEmpty($entry->getMimetype());
37 $this->assertEmpty($entry->getLanguage()); 37 $this->assertEmpty($entry->getLanguage());
38 $this->assertEquals(0.0, $entry->getReadingTime());
39 $this->assertEquals('0.0.0.0', $entry->getDomainName());
38 } 40 }
39 41
40 public function testWithEmptyContentButOG() 42 public function testWithEmptyContentButOG()
@@ -59,14 +61,16 @@ class ContentProxyTest extends KernelTestCase
59 )); 61 ));
60 62
61 $proxy = new ContentProxy($graby); 63 $proxy = new ContentProxy($graby);
62 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); 64 $entry = $proxy->updateEntry(new Entry(new User()), 'http://domain.io');
63 65
64 $this->assertEquals('http://0.0.0.0', $entry->getUrl()); 66 $this->assertEquals('http://domain.io', $entry->getUrl());
65 $this->assertEquals('my title', $entry->getTitle()); 67 $this->assertEquals('my title', $entry->getTitle());
66 $this->assertEquals('<p>Unable to retrieve readable content.</p><p><i>But we found a short description: </i></p>desc', $entry->getContent()); 68 $this->assertEquals('<p>Unable to retrieve readable content.</p><p><i>But we found a short description: </i></p>desc', $entry->getContent());
67 $this->assertEmpty($entry->getPreviewPicture()); 69 $this->assertEmpty($entry->getPreviewPicture());
68 $this->assertEmpty($entry->getLanguage()); 70 $this->assertEmpty($entry->getLanguage());
69 $this->assertEmpty($entry->getMimetype()); 71 $this->assertEmpty($entry->getMimetype());
72 $this->assertEquals(0.0, $entry->getReadingTime());
73 $this->assertEquals('domain.io', $entry->getDomainName());
70 } 74 }
71 75
72 public function testWithContent() 76 public function testWithContent()
@@ -79,7 +83,7 @@ class ContentProxyTest extends KernelTestCase
79 $graby->expects($this->any()) 83 $graby->expects($this->any())
80 ->method('fetchContent') 84 ->method('fetchContent')
81 ->willReturn(array( 85 ->willReturn(array(
82 'html' => 'this is my content', 86 'html' => str_repeat('this is my content', 325),
83 'title' => 'this is my title', 87 'title' => 'this is my title',
84 'url' => 'http://1.1.1.1', 88 'url' => 'http://1.1.1.1',
85 'content_type' => 'text/html', 89 'content_type' => 'text/html',
@@ -96,9 +100,11 @@ class ContentProxyTest extends KernelTestCase
96 100
97 $this->assertEquals('http://1.1.1.1', $entry->getUrl()); 101 $this->assertEquals('http://1.1.1.1', $entry->getUrl());
98 $this->assertEquals('this is my title', $entry->getTitle()); 102 $this->assertEquals('this is my title', $entry->getTitle());
99 $this->assertEquals('this is my content', $entry->getContent()); 103 $this->assertContains('this is my content', $entry->getContent());
100 $this->assertEquals('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture()); 104 $this->assertEquals('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture());
101 $this->assertEquals('text/html', $entry->getMimetype()); 105 $this->assertEquals('text/html', $entry->getMimetype());
102 $this->assertEquals('fr', $entry->getLanguage()); 106 $this->assertEquals('fr', $entry->getLanguage());
107 $this->assertEquals(4.0, $entry->getReadingTime());
108 $this->assertEquals('1.1.1.1', $entry->getDomainName());
103 } 109 }
104} 110}