|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace MaxBeckers\AmazonAlexa\Test\Response\Directives; |
|
6
|
|
|
|
|
7
|
|
|
use ArrayObject; |
|
8
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\Display\HintDirective; |
|
9
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\Display\Image; |
|
10
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\Display\ImageSource; |
|
11
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\Display\ListItem; |
|
12
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\Display\RenderTemplateDirective; |
|
13
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\Display\Template; |
|
14
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\Display\Text; |
|
15
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\Display\TextContent; |
|
16
|
|
|
use PHPUnit\Framework\TestCase; |
|
17
|
|
|
|
|
18
|
|
|
class DisplayTest extends TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
public function testText(): void |
|
21
|
|
|
{ |
|
22
|
|
|
$text = Text::create('Test'); |
|
23
|
|
|
$this->assertInstanceOf(Text::class, $text); |
|
24
|
|
|
$this->assertSame('Test', $text->text); |
|
25
|
|
|
$this->assertSame(Text::TYPE_PLAIN_TEXT, $text->type); |
|
26
|
|
|
|
|
27
|
|
|
$text = Text::create('Test2', Text::TYPE_RICH_TEXT); |
|
28
|
|
|
$this->assertSame('Test2', $text->text); |
|
29
|
|
|
$this->assertSame(Text::TYPE_RICH_TEXT, $text->type); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testTextContent(): void |
|
33
|
|
|
{ |
|
34
|
|
|
$textContent = TextContent::create(Text::create('Text1')); |
|
35
|
|
|
$this->assertInstanceOf(TextContent::class, $textContent); |
|
36
|
|
|
$this->assertInstanceOf(Text::class, $textContent->primaryText); |
|
37
|
|
|
$this->assertSame('Text1', $textContent->primaryText->text); |
|
38
|
|
|
$this->assertNull($textContent->secondaryText); |
|
39
|
|
|
$this->assertNull($textContent->tertiaryText); |
|
40
|
|
|
|
|
41
|
|
|
$textContent = TextContent::create( |
|
42
|
|
|
Text::create('Text1'), |
|
43
|
|
|
Text::create('Text2'), |
|
44
|
|
|
Text::create('Text3') |
|
45
|
|
|
); |
|
46
|
|
|
$this->assertSame('Text1', $textContent->primaryText->text); |
|
47
|
|
|
$this->assertSame('Text2', $textContent->secondaryText->text); |
|
48
|
|
|
$this->assertSame('Text3', $textContent->tertiaryText->text); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testImageSource(): void |
|
52
|
|
|
{ |
|
53
|
|
|
$imgUrl = 'http://example.com/some/image.jpg'; |
|
54
|
|
|
$imageSource = ImageSource::create($imgUrl); |
|
55
|
|
|
$this->assertInstanceOf(ImageSource::class, $imageSource); |
|
56
|
|
|
$this->assertSame($imgUrl, $imageSource->url); |
|
57
|
|
|
$this->assertNull($imageSource->size); |
|
58
|
|
|
$this->assertNull($imageSource->widthPixels); |
|
59
|
|
|
$this->assertNull($imageSource->heightPixels); |
|
60
|
|
|
$this->assertEquals(new ArrayObject(['url' => $imgUrl]), $imageSource->jsonSerialize()); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function testImage(): void |
|
64
|
|
|
{ |
|
65
|
|
|
$img = Image::create(); |
|
66
|
|
|
$this->assertInstanceOf(Image::class, $img); |
|
67
|
|
|
$this->assertNull($img->contentDescription); |
|
68
|
|
|
$this->assertSame([], $img->sources); |
|
69
|
|
|
|
|
70
|
|
|
$img = Image::create('Test'); |
|
71
|
|
|
$this->assertSame('Test', $img->contentDescription); |
|
72
|
|
|
$this->assertSame([], $img->sources); |
|
73
|
|
|
|
|
74
|
|
|
$imgUrl = 'http://example.com/some/image.jpg'; |
|
75
|
|
|
$imgSource = ImageSource::create($imgUrl, '1024', 100, 200); |
|
76
|
|
|
|
|
77
|
|
|
$img = Image::create('Test', [$imgSource]); |
|
78
|
|
|
$this->assertSame([$imgSource], $img->sources); |
|
79
|
|
|
|
|
80
|
|
|
$imgUrl2 = 'http://example.com/some/image2.jpg'; |
|
81
|
|
|
$imgSource2 = ImageSource::create($imgUrl2); |
|
82
|
|
|
|
|
83
|
|
|
$img->addImageSource($imgSource2); |
|
84
|
|
|
$this->assertSame([$imgSource, $imgSource2], $img->sources); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function testTemplate(): void |
|
88
|
|
|
{ |
|
89
|
|
|
$tmp = Template::create('BodyTemplate1', 'BODY'); |
|
90
|
|
|
$this->assertInstanceOf(Template::class, $tmp); |
|
91
|
|
|
$this->assertSame($tmp->token, 'BODY'); |
|
92
|
|
|
$this->assertSame($tmp->type, 'BodyTemplate1'); |
|
93
|
|
|
$this->assertSame(Template::BACK_BUTTON_MODE_VISIBLE, $tmp->backButton); |
|
94
|
|
|
$this->assertNull($tmp->backgroundImage); |
|
95
|
|
|
$this->assertNull($tmp->title); |
|
96
|
|
|
$this->assertNull($tmp->textContent); |
|
97
|
|
|
$this->assertNull($tmp->image); |
|
98
|
|
|
$this->assertSame([], $tmp->listItems); |
|
99
|
|
|
|
|
100
|
|
|
$img1 = Image::create('IMG1'); |
|
101
|
|
|
$img2 = Image::create('IMG2'); |
|
102
|
|
|
$li = ListItem::create('T1'); |
|
103
|
|
|
$tc = TextContent::create(); |
|
104
|
|
|
$tmp = Template::create('BodyTemplate2', 'BODY2', Template::BACK_BUTTON_MODE_HIDDEN, $img2, 'TITLE', $tc, $img1, [$li]); |
|
105
|
|
|
$this->assertSame($tmp->token, 'BODY2'); |
|
106
|
|
|
$this->assertSame($tmp->type, 'BodyTemplate2'); |
|
107
|
|
|
$this->assertSame(Template::BACK_BUTTON_MODE_HIDDEN, $tmp->backButton); |
|
108
|
|
|
$this->assertSame($img2, $tmp->backgroundImage); |
|
109
|
|
|
$this->assertSame('TITLE', $tmp->title); |
|
110
|
|
|
$this->assertSame($tc, $tmp->textContent); |
|
111
|
|
|
$this->assertSame($img1, $tmp->image); |
|
112
|
|
|
$this->assertSame([$li], $tmp->listItems); |
|
113
|
|
|
|
|
114
|
|
|
$li2 = ListItem::create('T2'); |
|
115
|
|
|
$tmp->addListItem($li2); |
|
116
|
|
|
$this->assertSame([$li, $li2], $tmp->listItems); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function testRenderTemplate(): void |
|
120
|
|
|
{ |
|
121
|
|
|
$tmp = Template::create('BodyTemplate1', 'BODY'); |
|
122
|
|
|
$renderTemplateDirective = RenderTemplateDirective::create($tmp); |
|
123
|
|
|
$this->assertInstanceOf(RenderTemplateDirective::class, $renderTemplateDirective); |
|
124
|
|
|
$this->assertSame($renderTemplateDirective->template->token, 'BODY'); |
|
125
|
|
|
$this->assertSame($renderTemplateDirective->template->type, 'BodyTemplate1'); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
public function testListItem(): void |
|
129
|
|
|
{ |
|
130
|
|
|
$listItem = ListItem::create(); |
|
131
|
|
|
$this->assertInstanceOf(ListItem::class, $listItem); |
|
132
|
|
|
$this->assertNull($listItem->textContent); |
|
133
|
|
|
$this->assertNull($listItem->image); |
|
134
|
|
|
$this->assertNull($listItem->token); |
|
135
|
|
|
|
|
136
|
|
|
$img = Image::create(); |
|
137
|
|
|
$tc = TextContent::create(); |
|
138
|
|
|
$listItem = ListItem::create('TOKEN', $img, $tc); |
|
139
|
|
|
$this->assertSame($img, $listItem->image); |
|
140
|
|
|
$this->assertSame('TOKEN', $listItem->token); |
|
141
|
|
|
$this->assertSame($tc, $listItem->textContent); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
public function testHint(): void |
|
145
|
|
|
{ |
|
146
|
|
|
$txt = Text::create('Test'); |
|
147
|
|
|
$hint = HintDirective::create($txt); |
|
148
|
|
|
$this->assertInstanceOf(HintDirective::class, $hint); |
|
149
|
|
|
$this->assertSame('Hint', $hint->type); |
|
150
|
|
|
$this->assertSame($txt, $hint->hint); |
|
151
|
|
|
} |
|
152
|
|
|
} |
|
153
|
|
|
|