|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace MaxBeckers\AmazonAlexa\Test\Request; |
|
6
|
|
|
|
|
7
|
|
|
use MaxBeckers\AmazonAlexa\Request\Request; |
|
8
|
|
|
use MaxBeckers\AmazonAlexa\Request\Request\Standard\IntentRequest; |
|
9
|
|
|
use MaxBeckers\AmazonAlexa\Response\Card; |
|
10
|
|
|
use PHPUnit\Framework\TestCase; |
|
11
|
|
|
|
|
12
|
|
|
class GeolocationRequestTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
public function testGeolocationNeedsPermission(): void |
|
15
|
|
|
{ |
|
16
|
|
|
$requestBody = file_get_contents(__DIR__ . '/RequestData/geolocationPermission.json'); |
|
17
|
|
|
$request = Request::fromAmazonRequest($requestBody, 'https://s3.amazonaws.com/echo.api/echo-api-cert.pem', 'signature'); |
|
18
|
|
|
$this->assertInstanceOf(IntentRequest::class, $request->request); |
|
19
|
|
|
$this->assertArrayHasKey('Geolocation', $request->context->system->device->supportedInterfaces); |
|
20
|
|
|
$this->assertNull($request->context->geolocation); |
|
21
|
|
|
|
|
22
|
|
|
// Create permissions card. |
|
23
|
|
|
$card = Card::createAskForPermissionsConsent([Card::PERMISSION_GEOLOCATION]); |
|
24
|
|
|
$this->assertInstanceOf(Card::class, $card); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testGetGeolocationData(): void |
|
28
|
|
|
{ |
|
29
|
|
|
$requestBody = file_get_contents(__DIR__ . '/RequestData/geolocation.json'); |
|
30
|
|
|
$request = Request::fromAmazonRequest($requestBody, 'https://s3.amazonaws.com/echo.api/echo-api-cert.pem', 'signature'); |
|
31
|
|
|
$this->assertInstanceOf(IntentRequest::class, $request->request); |
|
32
|
|
|
$this->assertArrayHasKey('Geolocation', $request->context->system->device->supportedInterfaces); |
|
33
|
|
|
|
|
34
|
|
|
$geolocation = $request->context->geolocation; |
|
35
|
|
|
$this->assertNotNull($geolocation); |
|
36
|
|
|
|
|
37
|
|
|
$this->assertNotNull($geolocation->locationServices); |
|
38
|
|
|
$this->assertEquals('ENABLED', $geolocation->locationServices->access); |
|
39
|
|
|
$this->assertEquals('RUNNING', $geolocation->locationServices->status); |
|
40
|
|
|
$this->assertEquals(new \DateTime('2019-06-12T19:13:01+00:00'), $geolocation->timestamp); |
|
41
|
|
|
$this->assertNotNull($geolocation->coordinate); |
|
42
|
|
|
$this->assertEquals(40.3, $geolocation->coordinate->latitudeInDegrees); |
|
43
|
|
|
$this->assertEquals(-78.9, $geolocation->coordinate->longitudeInDegrees); |
|
44
|
|
|
$this->assertEquals(100, $geolocation->coordinate->accuracyInMeters); |
|
45
|
|
|
$this->assertNotNull($geolocation->altitude); |
|
46
|
|
|
$this->assertEquals(600, $geolocation->altitude->altitudeInMeters); |
|
47
|
|
|
$this->assertEquals(100, $geolocation->altitude->accuracyInMeters); |
|
48
|
|
|
$this->assertNotNull($geolocation->heading); |
|
49
|
|
|
$this->assertEquals(48.12, $geolocation->heading->directionInDegrees); |
|
50
|
|
|
$this->assertEquals(5, $geolocation->heading->accuracyInDegrees); |
|
51
|
|
|
$this->assertNotNull($geolocation->speed); |
|
52
|
|
|
$this->assertEquals(1, $geolocation->speed->speedInMetersPerSecond); |
|
53
|
|
|
$this->assertEquals(1.0, $geolocation->speed->accuracyInMetersPerSecond); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|