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 BaseTest 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
|
|
|
$this->view = $this->context->getView(); |
23
|
|
|
|
24
|
|
|
$this->object = $this->getMockBuilder( '\Aimeos\Client\JsonApi\Base' ) |
25
|
|
|
->setConstructorArgs( [$this->context, 'test'] ) |
26
|
|
|
->getMockForAbstractClass(); |
27
|
|
|
|
28
|
|
|
$this->object->setView( $this->view ); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
public function testDelete() |
33
|
|
|
{ |
34
|
|
|
$response = $this->object->delete( $this->view->request(), $this->view->response() ); |
35
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
36
|
|
|
|
37
|
|
|
$this->assertEquals( 403, $response->getStatusCode() ); |
38
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
39
|
|
|
$this->assertArrayHasKey( 'errors', $result ); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
public function testGet() |
44
|
|
|
{ |
45
|
|
|
$response = $this->object->get( $this->view->request(), $this->view->response() ); |
46
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
47
|
|
|
|
48
|
|
|
$this->assertEquals( 403, $response->getStatusCode() ); |
49
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
50
|
|
|
$this->assertArrayHasKey( 'errors', $result ); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
public function testPatch() |
55
|
|
|
{ |
56
|
|
|
$response = $this->object->patch( $this->view->request(), $this->view->response() ); |
57
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
58
|
|
|
|
59
|
|
|
$this->assertEquals( 403, $response->getStatusCode() ); |
60
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
61
|
|
|
$this->assertArrayHasKey( 'errors', $result ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
public function testPost() |
66
|
|
|
{ |
67
|
|
|
$response = $this->object->post( $this->view->request(), $this->view->response() ); |
68
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
69
|
|
|
|
70
|
|
|
$this->assertEquals( 403, $response->getStatusCode() ); |
71
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
72
|
|
|
$this->assertArrayHasKey( 'errors', $result ); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
public function testPut() |
77
|
|
|
{ |
78
|
|
|
$response = $this->object->put( $this->view->request(), $this->view->response() ); |
79
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
80
|
|
|
|
81
|
|
|
$this->assertEquals( 403, $response->getStatusCode() ); |
82
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
83
|
|
|
$this->assertArrayHasKey( 'errors', $result ); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
|
87
|
|
|
public function testOptions() |
88
|
|
|
{ |
89
|
|
|
$response = $this->object->options( $this->view->request(), $this->view->response() ); |
90
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
91
|
|
|
|
92
|
|
|
$this->assertEquals( 403, $response->getStatusCode() ); |
93
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
94
|
|
|
$this->assertArrayHasKey( 'errors', $result ); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
|
98
|
|
|
public function testGetContext() |
99
|
|
|
{ |
100
|
|
|
$result = $this->access( 'getContext' )->invokeArgs( $this->object, [] ); |
101
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Context\Item\Iface', $result ); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
|
105
|
|
|
public function testGetPath() |
106
|
|
|
{ |
107
|
|
|
$result = $this->access( 'getPath' )->invokeArgs( $this->object, [] ); |
108
|
|
|
$this->assertEquals( 'test', $result ); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
|
112
|
|
|
protected function access( $name ) |
113
|
|
|
{ |
114
|
|
|
$class = new \ReflectionClass( '\Aimeos\Client\JsonApi\Base' ); |
115
|
|
|
$method = $class->getMethod( $name ); |
116
|
|
|
$method->setAccessible( true ); |
117
|
|
|
|
118
|
|
|
return $method; |
119
|
|
|
} |
120
|
|
|
} |