3 namespace Wallabag\CoreBundle\Tests\Helper
;
5 use Wallabag\CoreBundle\Entity\Entry
;
6 use Wallabag\UserBundle\Entity\User
;
7 use Wallabag\CoreBundle\Helper\ContentProxy
;
9 class ContentProxyTest
extends \PHPUnit_Framework_TestCase
11 public function testWithEmptyContent()
13 $graby = $this->getMockBuilder('Graby\Graby')
14 ->setMethods(array('fetchContent'))
15 ->disableOriginalConstructor()
18 $graby->expects($this->any())
19 ->method('fetchContent')
28 $proxy = new ContentProxy($graby);
29 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0');
31 $this->assertEquals('http://0.0.0.0', $entry->getUrl());
32 $this->assertEmpty($entry->getTitle());
33 $this->assertEquals('<p>Unable to retrieve readable content.</p>', $entry->getContent());
34 $this->assertEmpty($entry->getPreviewPicture());
35 $this->assertEmpty($entry->getMimetype());
36 $this->assertEmpty($entry->getLanguage());
37 $this->assertEquals(0.0, $entry->getReadingTime());
38 $this->assertEquals('0.0.0.0', $entry->getDomainName());
41 public function testWithEmptyContentButOG()
43 $graby = $this->getMockBuilder('Graby\Graby')
44 ->setMethods(array('fetchContent'))
45 ->disableOriginalConstructor()
48 $graby->expects($this->any())
49 ->method('fetchContent')
56 'open_graph' => array(
57 'og_title' => 'my title',
58 'og_description' => 'desc',
62 $proxy = new ContentProxy($graby);
63 $entry = $proxy->updateEntry(new Entry(new User()), 'http://domain.io');
65 $this->assertEquals('http://domain.io', $entry->getUrl());
66 $this->assertEquals('my title', $entry->getTitle());
67 $this->assertEquals('<p>Unable to retrieve readable content.</p><p><i>But we found a short description: </i></p>desc', $entry->getContent());
68 $this->assertEmpty($entry->getPreviewPicture());
69 $this->assertEmpty($entry->getLanguage());
70 $this->assertEmpty($entry->getMimetype());
71 $this->assertEquals(0.0, $entry->getReadingTime());
72 $this->assertEquals('domain.io', $entry->getDomainName());
75 public function testWithContent()
77 $graby = $this->getMockBuilder('Graby\Graby')
78 ->setMethods(array('fetchContent'))
79 ->disableOriginalConstructor()
82 $graby->expects($this->any())
83 ->method('fetchContent')
85 'html' => str_repeat('this is my content', 325),
86 'title' => 'this is my title',
87 'url' => 'http://1.1.1.1',
88 'content_type' => 'text/html',
90 'open_graph' => array(
91 'og_title' => 'my OG title',
92 'og_description' => 'OG desc',
93 'og_image' => 'http://3.3.3.3/cover.jpg',
97 $proxy = new ContentProxy($graby);
98 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0');
100 $this->assertEquals('http://1.1.1.1', $entry->getUrl());
101 $this->assertEquals('this is my title', $entry->getTitle());
102 $this->assertContains('this is my content', $entry->getContent());
103 $this->assertEquals('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture());
104 $this->assertEquals('text/html', $entry->getMimetype());
105 $this->assertEquals('fr', $entry->getLanguage());
106 $this->assertEquals(4.0, $entry->getReadingTime());
107 $this->assertEquals('1.1.1.1', $entry->getDomainName());