X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2FWallabag%2FCoreBundle%2FHelper%2FContentProxyTest.php;h=c1a56b89b0600f03482bd2b9d28649958ab1e1d5;hb=refs%2Fheads%2Furl-3529;hp=5c99e4618970b30e7ba81fc6f3fbc68de3f61986;hpb=773ac5b0f7a56ff2527601498b0822d6ef8bfa40;p=github%2Fwallabag%2Fwallabag.git diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index 5c99e461..c1a56b89 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php @@ -5,6 +5,7 @@ namespace Tests\Wallabag\CoreBundle\Helper; use Graby\Graby; use Monolog\Handler\TestHandler; use Monolog\Logger; +use PHPUnit\Framework\TestCase; use Psr\Log\NullLogger; use Symfony\Component\Validator\ConstraintViolation; use Symfony\Component\Validator\ConstraintViolationList; @@ -15,7 +16,7 @@ use Wallabag\CoreBundle\Helper\ContentProxy; use Wallabag\CoreBundle\Helper\RuleBasedTagger; use Wallabag\UserBundle\Entity\User; -class ContentProxyTest extends \PHPUnit_Framework_TestCase +class ContentProxyTest extends TestCase { private $fetchingErrorMessage = 'wallabag can\'t retrieve contents for this article. Please troubleshoot this issue.'; @@ -220,7 +221,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $tagger->expects($this->once()) ->method('tag'); - $validator = $this->getValidator(); + $validator = $this->getValidator(false); $validator->expects($this->once()) ->method('validate') ->willReturn(new ConstraintViolationList([new ConstraintViolation('oops', 'oops', [], 'oops', 'language', 'dontexist')])); @@ -261,7 +262,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $tagger->expects($this->once()) ->method('tag'); - $validator = $this->getValidator(); + $validator = $this->getValidator(false); $validator->expects($this->exactly(2)) ->method('validate') ->will($this->onConsecutiveCalls( @@ -531,6 +532,32 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $this->assertSame('1.1.1.1', $entry->getDomainName()); } + public function testWithChangedUrl() + { + $tagger = $this->getTaggerMock(); + $tagger->expects($this->once()) + ->method('tag'); + + $proxy = new ContentProxy((new Graby()), $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage, true); + $entry = new Entry(new User()); + $proxy->updateEntry( + $entry, + 'http://0.0.0.0', + [ + 'html' => false, + 'title' => '', + 'url' => 'http://1.1.1.1', + 'content_type' => '', + 'language' => '', + ], + true + ); + + $this->assertSame('http://1.1.1.1', $entry->getUrl()); + $this->assertSame('1.1.1.1', $entry->getDomainName()); + $this->assertSame('http://0.0.0.0', $entry->getOriginUrl()); + } + private function getTaggerMock() { return $this->getMockBuilder(RuleBasedTagger::class) @@ -544,11 +571,19 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase return new NullLogger(); } - private function getValidator() + private function getValidator($withDefaultMock = true) { - return $this->getMockBuilder(RecursiveValidator::class) + $mock = $this->getMockBuilder(RecursiveValidator::class) ->setMethods(['validate']) ->disableOriginalConstructor() ->getMock(); + + if ($withDefaultMock) { + $mock->expects($this->any()) + ->method('validate') + ->willReturn(new ConstraintViolationList()); + } + + return $mock; } }