X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2Fhttp%2FMetadataRetrieverTest.php;h=cae65091f77c81c1bf01e837de3c20be8b4e245b;hb=ffa39719a17982e6a6cac9bc3f758aa12fa69973;hp=2a1838e81cb1ad59e5f7b62a8326127219469cc2;hpb=4cf3564d28dc8e4d08a3e64f09ad045ffbde97ae;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/http/MetadataRetrieverTest.php b/tests/http/MetadataRetrieverTest.php index 2a1838e8..cae65091 100644 --- a/tests/http/MetadataRetrieverTest.php +++ b/tests/http/MetadataRetrieverTest.php @@ -38,18 +38,36 @@ class MetadataRetrieverTest extends TestCase $remoteTitle = 'Remote Title '; $remoteDesc = 'Sometimes the meta description is relevant.'; $remoteTags = 'abc def'; + $remoteCharset = 'utf-8'; $expectedResult = [ - 'title' => $remoteTitle, + 'title' => trim($remoteTitle), 'description' => $remoteDesc, 'tags' => $remoteTags, ]; + $this->httpAccess + ->expects(static::once()) + ->method('getCurlHeaderCallback') + ->willReturnCallback( + function (&$charset) use ( + $remoteCharset + ): callable { + return function () use ( + &$charset, + $remoteCharset + ): void { + $charset = $remoteCharset; + }; + } + ) + ; $this->httpAccess ->expects(static::once()) ->method('getCurlDownloadCallback') ->willReturnCallback( function (&$charset, &$title, &$description, &$tags) use ( + $remoteCharset, $remoteTitle, $remoteDesc, $remoteTags @@ -59,11 +77,13 @@ class MetadataRetrieverTest extends TestCase &$title, &$description, &$tags, + $remoteCharset, $remoteTitle, $remoteDesc, $remoteTags ): void { - $charset = 'ISO-8859-1'; + static::assertSame($remoteCharset, $charset); + $title = $remoteTitle; $description = $remoteDesc; $tags = $remoteTags; @@ -75,8 +95,9 @@ class MetadataRetrieverTest extends TestCase ->expects(static::once()) ->method('getHttpResponse') ->with($url, 30, 4194304) - ->willReturnCallback(function($url, $timeout, $maxBytes, $callback): void { - $callback(); + ->willReturnCallback(function($url, $timeout, $maxBytes, $headerCallback, $dlCallback): void { + $headerCallback(); + $dlCallback(); }) ; @@ -102,8 +123,17 @@ class MetadataRetrieverTest extends TestCase ->expects(static::once()) ->method('getCurlDownloadCallback') ->willReturnCallback( - function (&$charset, &$title, &$description, &$tags): callable { - return function () use (&$charset, &$title, &$description, &$tags): void {}; + function (): callable { + return function (): void {}; + } + ) + ; + $this->httpAccess + ->expects(static::once()) + ->method('getCurlHeaderCallback') + ->willReturnCallback( + function (): callable { + return function (): void {}; } ) ; @@ -111,8 +141,9 @@ class MetadataRetrieverTest extends TestCase ->expects(static::once()) ->method('getHttpResponse') ->with($url, 30, 4194304) - ->willReturnCallback(function($url, $timeout, $maxBytes, $callback): void { - $callback(); + ->willReturnCallback(function($url, $timeout, $maxBytes, $headerCallback, $dlCallback): void { + $headerCallback(); + $dlCallback(); }) ;