]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php
Use tecnickcom/tcpdf
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Tests / Helper / ContentProxyTest.php
CommitLineData
558d9aab
JB
1<?php
2
3namespace Wallabag\CoreBundle\Tests\Helper;
4
5use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
6use Wallabag\CoreBundle\Entity\Entry;
7use Wallabag\CoreBundle\Entity\User;
8use Wallabag\CoreBundle\Helper\ContentProxy;
9
10class 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')
98f0929f
JB
21 ->willReturn(array(
22 'html' => false,
23 'title' => '',
24 'url' => '',
25 'content_type' => '',
26 'language' => '',
27 ));
558d9aab
JB
28
29 $proxy = new ContentProxy($graby);
30 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0');
31
32 $this->assertEquals('http://0.0.0.0', $entry->getUrl());
33 $this->assertEmpty($entry->getTitle());
34 $this->assertEquals('<p>Unable to retrieve readable content.</p>', $entry->getContent());
35 $this->assertEmpty($entry->getPreviewPicture());
36 $this->assertEmpty($entry->getMimetype());
98f0929f 37 $this->assertEmpty($entry->getLanguage());
558d9aab
JB
38 }
39
40 public function testWithEmptyContentButOG()
41 {
42 $graby = $this->getMockBuilder('Graby\Graby')
43 ->setMethods(array('fetchContent'))
44 ->disableOriginalConstructor()
45 ->getMock();
46
47 $graby->expects($this->any())
48 ->method('fetchContent')
98f0929f
JB
49 ->willReturn(array(
50 'html' => false,
51 'title' => '',
52 'url' => '',
53 'content_type' => '',
54 'language' => '',
55 'open_graph' => array(
56 'og_title' => 'my title',
57 'og_description' => 'desc',
58 ),
59 ));
558d9aab
JB
60
61 $proxy = new ContentProxy($graby);
62 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0');
63
64 $this->assertEquals('http://0.0.0.0', $entry->getUrl());
65 $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());
67 $this->assertEmpty($entry->getPreviewPicture());
98f0929f 68 $this->assertEmpty($entry->getLanguage());
558d9aab
JB
69 $this->assertEmpty($entry->getMimetype());
70 }
71
72 public function testWithContent()
73 {
74 $graby = $this->getMockBuilder('Graby\Graby')
75 ->setMethods(array('fetchContent'))
76 ->disableOriginalConstructor()
77 ->getMock();
78
79 $graby->expects($this->any())
80 ->method('fetchContent')
81 ->willReturn(array(
82 'html' => 'this is my content',
83 'title' => 'this is my title',
84 'url' => 'http://1.1.1.1',
85 'content_type' => 'text/html',
98f0929f 86 'language' => 'fr',
558d9aab
JB
87 'open_graph' => array(
88 'og_title' => 'my OG title',
89 'og_description' => 'OG desc',
f1e29e69
JB
90 'og_image' => 'http://3.3.3.3/cover.jpg',
91 ),
558d9aab
JB
92 ));
93
94 $proxy = new ContentProxy($graby);
95 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0');
96
97 $this->assertEquals('http://1.1.1.1', $entry->getUrl());
98 $this->assertEquals('this is my title', $entry->getTitle());
99 $this->assertEquals('this is my content', $entry->getContent());
100 $this->assertEquals('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture());
101 $this->assertEquals('text/html', $entry->getMimetype());
98f0929f 102 $this->assertEquals('fr', $entry->getLanguage());
558d9aab
JB
103 }
104}