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 protected function tearDown(): void
45 $this->tearDownFixtures();
50 public function dataImages()
54 'url' => 'https://pbs.twimg.com/profile_images/2365515285/9re7kx4xmc0eu9ppmado.png',
57 'Content-Type' => 'image/png',
58 'Cache-Control' => 'max-age=604800,must-revalidate',
59 'Last-Modified' => 'Thu,04Nov201001:42:54GMT',
60 'Content-Length' => '24875',
61 'Access-Control-Allow-Origin' => '*',
62 'Access-Control-Expose-Headers' => 'Content-Length',
63 'Date' => 'Mon,23Aug202112:39:00GMT',
64 'Connection' => 'keep-alive',
66 'data' => file_get_contents(__DIR__ . '/../../datasets/curl/image.content'),
71 '3' => 'width="400" height="400"',
73 'mime' => 'image/png',
87 * Test the Images::getInfoFromURL() method (only remote images, not local/relative!)
89 * @dataProvider dataImages
91 public function testGetInfoFromRemotURL(string $url, array $headers, string $data, array $assertion)
93 $this->httpRequestHandler->setHandler(new MockHandler([
94 new Response(200, $headers, $data),
97 self::assertArraySubset($assertion, Images::getInfoFromURL($url));