|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace MaxBeckers\AmazonAlexa\Test\Response\Directives\APL\AVGFilter; |
|
6
|
|
|
|
|
7
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\AVGFilter\AVGFilter; |
|
8
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\AVGFilter\DropShadow; |
|
9
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\AVGFilterType; |
|
10
|
|
|
use PHPUnit\Framework\TestCase; |
|
11
|
|
|
|
|
12
|
|
|
class DropShadowTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
public function testConstructorWithAllParameters(): void |
|
15
|
|
|
{ |
|
16
|
|
|
$color = '#ff0000'; |
|
17
|
|
|
$horizontalOffset = 5; |
|
18
|
|
|
$radius = 10; |
|
19
|
|
|
$verticalOffset = 3; |
|
20
|
|
|
|
|
21
|
|
|
$dropShadow = new DropShadow($color, $horizontalOffset, $radius, $verticalOffset); |
|
22
|
|
|
|
|
23
|
|
|
$this->assertSame($color, $dropShadow->color); |
|
24
|
|
|
$this->assertSame($horizontalOffset, $dropShadow->horizontalOffset); |
|
25
|
|
|
$this->assertSame($radius, $dropShadow->radius); |
|
26
|
|
|
$this->assertSame($verticalOffset, $dropShadow->verticalOffset); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function testConstructorWithDefaultParameters(): void |
|
30
|
|
|
{ |
|
31
|
|
|
$dropShadow = new DropShadow(); |
|
32
|
|
|
|
|
33
|
|
|
$this->assertNull($dropShadow->color); |
|
34
|
|
|
$this->assertNull($dropShadow->horizontalOffset); |
|
35
|
|
|
$this->assertNull($dropShadow->radius); |
|
36
|
|
|
$this->assertNull($dropShadow->verticalOffset); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testJsonSerializeWithAllProperties(): void |
|
40
|
|
|
{ |
|
41
|
|
|
$color = '#0000ff'; |
|
42
|
|
|
$horizontalOffset = 8; |
|
43
|
|
|
$radius = 15; |
|
44
|
|
|
$verticalOffset = -2; |
|
45
|
|
|
|
|
46
|
|
|
$dropShadow = new DropShadow($color, $horizontalOffset, $radius, $verticalOffset); |
|
47
|
|
|
$result = $dropShadow->jsonSerialize(); |
|
48
|
|
|
|
|
49
|
|
|
$this->assertSame(AVGFilterType::DROP_SHADOW->value, $result['type']); |
|
50
|
|
|
$this->assertSame($color, $result['color']); |
|
51
|
|
|
$this->assertSame($horizontalOffset, $result['horizontalOffset']); |
|
52
|
|
|
$this->assertSame($radius, $result['radius']); |
|
53
|
|
|
$this->assertSame($verticalOffset, $result['verticalOffset']); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function testJsonSerializeWithNullValues(): void |
|
57
|
|
|
{ |
|
58
|
|
|
$dropShadow = new DropShadow(); |
|
59
|
|
|
$result = $dropShadow->jsonSerialize(); |
|
60
|
|
|
|
|
61
|
|
|
$this->assertSame(AVGFilterType::DROP_SHADOW->value, $result['type']); |
|
62
|
|
|
$this->assertArrayNotHasKey('color', $result); |
|
63
|
|
|
$this->assertArrayNotHasKey('horizontalOffset', $result); |
|
64
|
|
|
$this->assertArrayNotHasKey('radius', $result); |
|
65
|
|
|
$this->assertArrayNotHasKey('verticalOffset', $result); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function testJsonSerializeWithPartialProperties(): void |
|
69
|
|
|
{ |
|
70
|
|
|
$dropShadow = new DropShadow('#green', null, 20, null); |
|
71
|
|
|
$result = $dropShadow->jsonSerialize(); |
|
72
|
|
|
|
|
73
|
|
|
$this->assertSame(AVGFilterType::DROP_SHADOW->value, $result['type']); |
|
74
|
|
|
$this->assertSame('#green', $result['color']); |
|
75
|
|
|
$this->assertSame(20, $result['radius']); |
|
76
|
|
|
$this->assertArrayNotHasKey('horizontalOffset', $result); |
|
77
|
|
|
$this->assertArrayNotHasKey('verticalOffset', $result); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function testJsonSerializeWithZeroValues(): void |
|
81
|
|
|
{ |
|
82
|
|
|
$dropShadow = new DropShadow('#black', 0, 0, 0); |
|
83
|
|
|
$result = $dropShadow->jsonSerialize(); |
|
84
|
|
|
|
|
85
|
|
|
$this->assertSame(AVGFilterType::DROP_SHADOW->value, $result['type']); |
|
86
|
|
|
$this->assertSame('#black', $result['color']); |
|
87
|
|
|
$this->assertSame(0, $result['horizontalOffset']); |
|
88
|
|
|
$this->assertSame(0, $result['radius']); |
|
89
|
|
|
$this->assertSame(0, $result['verticalOffset']); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function testJsonSerializeWithNegativeValues(): void |
|
93
|
|
|
{ |
|
94
|
|
|
$dropShadow = new DropShadow('#gray', -5, -10, -3); |
|
95
|
|
|
$result = $dropShadow->jsonSerialize(); |
|
96
|
|
|
|
|
97
|
|
|
$this->assertSame('#gray', $result['color']); |
|
98
|
|
|
$this->assertSame(-5, $result['horizontalOffset']); |
|
99
|
|
|
$this->assertSame(-10, $result['radius']); |
|
100
|
|
|
$this->assertSame(-3, $result['verticalOffset']); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function testTypeConstant(): void |
|
104
|
|
|
{ |
|
105
|
|
|
$this->assertSame(AVGFilterType::DROP_SHADOW, DropShadow::TYPE); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function testExtendsAVGFilter(): void |
|
109
|
|
|
{ |
|
110
|
|
|
$dropShadow = new DropShadow(); |
|
111
|
|
|
|
|
112
|
|
|
$this->assertInstanceOf(AVGFilter::class, $dropShadow); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
public function testImplementsJsonSerializable(): void |
|
116
|
|
|
{ |
|
117
|
|
|
$dropShadow = new DropShadow(); |
|
118
|
|
|
|
|
119
|
|
|
$this->assertInstanceOf(\JsonSerializable::class, $dropShadow); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
public function testInheritsTypeFromParent(): void |
|
123
|
|
|
{ |
|
124
|
|
|
$dropShadow = new DropShadow(); |
|
125
|
|
|
$result = $dropShadow->jsonSerialize(); |
|
126
|
|
|
|
|
127
|
|
|
// Verify that the type is included from parent class |
|
128
|
|
|
$this->assertArrayHasKey('type', $result); |
|
129
|
|
|
$this->assertSame(AVGFilterType::DROP_SHADOW->value, $result['type']); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
public function testJsonSerializeStructure(): void |
|
133
|
|
|
{ |
|
134
|
|
|
$dropShadow = new DropShadow('#white', 1, 2, 3); |
|
135
|
|
|
$result = $dropShadow->jsonSerialize(); |
|
136
|
|
|
|
|
137
|
|
|
$this->assertIsArray($result); |
|
138
|
|
|
$this->assertArrayHasKey('type', $result); |
|
139
|
|
|
$this->assertArrayHasKey('color', $result); |
|
140
|
|
|
$this->assertArrayHasKey('horizontalOffset', $result); |
|
141
|
|
|
$this->assertArrayHasKey('radius', $result); |
|
142
|
|
|
$this->assertArrayHasKey('verticalOffset', $result); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
public function testColorFormatting(): void |
|
146
|
|
|
{ |
|
147
|
|
|
$testColors = ['#ff0000', 'red', 'rgb(255, 0, 0)', 'rgba(255, 0, 0, 0.5)']; |
|
148
|
|
|
|
|
149
|
|
|
foreach ($testColors as $color) { |
|
150
|
|
|
$dropShadow = new DropShadow($color); |
|
151
|
|
|
$result = $dropShadow->jsonSerialize(); |
|
152
|
|
|
|
|
153
|
|
|
$this->assertSame($color, $result['color']); |
|
154
|
|
|
} |
|
155
|
|
|
} |
|
156
|
|
|
} |
|
157
|
|
|
|