|
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\PagerComponent; |
|
8
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\APLComponentType; |
|
9
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\Navigation; |
|
10
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\PageDirection; |
|
11
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand\AbstractStandardCommand; |
|
12
|
|
|
use PHPUnit\Framework\TestCase; |
|
13
|
|
|
|
|
14
|
|
|
class PagerComponentTest extends TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
public function testConstructorWithAllParameters(): void |
|
17
|
|
|
{ |
|
18
|
|
|
$handlePageMove = ['handler1', 'handler2']; |
|
19
|
|
|
$initialPage = 2; |
|
20
|
|
|
$navigation = Navigation::NORMAL; |
|
21
|
|
|
$onPageChanged = [$this->createMock(AbstractStandardCommand::class)]; |
|
22
|
|
|
$pageDirection = PageDirection::HORIZONTAL; |
|
23
|
|
|
$preserve = ['pageIndex', 'state']; |
|
24
|
|
|
|
|
25
|
|
|
$component = new PagerComponent( |
|
26
|
|
|
$handlePageMove, |
|
27
|
|
|
$initialPage, |
|
28
|
|
|
$navigation, |
|
29
|
|
|
$onPageChanged, |
|
30
|
|
|
$pageDirection, |
|
31
|
|
|
$preserve |
|
32
|
|
|
); |
|
33
|
|
|
|
|
34
|
|
|
$this->assertSame($handlePageMove, $component->handlePageMove); |
|
35
|
|
|
$this->assertSame($initialPage, $component->initialPage); |
|
36
|
|
|
$this->assertSame($navigation, $component->navigation); |
|
37
|
|
|
$this->assertSame($onPageChanged, $component->onPageChanged); |
|
38
|
|
|
$this->assertSame($pageDirection, $component->pageDirection); |
|
39
|
|
|
$this->assertSame($preserve, $component->preserve); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function testConstructorWithDefaultParameters(): void |
|
43
|
|
|
{ |
|
44
|
|
|
$component = new PagerComponent(); |
|
45
|
|
|
|
|
46
|
|
|
$this->assertNull($component->handlePageMove); |
|
47
|
|
|
$this->assertSame(0, $component->initialPage); |
|
48
|
|
|
$this->assertNull($component->navigation); |
|
49
|
|
|
$this->assertNull($component->onPageChanged); |
|
50
|
|
|
$this->assertNull($component->pageDirection); |
|
51
|
|
|
$this->assertNull($component->preserve); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testJsonSerializeWithAllProperties(): void |
|
55
|
|
|
{ |
|
56
|
|
|
$handlePageMove = ['moveHandler1', 'moveHandler2']; |
|
57
|
|
|
$initialPage = 1; |
|
58
|
|
|
$navigation = Navigation::WRAP; |
|
59
|
|
|
$onPageChanged = [ |
|
60
|
|
|
$this->createMock(AbstractStandardCommand::class), |
|
61
|
|
|
$this->createMock(AbstractStandardCommand::class), |
|
62
|
|
|
]; |
|
63
|
|
|
$pageDirection = PageDirection::VERTICAL; |
|
64
|
|
|
$preserve = ['position', 'scroll']; |
|
65
|
|
|
|
|
66
|
|
|
$component = new PagerComponent( |
|
67
|
|
|
$handlePageMove, |
|
68
|
|
|
$initialPage, |
|
69
|
|
|
$navigation, |
|
70
|
|
|
$onPageChanged, |
|
71
|
|
|
$pageDirection, |
|
72
|
|
|
$preserve |
|
73
|
|
|
); |
|
74
|
|
|
|
|
75
|
|
|
$result = $component->jsonSerialize(); |
|
76
|
|
|
|
|
77
|
|
|
$this->assertSame(APLComponentType::PAGER->value, $result['type']); |
|
78
|
|
|
$this->assertSame($handlePageMove, $result['handlePageMove']); |
|
79
|
|
|
$this->assertSame($initialPage, $result['initialPage']); |
|
80
|
|
|
$this->assertSame($navigation->value, $result['navigation']); |
|
81
|
|
|
$this->assertSame($onPageChanged, $result['onPageChanged']); |
|
82
|
|
|
$this->assertSame($pageDirection->value, $result['pageDirection']); |
|
83
|
|
|
$this->assertSame($preserve, $result['preserve']); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function testJsonSerializeWithDefaultInitialPage(): void |
|
87
|
|
|
{ |
|
88
|
|
|
$component = new PagerComponent(); |
|
89
|
|
|
$result = $component->jsonSerialize(); |
|
90
|
|
|
|
|
91
|
|
|
$this->assertArrayNotHasKey('initialPage', $result); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function testJsonSerializeWithNonZeroInitialPage(): void |
|
95
|
|
|
{ |
|
96
|
|
|
$component = new PagerComponent(initialPage: 3); |
|
97
|
|
|
$result = $component->jsonSerialize(); |
|
98
|
|
|
|
|
99
|
|
|
$this->assertSame(3, $result['initialPage']); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function testJsonSerializeWithEmptyArrays(): void |
|
103
|
|
|
{ |
|
104
|
|
|
$component = new PagerComponent( |
|
105
|
|
|
handlePageMove: [], |
|
106
|
|
|
onPageChanged: [], |
|
107
|
|
|
preserve: [] |
|
108
|
|
|
); |
|
109
|
|
|
$result = $component->jsonSerialize(); |
|
110
|
|
|
|
|
111
|
|
|
$this->assertArrayNotHasKey('handlePageMove', $result); |
|
112
|
|
|
$this->assertArrayNotHasKey('onPageChanged', $result); |
|
113
|
|
|
$this->assertArrayNotHasKey('preserve', $result); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function testJsonSerializeWithNullValues(): void |
|
117
|
|
|
{ |
|
118
|
|
|
$component = new PagerComponent(); |
|
119
|
|
|
$result = $component->jsonSerialize(); |
|
120
|
|
|
|
|
121
|
|
|
$this->assertSame(APLComponentType::PAGER->value, $result['type']); |
|
122
|
|
|
$this->assertArrayNotHasKey('handlePageMove', $result); |
|
123
|
|
|
$this->assertArrayNotHasKey('navigation', $result); |
|
124
|
|
|
$this->assertArrayNotHasKey('onPageChanged', $result); |
|
125
|
|
|
$this->assertArrayNotHasKey('pageDirection', $result); |
|
126
|
|
|
$this->assertArrayNotHasKey('preserve', $result); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
public function testJsonSerializeWithDifferentNavigationValues(): void |
|
130
|
|
|
{ |
|
131
|
|
|
$navigationValues = [Navigation::NORMAL, Navigation::NONE, Navigation::WRAP]; |
|
132
|
|
|
|
|
133
|
|
|
foreach ($navigationValues as $navigation) { |
|
134
|
|
|
$component = new PagerComponent(navigation: $navigation); |
|
135
|
|
|
$result = $component->jsonSerialize(); |
|
136
|
|
|
|
|
137
|
|
|
$this->assertSame($navigation->value, $result['navigation']); |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
public function testJsonSerializeWithDifferentPageDirections(): void |
|
142
|
|
|
{ |
|
143
|
|
|
$pageDirections = [PageDirection::HORIZONTAL, PageDirection::VERTICAL]; |
|
144
|
|
|
|
|
145
|
|
|
foreach ($pageDirections as $direction) { |
|
146
|
|
|
$component = new PagerComponent(pageDirection: $direction); |
|
147
|
|
|
$result = $component->jsonSerialize(); |
|
148
|
|
|
|
|
149
|
|
|
$this->assertSame($direction->value, $result['pageDirection']); |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
public function testTypeConstant(): void |
|
154
|
|
|
{ |
|
155
|
|
|
$this->assertSame(APLComponentType::PAGER, PagerComponent::TYPE); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
public function testExtendsAPLBaseComponent(): void |
|
159
|
|
|
{ |
|
160
|
|
|
$component = new PagerComponent(); |
|
161
|
|
|
|
|
162
|
|
|
$this->assertInstanceOf(\MaxBeckers\AmazonAlexa\Response\Directives\APL\Component\APLBaseComponent::class, $component); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
public function testUsesActionableComponentTrait(): void |
|
166
|
|
|
{ |
|
167
|
|
|
$component = new PagerComponent(); |
|
168
|
|
|
|
|
169
|
|
|
$this->assertTrue(in_array( |
|
170
|
|
|
\MaxBeckers\AmazonAlexa\Response\Directives\APL\Component\Traits\ActionableComponentTrait::class, |
|
171
|
|
|
class_uses($component), |
|
172
|
|
|
true |
|
173
|
|
|
)); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
public function testUsesMultiChildComponentTrait(): void |
|
177
|
|
|
{ |
|
178
|
|
|
$component = new PagerComponent(); |
|
179
|
|
|
|
|
180
|
|
|
$this->assertTrue(in_array( |
|
181
|
|
|
\MaxBeckers\AmazonAlexa\Response\Directives\APL\Component\Traits\MultiChildComponentTrait::class, |
|
182
|
|
|
class_uses($component), |
|
183
|
|
|
true |
|
184
|
|
|
)); |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
public function testImplementsJsonSerializable(): void |
|
188
|
|
|
{ |
|
189
|
|
|
$component = new PagerComponent(); |
|
190
|
|
|
|
|
191
|
|
|
$this->assertInstanceOf(\JsonSerializable::class, $component); |
|
192
|
|
|
} |
|
193
|
|
|
} |
|
194
|
|
|
|