|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace MaxBeckers\AmazonAlexa\Test\Request; |
|
6
|
|
|
|
|
7
|
|
|
use MaxBeckers\AmazonAlexa\Request\AudioTrack; |
|
8
|
|
|
use MaxBeckers\AmazonAlexa\Request\MediaState; |
|
9
|
|
|
use MaxBeckers\AmazonAlexa\Request\MediaTag; |
|
10
|
|
|
use PHPUnit\Framework\TestCase; |
|
11
|
|
|
|
|
12
|
|
|
class MediaTagTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
public function testFullMapping(): void |
|
15
|
|
|
{ |
|
16
|
|
|
$request = [ |
|
17
|
|
|
'allowAdjustSeekPositionForward' => true, |
|
18
|
|
|
'allowAdjustSeekPositionBackwards' => false, |
|
19
|
|
|
'allowNext' => true, |
|
20
|
|
|
'allowPrevious' => false, |
|
21
|
|
|
'audioTrack' => AudioTrack::BACKGROUND->value, |
|
22
|
|
|
'entities' => [ |
|
23
|
|
|
['name' => 'entity1'], |
|
24
|
|
|
['name' => 'entity2'], |
|
25
|
|
|
], |
|
26
|
|
|
'muted' => true, |
|
27
|
|
|
'positionInMilliseconds' => 12345, |
|
28
|
|
|
'state' => MediaState::PAUSED->value, |
|
29
|
|
|
'url' => 'https://example.com/audio.mp3', |
|
30
|
|
|
]; |
|
31
|
|
|
|
|
32
|
|
|
$tag = MediaTag::fromAmazonRequest($request); |
|
33
|
|
|
|
|
34
|
|
|
$this->assertTrue($tag->allowAdjustSeekPositionForward); |
|
35
|
|
|
$this->assertFalse($tag->allowAdjustSeekPositionBackwards); |
|
36
|
|
|
$this->assertTrue($tag->allowNext); |
|
37
|
|
|
$this->assertFalse($tag->allowPrevious); |
|
38
|
|
|
$this->assertSame(AudioTrack::BACKGROUND, $tag->audioTrack); |
|
39
|
|
|
$this->assertCount(2, $tag->entities); |
|
40
|
|
|
$this->assertTrue($tag->muted); |
|
41
|
|
|
$this->assertSame(12345, $tag->positionInMilliseconds); |
|
42
|
|
|
$this->assertSame(MediaState::PAUSED, $tag->state); |
|
43
|
|
|
$this->assertSame('https://example.com/audio.mp3', $tag->url); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function testMissingFieldsDefaults(): void |
|
47
|
|
|
{ |
|
48
|
|
|
$tag = MediaTag::fromAmazonRequest([]); |
|
49
|
|
|
|
|
50
|
|
|
$this->assertNull($tag->audioTrack); |
|
51
|
|
|
$this->assertSame([], $tag->entities); |
|
52
|
|
|
$this->assertNull($tag->state); |
|
53
|
|
|
$this->assertNull($tag->allowNext); |
|
54
|
|
|
$this->assertNull($tag->url); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function testInvalidEnumValuesBecomeNull(): void |
|
58
|
|
|
{ |
|
59
|
|
|
$tag = MediaTag::fromAmazonRequest([ |
|
60
|
|
|
'audioTrack' => 'INVALID_TRACK', |
|
61
|
|
|
'state' => 'INVALID_STATE', |
|
62
|
|
|
]); |
|
63
|
|
|
|
|
64
|
|
|
$this->assertNull($tag->audioTrack); |
|
65
|
|
|
$this->assertNull($tag->state); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function testEntitiesParsedEvenIfEmptyArray(): void |
|
69
|
|
|
{ |
|
70
|
|
|
$tag = MediaTag::fromAmazonRequest(['entities' => []]); |
|
71
|
|
|
|
|
72
|
|
|
$this->assertIsArray($tag->entities); |
|
73
|
|
|
$this->assertCount(0, $tag->entities); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|