1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace MaxBeckers\AmazonAlexa\Test\Response\Directives\APL\Component; |
6
|
|
|
|
7
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Component\VectorGraphicComponent; |
8
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\APLComponentType; |
9
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\ImageAlign; |
10
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\Scale; |
11
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand\AbstractStandardCommand; |
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
|
14
|
|
|
class VectorGraphicComponentTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
public function testConstructorWithAllParameters(): void |
17
|
|
|
{ |
18
|
|
|
$align = ImageAlign::CENTER; |
19
|
|
|
$onFail = [$this->createMock(AbstractStandardCommand::class)]; |
20
|
|
|
$onLoad = [$this->createMock(AbstractStandardCommand::class)]; |
21
|
|
|
$parameters = ['param1' => 'value1', 'param2' => 'value2']; |
22
|
|
|
$scale = Scale::FILL; |
23
|
|
|
$source = 'https://example.com/vector.svg'; |
24
|
|
|
|
25
|
|
|
$component = new VectorGraphicComponent($align, $onFail, $onLoad, $parameters, $scale, $source); |
26
|
|
|
|
27
|
|
|
$this->assertSame($align, $component->align); |
28
|
|
|
$this->assertSame($onFail, $component->onFail); |
29
|
|
|
$this->assertSame($onLoad, $component->onLoad); |
30
|
|
|
$this->assertSame($parameters, $component->parameters); |
31
|
|
|
$this->assertSame($scale, $component->scale); |
32
|
|
|
$this->assertSame($source, $component->source); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testConstructorWithDefaultParameters(): void |
36
|
|
|
{ |
37
|
|
|
$component = new VectorGraphicComponent(); |
38
|
|
|
|
39
|
|
|
$this->assertNull($component->align); |
40
|
|
|
$this->assertNull($component->onFail); |
41
|
|
|
$this->assertNull($component->onLoad); |
42
|
|
|
$this->assertNull($component->parameters); |
43
|
|
|
$this->assertNull($component->scale); |
44
|
|
|
$this->assertNull($component->source); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testJsonSerializeWithAllProperties(): void |
48
|
|
|
{ |
49
|
|
|
$align = ImageAlign::TOP_LEFT; |
50
|
|
|
$onFail = [ |
51
|
|
|
$this->createMock(AbstractStandardCommand::class), |
52
|
|
|
$this->createMock(AbstractStandardCommand::class), |
53
|
|
|
]; |
54
|
|
|
$onLoad = [$this->createMock(AbstractStandardCommand::class)]; |
55
|
|
|
$parameters = ['width' => 100, 'height' => 200, 'color' => 'red']; |
56
|
|
|
$scale = Scale::BEST_FIT; |
57
|
|
|
$source = 'https://test.com/graphic.svg'; |
58
|
|
|
|
59
|
|
|
$component = new VectorGraphicComponent($align, $onFail, $onLoad, $parameters, $scale, $source); |
60
|
|
|
$result = $component->jsonSerialize(); |
61
|
|
|
|
62
|
|
|
$this->assertSame(APLComponentType::VECTOR_GRAPHIC->value, $result['type']); |
63
|
|
|
$this->assertSame($align->value, $result['align']); |
64
|
|
|
$this->assertSame($onFail, $result['onFail']); |
65
|
|
|
$this->assertSame($onLoad, $result['onLoad']); |
66
|
|
|
$this->assertSame($parameters, $result['parameters']); |
67
|
|
|
$this->assertSame($scale->value, $result['scale']); |
68
|
|
|
$this->assertSame($source, $result['source']); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testJsonSerializeWithNullValues(): void |
72
|
|
|
{ |
73
|
|
|
$component = new VectorGraphicComponent(); |
74
|
|
|
$result = $component->jsonSerialize(); |
75
|
|
|
|
76
|
|
|
$this->assertSame(APLComponentType::VECTOR_GRAPHIC->value, $result['type']); |
77
|
|
|
$this->assertArrayNotHasKey('align', $result); |
78
|
|
|
$this->assertArrayNotHasKey('onFail', $result); |
79
|
|
|
$this->assertArrayNotHasKey('onLoad', $result); |
80
|
|
|
$this->assertArrayNotHasKey('parameters', $result); |
81
|
|
|
$this->assertArrayNotHasKey('scale', $result); |
82
|
|
|
$this->assertArrayNotHasKey('source', $result); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testJsonSerializeWithEmptyArrays(): void |
86
|
|
|
{ |
87
|
|
|
$component = new VectorGraphicComponent( |
88
|
|
|
onFail: [], |
89
|
|
|
onLoad: [], |
90
|
|
|
parameters: [] |
91
|
|
|
); |
92
|
|
|
$result = $component->jsonSerialize(); |
93
|
|
|
|
94
|
|
|
$this->assertArrayNotHasKey('onFail', $result); |
95
|
|
|
$this->assertArrayNotHasKey('onLoad', $result); |
96
|
|
|
$this->assertArrayNotHasKey('parameters', $result); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function testJsonSerializeWithPartialProperties(): void |
100
|
|
|
{ |
101
|
|
|
$component = new VectorGraphicComponent( |
102
|
|
|
align: ImageAlign::BOTTOM_RIGHT, |
103
|
|
|
source: 'vector.svg' |
104
|
|
|
); |
105
|
|
|
$result = $component->jsonSerialize(); |
106
|
|
|
|
107
|
|
|
$this->assertSame(APLComponentType::VECTOR_GRAPHIC->value, $result['type']); |
108
|
|
|
$this->assertSame(ImageAlign::BOTTOM_RIGHT->value, $result['align']); |
109
|
|
|
$this->assertSame('vector.svg', $result['source']); |
110
|
|
|
$this->assertArrayNotHasKey('onFail', $result); |
111
|
|
|
$this->assertArrayNotHasKey('onLoad', $result); |
112
|
|
|
$this->assertArrayNotHasKey('parameters', $result); |
113
|
|
|
$this->assertArrayNotHasKey('scale', $result); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function testJsonSerializeWithDifferentAlignValues(): void |
117
|
|
|
{ |
118
|
|
|
$alignValues = [ |
119
|
|
|
ImageAlign::CENTER, |
120
|
|
|
ImageAlign::TOP_LEFT, |
121
|
|
|
ImageAlign::BOTTOM_RIGHT, |
122
|
|
|
]; |
123
|
|
|
|
124
|
|
|
foreach ($alignValues as $align) { |
125
|
|
|
$component = new VectorGraphicComponent(align: $align); |
126
|
|
|
$result = $component->jsonSerialize(); |
127
|
|
|
|
128
|
|
|
$this->assertSame($align->value, $result['align']); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function testJsonSerializeWithDifferentScaleValues(): void |
133
|
|
|
{ |
134
|
|
|
$scaleValues = [Scale::FILL, Scale::BEST_FIT, Scale::NONE]; |
135
|
|
|
|
136
|
|
|
foreach ($scaleValues as $scale) { |
137
|
|
|
$component = new VectorGraphicComponent(scale: $scale); |
138
|
|
|
$result = $component->jsonSerialize(); |
139
|
|
|
|
140
|
|
|
$this->assertSame($scale->value, $result['scale']); |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function testTypeConstant(): void |
145
|
|
|
{ |
146
|
|
|
$this->assertSame(APLComponentType::VECTOR_GRAPHIC, VectorGraphicComponent::TYPE); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function testExtendsTouchableComponent(): void |
150
|
|
|
{ |
151
|
|
|
$component = new VectorGraphicComponent(); |
152
|
|
|
|
153
|
|
|
$this->assertInstanceOf(\MaxBeckers\AmazonAlexa\Response\Directives\APL\Component\TouchableComponent::class, $component); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
public function testImplementsJsonSerializable(): void |
157
|
|
|
{ |
158
|
|
|
$component = new VectorGraphicComponent(); |
159
|
|
|
|
160
|
|
|
$this->assertInstanceOf(\JsonSerializable::class, $component); |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|