From 98f0929f168a336079456f65b6ca41e84b22efff Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 20 Sep 2015 22:37:27 +0200 Subject: [PATCH] Handle entry in language Fix #1333 --- src/Wallabag/CoreBundle/Entity/Entry.php | 31 +++++++++++++++++++ src/Wallabag/CoreBundle/Entity/User.php | 5 ++- .../CoreBundle/Helper/ContentProxy.php | 1 + .../Tests/Helper/ContentProxyTest.php | 24 ++++++++++++-- 4 files changed, 56 insertions(+), 5 deletions(-) diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index e684c9b10..7108889e0 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -94,6 +94,13 @@ class Entry */ private $mimetype; + /** + * @var string + * + * @ORM\Column(name="language", type="text", nullable=true) + */ + private $language; + /** * @var int * @@ -450,4 +457,28 @@ class Entry { return $this->previewPicture; } + + /** + * Set language. + * + * @param string $language + * + * @return Entry + */ + public function setLanguage($language) + { + $this->language = $language; + + return $this; + } + + /** + * Get language. + * + * @return string + */ + public function getLanguage() + { + return $this->language; + } } diff --git a/src/Wallabag/CoreBundle/Entity/User.php b/src/Wallabag/CoreBundle/Entity/User.php index eeae331e2..a60023523 100644 --- a/src/Wallabag/CoreBundle/Entity/User.php +++ b/src/Wallabag/CoreBundle/Entity/User.php @@ -7,7 +7,6 @@ use Doctrine\ORM\Mapping as ORM; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\AdvancedUserInterface; -use Symfony\Component\Validator\Constraints as Assert; use JMS\Serializer\Annotation\ExclusionPolicy; use JMS\Serializer\Annotation\Expose; use FOS\UserBundle\Model\User as BaseUser; @@ -74,8 +73,8 @@ class User extends BaseUser implements AdvancedUserInterface, \Serializable public function __construct() { parent::__construct(); - $this->entries = new ArrayCollection(); - $this->tags = new ArrayCollection(); + $this->entries = new ArrayCollection(); + $this->tags = new ArrayCollection(); } /** diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php index 4565d8e7a..3de8828f9 100644 --- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php +++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php @@ -49,6 +49,7 @@ class ContentProxy $entry->setUrl($content['url'] ?: $url); $entry->setTitle($title); $entry->setContent($html); + $entry->setLanguage($content['language']); $entry->setMimetype($content['content_type']); if (isset($content['open_graph']['og_image'])) { diff --git a/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php b/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php index 71a004ffe..30065d6b7 100644 --- a/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php +++ b/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php @@ -18,7 +18,13 @@ class ContentProxyTest extends KernelTestCase $graby->expects($this->any()) ->method('fetchContent') - ->willReturn(array('html' => false, 'title' => '', 'url' => '', 'content_type' => '')); + ->willReturn(array( + 'html' => false, + 'title' => '', + 'url' => '', + 'content_type' => '', + 'language' => '', + )); $proxy = new ContentProxy($graby); $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); @@ -28,6 +34,7 @@ class ContentProxyTest extends KernelTestCase $this->assertEquals('

Unable to retrieve readable content.

', $entry->getContent()); $this->assertEmpty($entry->getPreviewPicture()); $this->assertEmpty($entry->getMimetype()); + $this->assertEmpty($entry->getLanguage()); } public function testWithEmptyContentButOG() @@ -39,7 +46,17 @@ class ContentProxyTest extends KernelTestCase $graby->expects($this->any()) ->method('fetchContent') - ->willReturn(array('html' => false, 'title' => '', 'url' => '', 'content_type' => '', 'open_graph' => array('og_title' => 'my title', 'og_description' => 'desc'))); + ->willReturn(array( + 'html' => false, + 'title' => '', + 'url' => '', + 'content_type' => '', + 'language' => '', + 'open_graph' => array( + 'og_title' => 'my title', + 'og_description' => 'desc', + ), + )); $proxy = new ContentProxy($graby); $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); @@ -48,6 +65,7 @@ class ContentProxyTest extends KernelTestCase $this->assertEquals('my title', $entry->getTitle()); $this->assertEquals('

Unable to retrieve readable content.

But we found a short description:

desc', $entry->getContent()); $this->assertEmpty($entry->getPreviewPicture()); + $this->assertEmpty($entry->getLanguage()); $this->assertEmpty($entry->getMimetype()); } @@ -65,6 +83,7 @@ class ContentProxyTest extends KernelTestCase 'title' => 'this is my title', 'url' => 'http://1.1.1.1', 'content_type' => 'text/html', + 'language' => 'fr', 'open_graph' => array( 'og_title' => 'my OG title', 'og_description' => 'OG desc', @@ -80,5 +99,6 @@ class ContentProxyTest extends KernelTestCase $this->assertEquals('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()); } }