-
-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathImage.send.phpt
More file actions
62 lines (43 loc) · 1.15 KB
/
Image.send.phpt
File metadata and controls
62 lines (43 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?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__ . '/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 (!function_exists('imagewebp')) {
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(function () use ($main) { // invalid image type
$main->send(IMG_WBMP);
}, Nette\InvalidArgumentException::class, sprintf('Unsupported image type \'%d\'.', IMG_WBMP));