| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- /**
- * Test: Nette\Utils\Image send method exceptions.
- * @phpExtension gd
- */
- declare(strict_types=1);
- use Nette\Utils\Image;
- use Tester\Assert;
- require __DIR__ . '/../bootstrap.php';
- $main = Image::fromFile(__DIR__ . '/fixtures.images/alpha1.png');
- test('', function () use ($main) {
- ob_start();
- $main->send();
- $data = ob_get_clean();
- Assert::contains('JFIF', $data);
- if (PHP_SAPI !== 'cli') {
- Assert::contains('Content-Type: image/jpeg', headers_list());
- }
- });
- test('', function () use ($main) {
- ob_start();
- $main->send(Image::PNG);
- $data = ob_get_clean();
- Assert::contains('PNG', $data);
- if (PHP_SAPI !== 'cli') {
- Assert::contains('Content-Type: image/png', headers_list());
- }
- });
- test('', function () use ($main) {
- if (!Image::isTypeSupported(Image::WEBP)) {
- return;
- }
- ob_start();
- $main->send(Image::WEBP);
- $data = ob_get_clean();
- Assert::contains('WEBP', $data);
- if (PHP_SAPI !== 'cli') {
- Assert::contains('Content-Type: image/webp', headers_list());
- }
- });
- Assert::exception(
- fn() => $main->send(IMG_WBMP),
- Nette\InvalidArgumentException::class,
- sprintf('Unsupported image type \'%d\'.', IMG_WBMP),
- );
|