]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | namespace Wallabag\CoreBundle\Tests\Helper; | |
4 | ||
5 | use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | |
6 | use Wallabag\CoreBundle\Entity\Entry; | |
7 | use Wallabag\CoreBundle\Entity\User; | |
8 | use Wallabag\CoreBundle\Helper\ContentProxy; | |
9 | ||
10 | class ContentProxyTest extends KernelTestCase | |
11 | { | |
12 | public function testWithEmptyContent() | |
13 | { | |
14 | $graby = $this->getMockBuilder('Graby\Graby') | |
15 | ->setMethods(array('fetchContent')) | |
16 | ->disableOriginalConstructor() | |
17 | ->getMock(); | |
18 | ||
19 | $graby->expects($this->any()) | |
20 | ->method('fetchContent') | |
21 | ->willReturn(array('html' => false, 'title' => '', 'url' => '', 'content_type' => '')); | |
22 | ||
23 | $proxy = new ContentProxy($graby); | |
24 | $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); | |
25 | ||
26 | $this->assertEquals('http://0.0.0.0', $entry->getUrl()); | |
27 | $this->assertEmpty($entry->getTitle()); | |
28 | $this->assertEquals('<p>Unable to retrieve readable content.</p>', $entry->getContent()); | |
29 | $this->assertEmpty($entry->getPreviewPicture()); | |
30 | $this->assertEmpty($entry->getMimetype()); | |
31 | } | |
32 | ||
33 | public function testWithEmptyContentButOG() | |
34 | { | |
35 | $graby = $this->getMockBuilder('Graby\Graby') | |
36 | ->setMethods(array('fetchContent')) | |
37 | ->disableOriginalConstructor() | |
38 | ->getMock(); | |
39 | ||
40 | $graby->expects($this->any()) | |
41 | ->method('fetchContent') | |
42 | ->willReturn(array('html' => false, 'title' => '', 'url' => '', 'content_type' => '', 'open_graph' => array('og_title' => 'my title', 'og_description' => 'desc'))); | |
43 | ||
44 | $proxy = new ContentProxy($graby); | |
45 | $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); | |
46 | ||
47 | $this->assertEquals('http://0.0.0.0', $entry->getUrl()); | |
48 | $this->assertEquals('my title', $entry->getTitle()); | |
49 | $this->assertEquals('<p>Unable to retrieve readable content.</p><p><i>But we found a short description: </i></p>desc', $entry->getContent()); | |
50 | $this->assertEmpty($entry->getPreviewPicture()); | |
51 | $this->assertEmpty($entry->getMimetype()); | |
52 | } | |
53 | ||
54 | public function testWithContent() | |
55 | { | |
56 | $graby = $this->getMockBuilder('Graby\Graby') | |
57 | ->setMethods(array('fetchContent')) | |
58 | ->disableOriginalConstructor() | |
59 | ->getMock(); | |
60 | ||
61 | $graby->expects($this->any()) | |
62 | ->method('fetchContent') | |
63 | ->willReturn(array( | |
64 | 'html' => 'this is my content', | |
65 | 'title' => 'this is my title', | |
66 | 'url' => 'http://1.1.1.1', | |
67 | 'content_type' => 'text/html', | |
68 | 'open_graph' => array( | |
69 | 'og_title' => 'my OG title', | |
70 | 'og_description' => 'OG desc', | |
71 | 'og_image' => 'http://3.3.3.3/cover.jpg' | |
72 | ) | |
73 | )); | |
74 | ||
75 | $proxy = new ContentProxy($graby); | |
76 | $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); | |
77 | ||
78 | $this->assertEquals('http://1.1.1.1', $entry->getUrl()); | |
79 | $this->assertEquals('this is my title', $entry->getTitle()); | |
80 | $this->assertEquals('this is my content', $entry->getContent()); | |
81 | $this->assertEquals('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture()); | |
82 | $this->assertEquals('text/html', $entry->getMimetype()); | |
83 | } | |
84 | } |