]> git.mxchange.org Git - friendica.git/blob - tests/src/Util/ImagesTest.php
Introduce DiceTestTrait for partial mocking DI:: calls
[friendica.git] / tests / src / Util / ImagesTest.php
1 <?php
2
3 namespace Friendica\Test\src\Util;
4
5 use Friendica\Test\DiceTestTrait;
6 use Friendica\Test\MockedTest;
7 use Friendica\Util\Images;
8 use GuzzleHttp\Handler\MockHandler;
9 use GuzzleHttp\Psr7\Response;
10
11 class ImagesTest extends MockedTest
12 {
13         use DiceTestTrait;
14
15         public static function setUpBeforeClass(): void
16         {
17                 parent::setUpBeforeClass();
18
19                 self::setUpDice();
20         }
21
22         public function dataImages()
23         {
24                 return [
25                         'image' => [
26                                 'url'     => 'https://pbs.twimg.com/profile_images/2365515285/9re7kx4xmc0eu9ppmado.png',
27                                 'headers' => [
28                                         'Server'                        => 'tsa_b',
29                                         'Content-Type'                  => 'image/png',
30                                         'Cache-Control'                 => 'max-age=604800,must-revalidate',
31                                         'Last-Modified'                 => 'Thu,04Nov201001:42:54GMT',
32                                         'Content-Length'                => '24875',
33                                         'Access-Control-Allow-Origin'   => '*',
34                                         'Access-Control-Expose-Headers' => 'Content-Length',
35                                         'Date'                          => 'Mon,23Aug202112:39:00GMT',
36                                         'Connection'                    => 'keep-alive',
37                                 ],
38                                 'data'      => file_get_contents(__DIR__ . '/../../datasets/curl/image.content'),
39                                 'assertion' => [
40                                         '0'    => '400',
41                                         '1'    => '400',
42                                         '2'    => '3',
43                                         '3'    => 'width="400" height="400"',
44                                         'bits' => '8',
45                                         'mime' => 'image/png',
46                                         'size' => '24875',
47                                 ]
48                         ],
49                         'emptyUrl' => [
50                                 'url'       => '',
51                                 'headers'   => [],
52                                 'data'      => '',
53                                 'assertion' => [],
54                         ],
55                 ];
56         }
57
58         /**
59          * Test the Images::getInfoFromURL() method
60          *
61          * @dataProvider dataImages
62          */
63         public function testGetInfoFromURL(string $url, array $headers, string $data, array $assertion)
64         {
65                 self::$httpRequestHandler->setHandler(new MockHandler([
66                         new Response(200, $headers, $data),
67                 ]));
68
69                 self::assertArraySubset($assertion, Images::getInfoFromURL($url));
70         }
71 }