]> git.mxchange.org Git - friendica.git/blob - tests/src/Util/ImagesTest.php
Merge remote-tracking branch 'upstream/2021.12-rc' into user-banner
[friendica.git] / tests / src / Util / ImagesTest.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Test\src\Util;
23
24 use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
25 use Friendica\Test\DiceHttpMockHandlerTrait;
26 use Friendica\Test\MockedTest;
27 use Friendica\Util\Images;
28 use GuzzleHttp\Handler\MockHandler;
29 use GuzzleHttp\Psr7\Response;
30
31 class ImagesTest extends MockedTest
32 {
33         use DiceHttpMockHandlerTrait;
34         use ArraySubsetAsserts;
35
36         protected function setUp(): void
37         {
38                 parent::setUp();
39
40                 $this->setupHttpMockHandler();
41         }
42
43         public function dataImages()
44         {
45                 return [
46                         'image' => [
47                                 'url'     => 'https://pbs.twimg.com/profile_images/2365515285/9re7kx4xmc0eu9ppmado.png',
48                                 'headers' => [
49                                         'Server'                        => 'tsa_b',
50                                         'Content-Type'                  => 'image/png',
51                                         'Cache-Control'                 => 'max-age=604800,must-revalidate',
52                                         'Last-Modified'                 => 'Thu,04Nov201001:42:54GMT',
53                                         'Content-Length'                => '24875',
54                                         'Access-Control-Allow-Origin'   => '*',
55                                         'Access-Control-Expose-Headers' => 'Content-Length',
56                                         'Date'                          => 'Mon,23Aug202112:39:00GMT',
57                                         'Connection'                    => 'keep-alive',
58                                 ],
59                                 'data'      => file_get_contents(__DIR__ . '/../../datasets/curl/image.content'),
60                                 'assertion' => [
61                                         '0'    => '400',
62                                         '1'    => '400',
63                                         '2'    => '3',
64                                         '3'    => 'width="400" height="400"',
65                                         'bits' => '8',
66                                         'mime' => 'image/png',
67                                         'size' => '24875',
68                                 ]
69                         ],
70                         'emptyUrl' => [
71                                 'url'       => '',
72                                 'headers'   => [],
73                                 'data'      => '',
74                                 'assertion' => [],
75                         ],
76                 ];
77         }
78
79         /**
80          * Test the Images::getInfoFromURL() method (only remote images, not local/relative!)
81          *
82          * @dataProvider dataImages
83          */
84         public function testGetInfoFromRemotURL(string $url, array $headers, string $data, array $assertion)
85         {
86                 $this->httpRequestHandler->setHandler(new MockHandler([
87                         new Response(200, $headers, $data),
88                 ]));
89
90                 self::assertArraySubset($assertion, Images::getInfoFromURL($url));
91         }
92 }