X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2FWallabag%2FCoreBundle%2FHelper%2FContentProxyTest.php;h=5c99e4618970b30e7ba81fc6f3fbc68de3f61986;hb=773ac5b0f7a56ff2527601498b0822d6ef8bfa40;hp=c63671c4613e4e536f84f9da3752f00911ee5ecf;hpb=38520658addc217f127b0627ea28dcf8d6e6178c;p=github%2Fwallabag%2Fwallabag.git diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index c63671c4..5c99e461 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php @@ -51,7 +51,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $this->assertEmpty($entry->getMimetype()); $this->assertEmpty($entry->getLanguage()); $this->assertSame(0.0, $entry->getReadingTime()); - $this->assertSame(null, $entry->getDomainName()); + $this->assertNull($entry->getDomainName()); } public function testWithEmptyContent() @@ -221,12 +221,9 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase ->method('tag'); $validator = $this->getValidator(); - $validator->expects($this->exactly(2)) + $validator->expects($this->once()) ->method('validate') - ->will($this->onConsecutiveCalls( - new ConstraintViolationList([new ConstraintViolation('oops', 'oops', [], 'oops', 'language', 'dontexist')]), - new ConstraintViolationList() - )); + ->willReturn(new ConstraintViolationList([new ConstraintViolation('oops', 'oops', [], 'oops', 'language', 'dontexist')])); $graby = $this->getMockBuilder('Graby\Graby') ->setMethods(['fetchContent']) @@ -314,7 +311,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $tagger->expects($this->once()) ->method('tag'); - $proxy = new ContentProxy((new Graby()), $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy((new Graby()), $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage, true); $entry = new Entry(new User()); $proxy->updateEntry( $entry, @@ -344,6 +341,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $this->assertContains('Jeremy', $entry->getPublishedBy()); $this->assertContains('Nico', $entry->getPublishedBy()); $this->assertContains('Thomas', $entry->getPublishedBy()); + $this->assertNotNull($entry->getHeaders(), 'Headers are stored, so value is not null'); $this->assertContains('no-cache', $entry->getHeaders()); } @@ -498,6 +496,41 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $this->assertSame('1.1.1.1', $entry->getDomainName()); } + public function testWithImageAsContent() + { + $tagger = $this->getTaggerMock(); + $tagger->expects($this->once()) + ->method('tag'); + + $graby = $this->getMockBuilder('Graby\Graby') + ->setMethods(['fetchContent']) + ->disableOriginalConstructor() + ->getMock(); + + $graby->expects($this->any()) + ->method('fetchContent') + ->willReturn([ + 'html' => '

', + 'title' => 'this is my title', + 'url' => 'http://1.1.1.1/image.jpg', + 'content_type' => 'image/jpeg', + 'status' => '200', + 'open_graph' => [], + ]); + + $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); + $entry = new Entry(new User()); + $proxy->updateEntry($entry, 'http://0.0.0.0'); + + $this->assertSame('http://1.1.1.1/image.jpg', $entry->getUrl()); + $this->assertSame('this is my title', $entry->getTitle()); + $this->assertContains('http://1.1.1.1/image.jpg', $entry->getContent()); + $this->assertSame('http://1.1.1.1/image.jpg', $entry->getPreviewPicture()); + $this->assertSame('image/jpeg', $entry->getMimetype()); + $this->assertSame('200', $entry->getHttpStatus()); + $this->assertSame('1.1.1.1', $entry->getDomainName()); + } + private function getTaggerMock() { return $this->getMockBuilder(RuleBasedTagger::class)