1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class JsonadmControllerTest extends AimeosTestAbstract |
4
|
|
|
{ |
5
|
|
|
public function testOptionsActionSite() |
6
|
|
|
{ |
7
|
|
|
View::addLocation(dirname(__DIR__).'/fixtures/views'); |
8
|
|
|
|
9
|
|
|
$params = ['site' => 'invalid', 'resource' => 'product']; |
10
|
|
|
$response = $this->action('OPTIONS', '\Aimeos\Shop\Controller\JsonadmController@optionsAction', $params); |
11
|
|
|
|
12
|
|
|
$json = json_decode( $response->getContent(), true ); |
13
|
|
|
|
14
|
|
|
$this->assertResponseOk(); |
15
|
|
|
$this->assertNotNull( $json ); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
public function testOptionsAction() |
20
|
|
|
{ |
21
|
|
|
View::addLocation(dirname(__DIR__).'/fixtures/views'); |
22
|
|
|
|
23
|
|
|
$params = ['site' => 'unittest', 'resource' => 'product']; |
24
|
|
|
$response = $this->action('OPTIONS', '\Aimeos\Shop\Controller\JsonadmController@optionsAction', $params); |
25
|
|
|
|
26
|
|
|
$json = json_decode( $response->getContent(), true ); |
27
|
|
|
|
28
|
|
|
$this->assertNotNull( $json ); |
29
|
|
|
$this->assertEquals( 200, $response->getStatusCode() ); |
30
|
|
|
$this->assertArrayHasKey( 'resources', $json['meta'] ); |
31
|
|
|
$this->assertGreaterThan( 1, count( $json['meta']['resources'] ) ); |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
$params = ['site' => 'unittest']; |
35
|
|
|
$response = $this->action('OPTIONS', '\Aimeos\Shop\Controller\JsonadmController@optionsAction', $params); |
36
|
|
|
|
37
|
|
|
$json = json_decode( $response->getContent(), true ); |
38
|
|
|
|
39
|
|
|
$this->assertNotNull( $json ); |
40
|
|
|
$this->assertEquals( 200, $response->getStatusCode() ); |
41
|
|
|
$this->assertArrayHasKey( 'resources', $json['meta'] ); |
42
|
|
|
$this->assertGreaterThan( 1, count( $json['meta']['resources'] ) ); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
public function testActionsSingle() |
47
|
|
|
{ |
48
|
|
|
View::addLocation(dirname(__DIR__).'/fixtures/views'); |
49
|
|
|
|
50
|
|
|
$params = ['site' => 'unittest', 'resource' => 'stock/type']; |
51
|
|
|
$content = '{"data":{"type":"stock/type","attributes":{"stock.type.code":"laravel","stock.type.label":"laravel"}}}'; |
52
|
|
|
$response = $this->action('POST', '\Aimeos\Shop\Controller\JsonadmController@postAction', $params, [], [], [], [], $content); |
53
|
|
|
|
54
|
|
|
$json = json_decode( $response->getContent(), true ); |
55
|
|
|
|
56
|
|
|
$this->assertEquals( 201, $response->getStatusCode() ); |
57
|
|
|
$this->assertNotNull( $json ); |
58
|
|
|
$this->assertArrayHasKey( 'stock.type.id', $json['data']['attributes'] ); |
59
|
|
|
$this->assertEquals( 'laravel', $json['data']['attributes']['stock.type.code'] ); |
60
|
|
|
$this->assertEquals( 'laravel', $json['data']['attributes']['stock.type.label'] ); |
61
|
|
|
$this->assertEquals( 1, $json['meta']['total'] ); |
62
|
|
|
|
63
|
|
|
$id = $json['data']['attributes']['stock.type.id']; |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
$params = ['site' => 'unittest', 'resource' => 'stock/type', 'id' => $id ]; |
67
|
|
|
$content = '{"data":{"type":"stock/type","attributes":{"stock.type.code":"laravel2","stock.type.label":"laravel2"}}}'; |
68
|
|
|
$response = $this->action('PATCH', '\Aimeos\Shop\Controller\JsonadmController@patchAction', $params, [], [], [], [], $content); |
69
|
|
|
|
70
|
|
|
$json = json_decode( $response->getContent(), true ); |
71
|
|
|
|
72
|
|
|
$this->assertResponseOk(); |
73
|
|
|
$this->assertNotNull( $json ); |
74
|
|
|
$this->assertArrayHasKey( 'stock.type.id', $json['data']['attributes'] ); |
75
|
|
|
$this->assertEquals( 'laravel2', $json['data']['attributes']['stock.type.code'] ); |
76
|
|
|
$this->assertEquals( 'laravel2', $json['data']['attributes']['stock.type.label'] ); |
77
|
|
|
$this->assertEquals( $id, $json['data']['attributes']['stock.type.id'] ); |
78
|
|
|
$this->assertEquals( 1, $json['meta']['total'] ); |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
$params = ['site' => 'unittest', 'resource' => 'stock/type', 'id' => $id ]; |
82
|
|
|
$response = $this->action('GET', '\Aimeos\Shop\Controller\JsonadmController@getAction', $params); |
83
|
|
|
|
84
|
|
|
$json = json_decode( $response->getContent(), true ); |
85
|
|
|
|
86
|
|
|
$this->assertResponseOk(); |
87
|
|
|
$this->assertNotNull( $json ); |
88
|
|
|
$this->assertArrayHasKey( 'stock.type.id', $json['data']['attributes'] ); |
89
|
|
|
$this->assertEquals( 'laravel2', $json['data']['attributes']['stock.type.code'] ); |
90
|
|
|
$this->assertEquals( 'laravel2', $json['data']['attributes']['stock.type.label'] ); |
91
|
|
|
$this->assertEquals( $id, $json['data']['attributes']['stock.type.id'] ); |
92
|
|
|
$this->assertEquals( 1, $json['meta']['total'] ); |
93
|
|
|
|
94
|
|
|
|
95
|
|
|
$params = ['site' => 'unittest', 'resource' => 'stock/type', 'id' => $id ]; |
96
|
|
|
$response = $this->action('DELETE', '\Aimeos\Shop\Controller\JsonadmController@deleteAction', $params); |
97
|
|
|
|
98
|
|
|
$json = json_decode( $response->getContent(), true ); |
99
|
|
|
|
100
|
|
|
$this->assertResponseOk(); |
101
|
|
|
$this->assertNotNull( $json ); |
102
|
|
|
$this->assertEquals( 1, $json['meta']['total'] ); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
public function testActionsBulk() |
107
|
|
|
{ |
108
|
|
|
View::addLocation(dirname(__DIR__).'/fixtures/views'); |
109
|
|
|
|
110
|
|
|
$params = ['site' => 'unittest', 'resource' => 'stock/type']; |
111
|
|
|
$content = '{"data":[ |
112
|
|
|
{"type":"stock/type","attributes":{"stock.type.code":"laravel","stock.type.label":"laravel"}}, |
113
|
|
|
{"type":"stock/type","attributes":{"stock.type.code":"laravel2","stock.type.label":"laravel"}} |
114
|
|
|
]}'; |
115
|
|
|
$response = $this->action('POST', '\Aimeos\Shop\Controller\JsonadmController@postAction', $params, [], [], [], [], $content); |
116
|
|
|
|
117
|
|
|
$json = json_decode( $response->getContent(), true ); |
118
|
|
|
|
119
|
|
|
$this->assertEquals( 201, $response->getStatusCode() ); |
120
|
|
|
$this->assertNotNull( $json ); |
121
|
|
|
$this->assertEquals( 2, count( $json['data'] ) ); |
122
|
|
|
$this->assertArrayHasKey( 'stock.type.id', $json['data'][0]['attributes'] ); |
123
|
|
|
$this->assertArrayHasKey( 'stock.type.id', $json['data'][1]['attributes'] ); |
124
|
|
|
$this->assertEquals( 'laravel', $json['data'][0]['attributes']['stock.type.label'] ); |
125
|
|
|
$this->assertEquals( 'laravel', $json['data'][1]['attributes']['stock.type.label'] ); |
126
|
|
|
$this->assertEquals( 2, $json['meta']['total'] ); |
127
|
|
|
|
128
|
|
|
$ids = array( $json['data'][0]['attributes']['stock.type.id'], $json['data'][1]['attributes']['stock.type.id'] ); |
129
|
|
|
|
130
|
|
|
|
131
|
|
|
$params = ['site' => 'unittest', 'resource' => 'stock/type' ]; |
132
|
|
|
$content = '{"data":[ |
133
|
|
|
{"type":"stock/type","id":' . $ids[0] . ',"attributes":{"stock.type.label":"laravel2"}}, |
134
|
|
|
{"type":"stock/type","id":' . $ids[1] . ',"attributes":{"stock.type.label":"laravel2"}} |
135
|
|
|
]}'; |
136
|
|
|
$response = $this->action('PATCH', '\Aimeos\Shop\Controller\JsonadmController@patchAction', $params, [], [], [], [], $content); |
137
|
|
|
|
138
|
|
|
$json = json_decode( $response->getContent(), true ); |
139
|
|
|
|
140
|
|
|
$this->assertResponseOk(); |
141
|
|
|
$this->assertNotNull( $json ); |
142
|
|
|
$this->assertEquals( 2, count( $json['data'] ) ); |
143
|
|
|
$this->assertArrayHasKey( 'stock.type.id', $json['data'][0]['attributes'] ); |
144
|
|
|
$this->assertArrayHasKey( 'stock.type.id', $json['data'][1]['attributes'] ); |
145
|
|
|
$this->assertEquals( 'laravel2', $json['data'][0]['attributes']['stock.type.label'] ); |
146
|
|
|
$this->assertEquals( 'laravel2', $json['data'][1]['attributes']['stock.type.label'] ); |
147
|
|
|
$this->assertTrue( in_array( $json['data'][0]['attributes']['stock.type.id'], $ids ) ); |
148
|
|
|
$this->assertTrue( in_array( $json['data'][1]['attributes']['stock.type.id'], $ids ) ); |
149
|
|
|
$this->assertEquals( 2, $json['meta']['total'] ); |
150
|
|
|
|
151
|
|
|
|
152
|
|
|
$params = ['site' => 'unittest', 'resource' => 'stock/type' ]; |
153
|
|
|
$getParams = ['filter' => ['&&' => [ |
154
|
|
|
['=~' => ['stock.type.code' => 'laravel']], |
155
|
|
|
['==' => ['stock.type.label' => 'laravel2']] |
156
|
|
|
]], |
157
|
|
|
'sort' => 'stock.type.code', 'page' => ['offset' => 0, 'limit' => 3] |
158
|
|
|
]; |
159
|
|
|
$response = $this->action('GET', '\Aimeos\Shop\Controller\JsonadmController@getAction', $params, $getParams); |
160
|
|
|
|
161
|
|
|
$json = json_decode( $response->getContent(), true ); |
162
|
|
|
|
163
|
|
|
$this->assertResponseOk(); |
164
|
|
|
$this->assertNotNull( $json ); |
165
|
|
|
$this->assertEquals( 2, count( $json['data'] ) ); |
166
|
|
|
$this->assertEquals( 'laravel', $json['data'][0]['attributes']['stock.type.code'] ); |
167
|
|
|
$this->assertEquals( 'laravel2', $json['data'][1]['attributes']['stock.type.code'] ); |
168
|
|
|
$this->assertEquals( 'laravel2', $json['data'][0]['attributes']['stock.type.label'] ); |
169
|
|
|
$this->assertEquals( 'laravel2', $json['data'][1]['attributes']['stock.type.label'] ); |
170
|
|
|
$this->assertTrue( in_array( $json['data'][0]['attributes']['stock.type.id'], $ids ) ); |
171
|
|
|
$this->assertTrue( in_array( $json['data'][1]['attributes']['stock.type.id'], $ids ) ); |
172
|
|
|
$this->assertEquals( 2, $json['meta']['total'] ); |
173
|
|
|
|
174
|
|
|
|
175
|
|
|
$params = ['site' => 'unittest', 'resource' => 'stock/type' ]; |
176
|
|
|
$content = '{"data":[ |
177
|
|
|
{"type":"stock/type","id":' . $ids[0] . '}, |
178
|
|
|
{"type":"stock/type","id":' . $ids[1] . '} |
179
|
|
|
]}'; |
180
|
|
|
$response = $this->action('DELETE', '\Aimeos\Shop\Controller\JsonadmController@deleteAction', $params, [], [], [], [], $content); |
181
|
|
|
|
182
|
|
|
$json = json_decode( $response->getContent(), true ); |
183
|
|
|
|
184
|
|
|
$this->assertResponseOk(); |
185
|
|
|
$this->assertNotNull( $json ); |
186
|
|
|
$this->assertEquals( 2, $json['meta']['total'] ); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
|
190
|
|
|
public function testPutAction() |
191
|
|
|
{ |
192
|
|
|
View::addLocation(dirname(__DIR__).'/fixtures/views'); |
193
|
|
|
|
194
|
|
|
$params = ['site' => 'unittest', 'resource' => 'stock/type']; |
195
|
|
|
$content = '{"data":[ |
196
|
|
|
{"type":"stock/type","attributes":{"stock.type.code":"laravel","stock.type.label":"laravel"}}, |
197
|
|
|
{"type":"stock/type","attributes":{"stock.type.code":"laravel2","stock.type.label":"laravel"}} |
198
|
|
|
]}'; |
199
|
|
|
$response = $this->action('PUT', '\Aimeos\Shop\Controller\JsonadmController@postAction', $params, [], [], [], [], $content); |
200
|
|
|
|
201
|
|
|
$json = json_decode( $response->getContent(), true ); |
202
|
|
|
|
203
|
|
|
$this->assertEquals( 501, $response->getStatusCode() ); |
204
|
|
|
$this->assertNotNull( $json ); |
205
|
|
|
} |
206
|
|
|
} |
207
|
|
|
|