aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-03-27 20:35:56 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-03-27 20:54:57 +0200
commit4d0ec0e72108ff47952906e5d968a7c3eb0a76f9 (patch)
treeb8e9cd86010368631296c22a2352f5dbedb429a1 /src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php
parent5d6f6f56a2a0f72a67c2d3f96eb61986cf821a1e (diff)
downloadwallabag-4d0ec0e72108ff47952906e5d968a7c3eb0a76f9.tar.gz
wallabag-4d0ec0e72108ff47952906e5d968a7c3eb0a76f9.tar.zst
wallabag-4d0ec0e72108ff47952906e5d968a7c3eb0a76f9.zip
Fix some Scrutinizer issues
Diffstat (limited to 'src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php')
-rw-r--r--src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php b/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php
index f58b5828..74bfb054 100644
--- a/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php
+++ b/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php
@@ -10,6 +10,40 @@ use Wallabag\UserBundle\Entity\User;
10 10
11class ContentProxyTest extends \PHPUnit_Framework_TestCase 11class ContentProxyTest extends \PHPUnit_Framework_TestCase
12{ 12{
13 public function testWithBadUrl()
14 {
15 $tagger = $this->getTaggerMock();
16 $tagger->expects($this->once())
17 ->method('tag');
18
19 $graby = $this->getMockBuilder('Graby\Graby')
20 ->setMethods(array('fetchContent'))
21 ->disableOriginalConstructor()
22 ->getMock();
23
24 $graby->expects($this->any())
25 ->method('fetchContent')
26 ->willReturn(array(
27 'html' => false,
28 'title' => '',
29 'url' => '',
30 'content_type' => '',
31 'language' => '',
32 ));
33
34 $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger());
35 $entry = $proxy->updateEntry(new Entry(new User()), 'http://user@:80');
36
37 $this->assertEquals('http://user@:80', $entry->getUrl());
38 $this->assertEmpty($entry->getTitle());
39 $this->assertEquals('<p>Unable to retrieve readable content.</p>', $entry->getContent());
40 $this->assertEmpty($entry->getPreviewPicture());
41 $this->assertEmpty($entry->getMimetype());
42 $this->assertEmpty($entry->getLanguage());
43 $this->assertEquals(0.0, $entry->getReadingTime());
44 $this->assertEquals(false, $entry->getDomainName());
45 }
46
13 public function testWithEmptyContent() 47 public function testWithEmptyContent()
14 { 48 {
15 $tagger = $this->getTaggerMock(); 49 $tagger = $this->getTaggerMock();
@@ -121,6 +155,57 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
121 $this->assertEquals('1.1.1.1', $entry->getDomainName()); 155 $this->assertEquals('1.1.1.1', $entry->getDomainName());
122 } 156 }
123 157
158 public function testWithForcedContent()
159 {
160 $tagger = $this->getTaggerMock();
161 $tagger->expects($this->once())
162 ->method('tag');
163
164 $graby = $this->getMockBuilder('Graby\Graby')->getMock();
165
166 $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger());
167 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0', [
168 'html' => str_repeat('this is my content', 325),
169 'title' => 'this is my title',
170 'url' => 'http://1.1.1.1',
171 'content_type' => 'text/html',
172 'language' => 'fr',
173 ]);
174
175 $this->assertEquals('http://1.1.1.1', $entry->getUrl());
176 $this->assertEquals('this is my title', $entry->getTitle());
177 $this->assertContains('this is my content', $entry->getContent());
178 $this->assertEquals('text/html', $entry->getMimetype());
179 $this->assertEquals('fr', $entry->getLanguage());
180 $this->assertEquals(4.0, $entry->getReadingTime());
181 $this->assertEquals('1.1.1.1', $entry->getDomainName());
182 }
183
184 public function testTaggerThrowException()
185 {
186 $graby = $this->getMockBuilder('Graby\Graby')
187 ->disableOriginalConstructor()
188 ->getMock();
189
190 $tagger = $this->getTaggerMock();
191 $tagger->expects($this->once())
192 ->method('tag')
193 ->will($this->throwException(new \Exception()));
194
195 $tagRepo = $this->getTagRepositoryMock();
196 $proxy = new ContentProxy($graby, $tagger, $tagRepo, $this->getLogger());
197
198 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0', [
199 'html' => str_repeat('this is my content', 325),
200 'title' => 'this is my title',
201 'url' => 'http://1.1.1.1',
202 'content_type' => 'text/html',
203 'language' => 'fr',
204 ]);
205
206 $this->assertCount(0, $entry->getTags());
207 }
208
124 public function testAssignTagsWithArrayAndExtraSpaces() 209 public function testAssignTagsWithArrayAndExtraSpaces()
125 { 210 {
126 $graby = $this->getMockBuilder('Graby\Graby') 211 $graby = $this->getMockBuilder('Graby\Graby')