1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\Client\JsonApi; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $context; |
15
|
|
|
private $object; |
16
|
|
|
private $view; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
protected function setUp() |
20
|
|
|
{ |
21
|
|
|
$this->context = \TestHelperJapi::getContext(); |
22
|
|
|
$templatePaths = \TestHelperJapi::getTemplatePaths(); |
23
|
|
|
$this->view = $this->context->getView(); |
24
|
|
|
|
25
|
|
|
$this->object = new \Aimeos\Client\JsonApi\Standard( $this->context, $this->view, $templatePaths, '' ); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
public function testGet() |
30
|
|
|
{ |
31
|
|
|
$response = $this->object->get( $this->view->request(), $this->view->response() ); |
32
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
33
|
|
|
|
34
|
|
|
$this->assertEquals( 200, $response->getStatusCode() ); |
35
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Allow' ) ) ); |
36
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
37
|
|
|
|
38
|
|
|
$this->assertArrayHasKey( 'title', $result['errors'] ); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
public function testOptions() |
43
|
|
|
{ |
44
|
|
|
$response = $this->object->options( $this->view->request(), $this->view->response() ); |
45
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
46
|
|
|
|
47
|
|
|
$this->assertEquals( 200, $response->getStatusCode() ); |
48
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Allow' ) ) ); |
49
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
50
|
|
|
|
51
|
|
|
$this->assertEquals( null, $result['meta']['prefix'] ); |
52
|
|
|
$this->assertGreaterThan( 8, count( $result['meta']['resources'] ) ); |
53
|
|
|
$this->assertArrayNotHasKey( 'errors', $result ); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
public function testOptionsException() |
58
|
|
|
{ |
59
|
|
|
$templatePaths = \TestHelperJapi::getTemplatePaths(); |
60
|
|
|
|
61
|
|
|
$object = $this->getMockBuilder( '\Aimeos\Client\JsonApi\Standard' ) |
62
|
|
|
->setConstructorArgs( [$this->context, $this->view, $templatePaths, ''] ) |
63
|
|
|
->setMethods( ['getContext'] ) |
64
|
|
|
->getMock(); |
65
|
|
|
|
66
|
|
|
$object->expects( $this->once() )->method( 'getContext' ) |
67
|
|
|
->will( $this->throwException( new \Exception() ) ); |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
$response = $object->options( $this->view->request(), $this->view->response() ); |
71
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
$this->assertEquals( 500, $response->getStatusCode() ); |
75
|
|
|
$this->assertArrayHasKey( 'errors', $result ); |
76
|
|
|
} |
77
|
|
|
} |