Image.send.phpt 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Test: Nette\Utils\Image send method exceptions.
  4. * @phpExtension gd
  5. */
  6. declare(strict_types=1);
  7. use Nette\Utils\Image;
  8. use Tester\Assert;
  9. require __DIR__ . '/../bootstrap.php';
  10. $main = Image::fromFile(__DIR__ . '/fixtures.images/alpha1.png');
  11. test('', function () use ($main) {
  12. ob_start();
  13. $main->send();
  14. $data = ob_get_clean();
  15. Assert::contains('JFIF', $data);
  16. if (PHP_SAPI !== 'cli') {
  17. Assert::contains('Content-Type: image/jpeg', headers_list());
  18. }
  19. });
  20. test('', function () use ($main) {
  21. ob_start();
  22. $main->send(Image::PNG);
  23. $data = ob_get_clean();
  24. Assert::contains('PNG', $data);
  25. if (PHP_SAPI !== 'cli') {
  26. Assert::contains('Content-Type: image/png', headers_list());
  27. }
  28. });
  29. test('', function () use ($main) {
  30. if (!Image::isTypeSupported(Image::WEBP)) {
  31. return;
  32. }
  33. ob_start();
  34. $main->send(Image::WEBP);
  35. $data = ob_get_clean();
  36. Assert::contains('WEBP', $data);
  37. if (PHP_SAPI !== 'cli') {
  38. Assert::contains('Content-Type: image/webp', headers_list());
  39. }
  40. });
  41. Assert::exception(
  42. fn() => $main->send(IMG_WBMP),
  43. Nette\InvalidArgumentException::class,
  44. sprintf('Unsupported image type \'%d\'.', IMG_WBMP),
  45. );