|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace MaxBeckers\AmazonAlexa\Test\Response\Directives\APL\StandardCommand; |
|
6
|
|
|
|
|
7
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\SetPagePosition; |
|
8
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand\SetPageCommand; |
|
9
|
|
|
use PHPUnit\Framework\TestCase; |
|
10
|
|
|
|
|
11
|
|
|
class SetPageCommandTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
public function testConstructorWithAllParameters(): void |
|
14
|
|
|
{ |
|
15
|
|
|
$componentId = 'myPager'; |
|
16
|
|
|
$position = SetPagePosition::RELATIVE; |
|
17
|
|
|
$transitionDuration = 500; |
|
18
|
|
|
$value = 2; |
|
19
|
|
|
|
|
20
|
|
|
$command = new SetPageCommand($componentId, $position, $transitionDuration, $value); |
|
21
|
|
|
|
|
22
|
|
|
$this->assertSame($componentId, $command->componentId); |
|
23
|
|
|
$this->assertSame($position, $command->position); |
|
24
|
|
|
$this->assertSame($transitionDuration, $command->transitionDuration); |
|
25
|
|
|
$this->assertSame($value, $command->value); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function testConstructorWithDefaultParameters(): void |
|
29
|
|
|
{ |
|
30
|
|
|
$command = new SetPageCommand(); |
|
31
|
|
|
|
|
32
|
|
|
$this->assertNull($command->componentId); |
|
33
|
|
|
$this->assertSame(SetPagePosition::ABSOLUTE, $command->position); |
|
34
|
|
|
$this->assertNull($command->transitionDuration); |
|
35
|
|
|
$this->assertNull($command->value); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testJsonSerializeWithAllProperties(): void |
|
39
|
|
|
{ |
|
40
|
|
|
$componentId = 'testPager'; |
|
41
|
|
|
$position = SetPagePosition::RELATIVE; |
|
42
|
|
|
$transitionDuration = 300; |
|
43
|
|
|
$value = 1; |
|
44
|
|
|
|
|
45
|
|
|
$command = new SetPageCommand($componentId, $position, $transitionDuration, $value); |
|
46
|
|
|
$result = $command->jsonSerialize(); |
|
47
|
|
|
|
|
48
|
|
|
$this->assertSame(SetPageCommand::TYPE, $result['type']); |
|
49
|
|
|
$this->assertSame($componentId, $result['componentId']); |
|
50
|
|
|
$this->assertSame($position->value, $result['position']); |
|
51
|
|
|
$this->assertSame($transitionDuration, $result['transitionDuration']); |
|
52
|
|
|
$this->assertSame($value, $result['value']); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testJsonSerializeWithDefaultPosition(): void |
|
56
|
|
|
{ |
|
57
|
|
|
$command = new SetPageCommand('pager1'); |
|
58
|
|
|
$result = $command->jsonSerialize(); |
|
59
|
|
|
|
|
60
|
|
|
$this->assertSame(SetPageCommand::TYPE, $result['type']); |
|
61
|
|
|
$this->assertSame('pager1', $result['componentId']); |
|
62
|
|
|
$this->assertSame(SetPagePosition::ABSOLUTE->value, $result['position']); |
|
63
|
|
|
$this->assertArrayNotHasKey('transitionDuration', $result); |
|
64
|
|
|
$this->assertArrayNotHasKey('value', $result); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function testJsonSerializeWithNullValues(): void |
|
68
|
|
|
{ |
|
69
|
|
|
$command = new SetPageCommand(); |
|
70
|
|
|
$result = $command->jsonSerialize(); |
|
71
|
|
|
|
|
72
|
|
|
$this->assertSame(SetPageCommand::TYPE, $result['type']); |
|
73
|
|
|
$this->assertArrayNotHasKey('componentId', $result); |
|
74
|
|
|
$this->assertSame(SetPagePosition::ABSOLUTE->value, $result['position']); |
|
75
|
|
|
$this->assertArrayNotHasKey('transitionDuration', $result); |
|
76
|
|
|
$this->assertArrayNotHasKey('value', $result); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function testJsonSerializeWithZeroValues(): void |
|
80
|
|
|
{ |
|
81
|
|
|
$command = new SetPageCommand('pager', SetPagePosition::RELATIVE, 0, 0); |
|
82
|
|
|
$result = $command->jsonSerialize(); |
|
83
|
|
|
|
|
84
|
|
|
$this->assertSame(SetPageCommand::TYPE, $result['type']); |
|
85
|
|
|
$this->assertSame('pager', $result['componentId']); |
|
86
|
|
|
$this->assertSame(SetPagePosition::RELATIVE->value, $result['position']); |
|
87
|
|
|
$this->assertSame(0, $result['transitionDuration']); |
|
88
|
|
|
$this->assertSame(0, $result['value']); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function testJsonSerializeWithNegativeValue(): void |
|
92
|
|
|
{ |
|
93
|
|
|
$command = new SetPageCommand('pager', SetPagePosition::RELATIVE, 200, -1); |
|
94
|
|
|
$result = $command->jsonSerialize(); |
|
95
|
|
|
|
|
96
|
|
|
$this->assertSame(-1, $result['value']); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function testTypeConstant(): void |
|
100
|
|
|
{ |
|
101
|
|
|
$this->assertSame('SetPage', SetPageCommand::TYPE); |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|