]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php
Fix some Scrutinizer issues
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Tests / Helper / ContentProxyTest.php
index f58b58288ede937da35499954e32fdee1e9b5a86..74bfb0547ca0a8df44f1c4933894d141a8bf6ce1 100644 (file)
@@ -10,6 +10,40 @@ use Wallabag\UserBundle\Entity\User;
 
 class ContentProxyTest extends \PHPUnit_Framework_TestCase
 {
+    public function testWithBadUrl()
+    {
+        $tagger = $this->getTaggerMock();
+        $tagger->expects($this->once())
+            ->method('tag');
+
+        $graby = $this->getMockBuilder('Graby\Graby')
+            ->setMethods(array('fetchContent'))
+            ->disableOriginalConstructor()
+            ->getMock();
+
+        $graby->expects($this->any())
+            ->method('fetchContent')
+            ->willReturn(array(
+                'html' => false,
+                'title' => '',
+                'url' => '',
+                'content_type' => '',
+                'language' => '',
+            ));
+
+        $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger());
+        $entry = $proxy->updateEntry(new Entry(new User()), 'http://user@:80');
+
+        $this->assertEquals('http://user@:80', $entry->getUrl());
+        $this->assertEmpty($entry->getTitle());
+        $this->assertEquals('<p>Unable to retrieve readable content.</p>', $entry->getContent());
+        $this->assertEmpty($entry->getPreviewPicture());
+        $this->assertEmpty($entry->getMimetype());
+        $this->assertEmpty($entry->getLanguage());
+        $this->assertEquals(0.0, $entry->getReadingTime());
+        $this->assertEquals(false, $entry->getDomainName());
+    }
+
     public function testWithEmptyContent()
     {
         $tagger = $this->getTaggerMock();
@@ -121,6 +155,57 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
         $this->assertEquals('1.1.1.1', $entry->getDomainName());
     }
 
+    public function testWithForcedContent()
+    {
+        $tagger = $this->getTaggerMock();
+        $tagger->expects($this->once())
+            ->method('tag');
+
+        $graby = $this->getMockBuilder('Graby\Graby')->getMock();
+
+        $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger());
+        $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0', [
+            'html' => str_repeat('this is my content', 325),
+            'title' => 'this is my title',
+            'url' => 'http://1.1.1.1',
+            'content_type' => 'text/html',
+            'language' => 'fr',
+        ]);
+
+        $this->assertEquals('http://1.1.1.1', $entry->getUrl());
+        $this->assertEquals('this is my title', $entry->getTitle());
+        $this->assertContains('this is my content', $entry->getContent());
+        $this->assertEquals('text/html', $entry->getMimetype());
+        $this->assertEquals('fr', $entry->getLanguage());
+        $this->assertEquals(4.0, $entry->getReadingTime());
+        $this->assertEquals('1.1.1.1', $entry->getDomainName());
+    }
+
+    public function testTaggerThrowException()
+    {
+        $graby = $this->getMockBuilder('Graby\Graby')
+            ->disableOriginalConstructor()
+            ->getMock();
+
+        $tagger = $this->getTaggerMock();
+        $tagger->expects($this->once())
+            ->method('tag')
+            ->will($this->throwException(new \Exception()));
+
+        $tagRepo = $this->getTagRepositoryMock();
+        $proxy = new ContentProxy($graby, $tagger, $tagRepo, $this->getLogger());
+
+        $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0', [
+            'html' => str_repeat('this is my content', 325),
+            'title' => 'this is my title',
+            'url' => 'http://1.1.1.1',
+            'content_type' => 'text/html',
+            'language' => 'fr',
+        ]);
+
+        $this->assertCount(0, $entry->getTags());
+    }
+
     public function testAssignTagsWithArrayAndExtraSpaces()
     {
         $graby = $this->getMockBuilder('Graby\Graby')