1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace MaxBeckers\AmazonAlexa\Test\Response\Directives\APL\Gesture; |
6
|
|
|
|
7
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Component\APLBaseComponent; |
8
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\GestureType; |
9
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\SwipeAction; |
10
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\SwipeDirection; |
11
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Gesture\SwipeAway; |
12
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand\AbstractStandardCommand; |
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
|
15
|
|
|
class SwipeAwayTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
public function testConstructorWithAllParameters(): void |
18
|
|
|
{ |
19
|
|
|
$direction = SwipeDirection::LEFT; |
20
|
|
|
$action = SwipeAction::COVER; |
21
|
|
|
$item = $this->createMock(APLBaseComponent::class); |
22
|
|
|
$items = [$this->createMock(APLBaseComponent::class)]; |
23
|
|
|
$onSwipeMove = [$this->createMock(AbstractStandardCommand::class)]; |
24
|
|
|
$onSwipeDone = [$this->createMock(AbstractStandardCommand::class)]; |
25
|
|
|
$onCancel = [$this->createMock(AbstractStandardCommand::class)]; |
26
|
|
|
$when = true; |
27
|
|
|
|
28
|
|
|
$gesture = new SwipeAway($direction, $action, $item, $items, $onSwipeMove, $onSwipeDone, $onCancel, $when); |
29
|
|
|
|
30
|
|
|
$this->assertSame($direction, $gesture->direction); |
31
|
|
|
$this->assertSame($action, $gesture->action); |
32
|
|
|
$this->assertSame($item, $gesture->item); |
33
|
|
|
$this->assertSame($items, $gesture->items); |
34
|
|
|
$this->assertSame($onSwipeMove, $gesture->onSwipeMove); |
35
|
|
|
$this->assertSame($onSwipeDone, $gesture->onSwipeDone); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testConstructorWithDefaultParameters(): void |
39
|
|
|
{ |
40
|
|
|
$gesture = new SwipeAway(); |
41
|
|
|
|
42
|
|
|
$this->assertNull($gesture->direction); |
43
|
|
|
$this->assertNull($gesture->action); |
44
|
|
|
$this->assertNull($gesture->item); |
45
|
|
|
$this->assertNull($gesture->items); |
46
|
|
|
$this->assertNull($gesture->onSwipeMove); |
47
|
|
|
$this->assertNull($gesture->onSwipeDone); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testJsonSerializeWithAllProperties(): void |
51
|
|
|
{ |
52
|
|
|
$direction = SwipeDirection::RIGHT; |
53
|
|
|
$action = SwipeAction::REVEAL; |
54
|
|
|
$item = $this->createMock(APLBaseComponent::class); |
55
|
|
|
$items = [$this->createMock(APLBaseComponent::class)]; |
56
|
|
|
$onSwipeMove = [$this->createMock(AbstractStandardCommand::class)]; |
57
|
|
|
$onSwipeDone = [$this->createMock(AbstractStandardCommand::class)]; |
58
|
|
|
|
59
|
|
|
$gesture = new SwipeAway($direction, $action, $item, $items, $onSwipeMove, $onSwipeDone); |
60
|
|
|
$result = $gesture->jsonSerialize(); |
61
|
|
|
|
62
|
|
|
$this->assertSame(GestureType::SWIPE_AWAY->value, $result['type']); |
63
|
|
|
$this->assertSame($direction->value, $result['direction']); |
64
|
|
|
$this->assertSame($action->value, $result['action']); |
65
|
|
|
$this->assertSame($item, $result['item']); |
66
|
|
|
$this->assertSame($items, $result['items']); |
67
|
|
|
$this->assertSame($onSwipeMove, $result['onSwipeMove']); |
68
|
|
|
$this->assertSame($onSwipeDone, $result['onSwipeDone']); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testJsonSerializeWithEmptyArrays(): void |
72
|
|
|
{ |
73
|
|
|
$gesture = new SwipeAway(null, null, null, [], [], []); |
74
|
|
|
$result = $gesture->jsonSerialize(); |
75
|
|
|
|
76
|
|
|
$this->assertArrayNotHasKey('items', $result); |
77
|
|
|
$this->assertArrayNotHasKey('onSwipeMove', $result); |
78
|
|
|
$this->assertArrayNotHasKey('onSwipeDone', $result); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function testJsonSerializeWithNullValues(): void |
82
|
|
|
{ |
83
|
|
|
$gesture = new SwipeAway(); |
84
|
|
|
$result = $gesture->jsonSerialize(); |
85
|
|
|
|
86
|
|
|
$this->assertSame(GestureType::SWIPE_AWAY->value, $result['type']); |
87
|
|
|
$this->assertArrayNotHasKey('direction', $result); |
88
|
|
|
$this->assertArrayNotHasKey('action', $result); |
89
|
|
|
$this->assertArrayNotHasKey('item', $result); |
90
|
|
|
$this->assertArrayNotHasKey('items', $result); |
91
|
|
|
$this->assertArrayNotHasKey('onSwipeMove', $result); |
92
|
|
|
$this->assertArrayNotHasKey('onSwipeDone', $result); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|