2021-08-23 09:47:41 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Friendica\Test\src\Util;
|
|
|
|
|
2021-12-10 15:40:07 -05:00
|
|
|
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
|
2021-08-24 18:13:50 -04:00
|
|
|
use Friendica\Test\DiceHttpMockHandlerTrait;
|
2021-08-23 09:47:41 -04:00
|
|
|
use Friendica\Test\MockedTest;
|
2021-08-24 07:19:17 -04:00
|
|
|
use Friendica\Util\Images;
|
|
|
|
use GuzzleHttp\Handler\MockHandler;
|
|
|
|
use GuzzleHttp\Psr7\Response;
|
2021-08-23 09:47:41 -04:00
|
|
|
|
|
|
|
class ImagesTest extends MockedTest
|
|
|
|
{
|
2021-08-24 18:13:50 -04:00
|
|
|
use DiceHttpMockHandlerTrait;
|
2021-12-10 15:40:07 -05:00
|
|
|
use ArraySubsetAsserts;
|
2021-08-24 07:19:17 -04:00
|
|
|
|
2021-08-24 18:13:50 -04:00
|
|
|
protected function setUp(): void
|
2021-08-24 07:19:17 -04:00
|
|
|
{
|
2021-08-24 18:13:50 -04:00
|
|
|
parent::setUp();
|
2021-08-24 07:19:17 -04:00
|
|
|
|
2021-08-24 18:13:50 -04:00
|
|
|
$this->setupHttpMockHandler();
|
2021-08-24 07:19:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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' => [],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-08-24 18:13:50 -04:00
|
|
|
* Test the Images::getInfoFromURL() method (only remote images, not local/relative!)
|
2021-08-24 07:19:17 -04:00
|
|
|
*
|
|
|
|
* @dataProvider dataImages
|
|
|
|
*/
|
2021-08-24 18:13:50 -04:00
|
|
|
public function testGetInfoFromRemotURL(string $url, array $headers, string $data, array $assertion)
|
2021-08-23 09:47:41 -04:00
|
|
|
{
|
2021-08-24 18:13:50 -04:00
|
|
|
$this->httpRequestHandler->setHandler(new MockHandler([
|
2021-08-24 07:19:17 -04:00
|
|
|
new Response(200, $headers, $data),
|
|
|
|
]));
|
2021-08-23 09:47:41 -04:00
|
|
|
|
2021-08-24 07:19:17 -04:00
|
|
|
self::assertArraySubset($assertion, Images::getInfoFromURL($url));
|
2021-08-23 09:47:41 -04:00
|
|
|
}
|
|
|
|
}
|