|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace MaxBeckers\AmazonAlexa\Test\Response; |
|
6
|
|
|
|
|
7
|
|
|
use ArrayObject; |
|
8
|
|
|
use MaxBeckers\AmazonAlexa\Exception\InvalidCardPermissionsException; |
|
9
|
|
|
use MaxBeckers\AmazonAlexa\Response\Card; |
|
10
|
|
|
use MaxBeckers\AmazonAlexa\Response\CardImage; |
|
11
|
|
|
use PHPUnit\Framework\TestCase; |
|
12
|
|
|
|
|
13
|
|
|
class CardTest extends TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
public function testSimpleCard(): void |
|
16
|
|
|
{ |
|
17
|
|
|
$title = 'title'; |
|
18
|
|
|
$content = 'content'; |
|
19
|
|
|
|
|
20
|
|
|
$card = Card::createSimple($title, $content); |
|
21
|
|
|
$this->assertEquals(new ArrayObject([ |
|
22
|
|
|
'type' => Card::TYPE_SIMPLE, |
|
23
|
|
|
'title' => $title, |
|
24
|
|
|
'content' => $content, |
|
25
|
|
|
]), $card->jsonSerialize()); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function testStandardCardWithoutImage(): void |
|
29
|
|
|
{ |
|
30
|
|
|
$title = 'title'; |
|
31
|
|
|
$text = 'content'; |
|
32
|
|
|
|
|
33
|
|
|
$card = Card::createStandard($title, $text); |
|
34
|
|
|
$this->assertEquals(new ArrayObject([ |
|
35
|
|
|
'type' => Card::TYPE_STANDARD, |
|
36
|
|
|
'title' => $title, |
|
37
|
|
|
'text' => $text, |
|
38
|
|
|
]), $card->jsonSerialize()); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function testStandardCardWithImage(): void |
|
42
|
|
|
{ |
|
43
|
|
|
$title = 'title'; |
|
44
|
|
|
$text = 'content'; |
|
45
|
|
|
$image = CardImage::fromUrls('https://www.img.test/small.png', 'https://www.img.test/large.png'); |
|
46
|
|
|
|
|
47
|
|
|
$card = Card::createStandard($title, $text, $image); |
|
48
|
|
|
$this->assertEquals(new ArrayObject([ |
|
49
|
|
|
'type' => Card::TYPE_STANDARD, |
|
50
|
|
|
'title' => $title, |
|
51
|
|
|
'text' => $text, |
|
52
|
|
|
'image' => $image, |
|
53
|
|
|
]), $card->jsonSerialize()); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function testLinkAccount(): void |
|
57
|
|
|
{ |
|
58
|
|
|
$card = Card::createLinkAccount(); |
|
59
|
|
|
$this->assertEquals(new ArrayObject([ |
|
60
|
|
|
'type' => Card::TYPE_LINK_ACCOUNT, |
|
61
|
|
|
]), $card->jsonSerialize()); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function testCreateAskForPermissionsConsent(): void |
|
65
|
|
|
{ |
|
66
|
|
|
$card = Card::createAskForPermissionsConsent(Card::PERMISSIONS); |
|
67
|
|
|
$this->assertEquals(new ArrayObject([ |
|
68
|
|
|
'type' => Card::TYPE_ASK_FOR_PERMISSIONS_CONSENT, |
|
69
|
|
|
'permissions' => Card::PERMISSIONS, |
|
70
|
|
|
]), $card->jsonSerialize()); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function testCreateAskForPermissionsConsentFullAddress(): void |
|
74
|
|
|
{ |
|
75
|
|
|
$card = Card::createAskForPermissionsConsent([Card::PERMISSION_FULL_ADDRESS]); |
|
76
|
|
|
$this->assertEquals(new ArrayObject([ |
|
77
|
|
|
'type' => Card::TYPE_ASK_FOR_PERMISSIONS_CONSENT, |
|
78
|
|
|
'permissions' => [Card::PERMISSION_FULL_ADDRESS], |
|
79
|
|
|
]), $card->jsonSerialize()); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function testCreateAskForPermissionsConsentCountryRegionAndPostalCode(): void |
|
83
|
|
|
{ |
|
84
|
|
|
$card = Card::createAskForPermissionsConsent([Card::PERMISSION_COUNTRY_REGION_AND_POSTAL_CODE]); |
|
85
|
|
|
$this->assertEquals(new ArrayObject([ |
|
86
|
|
|
'type' => Card::TYPE_ASK_FOR_PERMISSIONS_CONSENT, |
|
87
|
|
|
'permissions' => [Card::PERMISSION_COUNTRY_REGION_AND_POSTAL_CODE], |
|
88
|
|
|
]), $card->jsonSerialize()); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function testCreateAskForPermissionsConsentEmptyPermissions(): void |
|
92
|
|
|
{ |
|
93
|
|
|
$this->expectException(InvalidCardPermissionsException::class); |
|
94
|
|
|
Card::createAskForPermissionsConsent([]); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function testCreateAskForPermissionsConsentInvalidPermissions(): void |
|
98
|
|
|
{ |
|
99
|
|
|
$this->expectException(InvalidCardPermissionsException::class); |
|
100
|
|
|
Card::createAskForPermissionsConsent(['invalid']); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|