This repository was archived by the owner on Dec 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptionsTest.php
More file actions
99 lines (77 loc) · 3.01 KB
/
OptionsTest.php
File metadata and controls
99 lines (77 loc) · 3.01 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
test('can set options with individual setters', function (): void {
$options = createOptions();
$options->setWidth(300)
->setHeight(400)
->setResizingType('fill')
->setGravity('sm');
expect($options)->toBeOptions();
expect($options->toString())->toBe('width:300/height:400/resizing_type:fill/gravity:sm');
});
test('can set options with constructor array', function (): void {
$options = createOptions([
'width' => 300,
'height' => 400,
'resizingType' => 'fill',
'gravity' => 'sm',
]);
expect($options)->toBeOptions();
expect($options->toString())->toBe('width:300/height:400/resizing_type:fill/gravity:sm');
});
test('can handle complex options', function (): void {
$options = createOptions();
$options->setPreset('sharp')
->setResize('fill', 300, 400, false)
->setGravity('sm')
->setWatermark(0.5, 'ce', 10, 10, 0.2)
->setQuality(80)
->setFormat('png');
expect($options)->toBeOptions();
expect($options->toString())->toBe('preset:sharp/resize:fill:300:400:0/gravity:sm/watermark:0.5:ce:10:10:0.2/quality:80/format:png');
});
test('magic __toString behaves like toString method', function (): void {
$options = createOptions();
$options->setPreset('sharp')
->setResize('fill', 300, 400, false);
expect($options->toString())->toBe((string) $options);
});
test('boolean values are converted to 1 and 0', function (): void {
$options = createOptions();
$options->setEnlarge(true)
->setAutoRotate(false)
->setStripMetadata(true);
expect($options->toString())->toBe('enlarge:1/auto_rotate:0/strip_metadata:1');
});
test('options requiring base64 encoding are properly encoded', function (): void {
$options = createOptions();
// Test watermark URL
$watermarkUrl = 'https://example.com/watermark.png';
$options->setWatermarkUrl($watermarkUrl);
$encodedUrl = base64_encode($watermarkUrl);
expect($options->toString())->toContain("watermark_url:{$encodedUrl}");
expect($options->getWatermarkUrl())->toBe($watermarkUrl);
// Test watermark text
$text = 'Sample watermark text';
$options->setWatermarkText($text);
$encodedText = base64_encode($text);
expect($options->toString())->toContain("watermark_text:{$encodedText}");
expect($options->getWatermarkText()[0])->toBe($text);
// Test style
$style = 'filter:blur(10px)';
$options->setStyle($style);
$encodedStyle = base64_encode($style);
expect($options->toString())->toContain("style:{$encodedStyle}");
expect($options->getStyle())->toBe($style);
// Test fallback image URL
$fallbackUrl = 'https://example.com/fallback.png';
$options->setFallbackImageUrl($fallbackUrl);
$encodedFallbackUrl = base64_encode($fallbackUrl);
expect($options->toString())->toContain("fallback_image_url:{$encodedFallbackUrl}");
expect($options->getFallbackImageUrl())->toBe($fallbackUrl);
// Test filename with encoded flag
$filename = 'image.png';
$options->setFilename($filename);
$encodedFilename = base64_encode($filename);
expect($options->toString())->toContain("filename:{$encodedFilename}:1");
expect($options->getFilename())->toBe($filename);
});