1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017-2025 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\Client\JsonApi; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class Example extends Base |
13
|
|
|
{ |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
class BaseTest extends \PHPUnit\Framework\TestCase |
18
|
|
|
{ |
19
|
|
|
private $context; |
20
|
|
|
private $object; |
21
|
|
|
private $view; |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
protected function setUp() : void |
25
|
|
|
{ |
26
|
|
|
$this->context = \TestHelper::context(); |
27
|
|
|
$this->view = $this->context->view(); |
28
|
|
|
|
29
|
|
|
$this->object = new \Aimeos\Client\JsonApi\Example( $this->context ); |
30
|
|
|
|
31
|
|
|
$this->object->setView( $this->view ); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
public function testDelete() |
36
|
|
|
{ |
37
|
|
|
$response = $this->object->delete( $this->view->request(), $this->view->response() ); |
38
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
39
|
|
|
|
40
|
|
|
$this->assertEquals( 403, $response->getStatusCode() ); |
41
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
42
|
|
|
$this->assertArrayHasKey( 'errors', $result ); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
public function testGet() |
47
|
|
|
{ |
48
|
|
|
$response = $this->object->get( $this->view->request(), $this->view->response() ); |
49
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
50
|
|
|
|
51
|
|
|
$this->assertEquals( 403, $response->getStatusCode() ); |
52
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
53
|
|
|
$this->assertArrayHasKey( 'errors', $result ); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
public function testPatch() |
58
|
|
|
{ |
59
|
|
|
$response = $this->object->patch( $this->view->request(), $this->view->response() ); |
60
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
61
|
|
|
|
62
|
|
|
$this->assertEquals( 403, $response->getStatusCode() ); |
63
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
64
|
|
|
$this->assertArrayHasKey( 'errors', $result ); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
public function testPost() |
69
|
|
|
{ |
70
|
|
|
$response = $this->object->post( $this->view->request(), $this->view->response() ); |
71
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
72
|
|
|
|
73
|
|
|
$this->assertEquals( 403, $response->getStatusCode() ); |
74
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
75
|
|
|
$this->assertArrayHasKey( 'errors', $result ); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
public function testPut() |
80
|
|
|
{ |
81
|
|
|
$response = $this->object->put( $this->view->request(), $this->view->response() ); |
82
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
83
|
|
|
|
84
|
|
|
$this->assertEquals( 403, $response->getStatusCode() ); |
85
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
86
|
|
|
$this->assertArrayHasKey( 'errors', $result ); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
public function testOptions() |
91
|
|
|
{ |
92
|
|
|
$response = $this->object->options( $this->view->request(), $this->view->response() ); |
93
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
94
|
|
|
|
95
|
|
|
$this->assertEquals( 403, $response->getStatusCode() ); |
96
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
97
|
|
|
$this->assertArrayHasKey( 'errors', $result ); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
public function testGetContext() |
102
|
|
|
{ |
103
|
|
|
$result = $this->access( 'context' )->invokeArgs( $this->object, [] ); |
104
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\ContextIface::class, $result ); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
|
108
|
|
|
protected function access( $name ) |
109
|
|
|
{ |
110
|
|
|
$class = new \ReflectionClass( \Aimeos\Client\JsonApi\Base::class ); |
111
|
|
|
$method = $class->getMethod( $name ); |
112
|
|
|
$method->setAccessible( true ); |
113
|
|
|
|
114
|
|
|
return $method; |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|