3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
22 namespace Friendica\Test\src\Util;
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;
31 class ImagesTest extends MockedTest
33 use DiceHttpMockHandlerTrait;
34 use ArraySubsetAsserts;
36 protected function setUp(): void
40 $this->setupHttpMockHandler();
43 public function dataImages()
47 'url' => 'https://pbs.twimg.com/profile_images/2365515285/9re7kx4xmc0eu9ppmado.png',
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',
59 'data' => file_get_contents(__DIR__ . '/../../datasets/curl/image.content'),
64 '3' => 'width="400" height="400"',
66 'mime' => 'image/png',
80 * Test the Images::getInfoFromURL() method (only remote images, not local/relative!)
82 * @dataProvider dataImages
84 public function testGetInfoFromRemotURL(string $url, array $headers, string $data, array $assertion)
86 $this->httpRequestHandler->setHandler(new MockHandler([
87 new Response(200, $headers, $data),
90 self::assertArraySubset($assertion, Images::getInfoFromURL($url));