X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=tests%2Fsrc%2FUtil%2FImagesTest.php;h=8e2881aa6639d5e1d524febe07c4096249c9af17;hb=3d8e82d95d9cc76b45a8db301b22c4111f335e1c;hp=d35f9c4eca5179587c9a1231df215d91b9d0046e;hpb=3eb2abdb2aec830d0d17d1e14695273dbcde5328;p=friendica.git diff --git a/tests/src/Util/ImagesTest.php b/tests/src/Util/ImagesTest.php index d35f9c4eca..8e2881aa66 100644 --- a/tests/src/Util/ImagesTest.php +++ b/tests/src/Util/ImagesTest.php @@ -1,13 +1,92 @@ . + * + */ namespace Friendica\Test\src\Util; +use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts; +use Friendica\Test\DiceHttpMockHandlerTrait; use Friendica\Test\MockedTest; +use Friendica\Util\Images; +use GuzzleHttp\Handler\MockHandler; +use GuzzleHttp\Psr7\Response; class ImagesTest extends MockedTest { - public function testGetInfoFromURL() + use DiceHttpMockHandlerTrait; + use ArraySubsetAsserts; + + protected function setUp(): void + { + parent::setUp(); + + $this->setupHttpMockHandler(); + } + + public function dataImages() + { + return [ + 'image' => [ + 'url' => 'https://pbs.twimg.com/profile_images/2365515285/9re7kx4xmc0eu9ppmado.png', + 'headers' => [ + 'Server' => 'tsa_b', + 'Content-Type' => 'image/png', + 'Cache-Control' => 'max-age=604800,must-revalidate', + 'Last-Modified' => 'Thu,04Nov201001:42:54GMT', + 'Content-Length' => '24875', + 'Access-Control-Allow-Origin' => '*', + 'Access-Control-Expose-Headers' => 'Content-Length', + 'Date' => 'Mon,23Aug202112:39:00GMT', + 'Connection' => 'keep-alive', + ], + 'data' => file_get_contents(__DIR__ . '/../../datasets/curl/image.content'), + 'assertion' => [ + '0' => '400', + '1' => '400', + '2' => '3', + '3' => 'width="400" height="400"', + 'bits' => '8', + 'mime' => 'image/png', + 'size' => '24875', + ] + ], + 'emptyUrl' => [ + 'url' => '', + 'headers' => [], + 'data' => '', + 'assertion' => [], + ], + ]; + } + + /** + * Test the Images::getInfoFromURL() method (only remote images, not local/relative!) + * + * @dataProvider dataImages + */ + public function testGetInfoFromRemotURL(string $url, array $headers, string $data, array $assertion) { + $this->httpRequestHandler->setHandler(new MockHandler([ + new Response(200, $headers, $data), + ])); + self::assertArraySubset($assertion, Images::getInfoFromURL($url)); } }