1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017-2022 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\Client\JsonApi\Basket; |
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() : void |
20
|
|
|
{ |
21
|
|
|
\Aimeos\Controller\Frontend::cache( true ); |
22
|
|
|
|
23
|
|
|
$this->context = \TestHelper::context(); |
24
|
|
|
$this->view = $this->context->view(); |
25
|
|
|
|
26
|
|
|
$this->object = new \Aimeos\Client\JsonApi\Basket\Standard( $this->context ); |
27
|
|
|
$this->object->setView( $this->view ); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
protected function tearDown() : void |
32
|
|
|
{ |
33
|
|
|
\Aimeos\Controller\Frontend::cache( false ); |
34
|
|
|
unset( $this->view, $this->object, $this->context ); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
public function testDelete() |
39
|
|
|
{ |
40
|
|
|
$body = '{"data": {"attributes": {"order.comment": "test"}}}'; |
41
|
|
|
$request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
42
|
|
|
|
43
|
|
|
$response = $this->object->patch( $request, $this->view->response() ); |
44
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
45
|
|
|
|
46
|
|
|
$this->assertEquals( 'test', $result['data']['attributes']['order.comment'] ); |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
$response = $this->object->delete( $request, $this->view->response() ); |
50
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
51
|
|
|
|
52
|
|
|
$this->assertEquals( 200, $response->getStatusCode() ); |
53
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Allow' ) ) ); |
54
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
55
|
|
|
|
56
|
|
|
$this->assertEquals( 1, $result['meta']['total'] ); |
57
|
|
|
$this->assertEquals( 'basket', $result['data']['type'] ); |
58
|
|
|
$this->assertGreaterThan( 9, count( $result['data']['attributes'] ) ); |
59
|
|
|
$this->assertEquals( '', $result['data']['attributes']['order.comment'] ); |
60
|
|
|
|
61
|
|
|
$this->assertArrayNotHasKey( 'errors', $result ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
public function testDeletePluginException() |
66
|
|
|
{ |
67
|
|
|
$object = $this->object( 'setType', $this->throwException( new \Aimeos\MShop\Plugin\Provider\Exception() ) ); |
68
|
|
|
|
69
|
|
|
$response = $object->delete( $this->view->request(), $this->view->response() ); |
70
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
71
|
|
|
|
72
|
|
|
$this->assertEquals( 409, $response->getStatusCode() ); |
73
|
|
|
$this->assertArrayHasKey( 'errors', $result ); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
public function testDeleteMShopException() |
78
|
|
|
{ |
79
|
|
|
$object = $this->object( 'setType', $this->throwException( new \Aimeos\MShop\Exception() ) ); |
80
|
|
|
|
81
|
|
|
$response = $object->delete( $this->view->request(), $this->view->response() ); |
82
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
83
|
|
|
|
84
|
|
|
$this->assertEquals( 404, $response->getStatusCode() ); |
85
|
|
|
$this->assertArrayHasKey( 'errors', $result ); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
|
89
|
|
|
public function testDeleteException() |
90
|
|
|
{ |
91
|
|
|
$object = $this->object( 'setType', $this->throwException( new \Exception() ) ); |
92
|
|
|
|
93
|
|
|
$response = $object->delete( $this->view->request(), $this->view->response() ); |
94
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
$this->assertEquals( 500, $response->getStatusCode() ); |
98
|
|
|
$this->assertArrayHasKey( 'errors', $result ); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
|
102
|
|
|
public function testGet() |
103
|
|
|
{ |
104
|
|
|
$response = $this->object->get( $this->view->request(), $this->view->response() ); |
105
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
106
|
|
|
|
107
|
|
|
$this->assertEquals( 200, $response->getStatusCode() ); |
108
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Allow' ) ) ); |
109
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
110
|
|
|
|
111
|
|
|
$this->assertEquals( 1, $result['meta']['total'] ); |
112
|
|
|
$this->assertEquals( 'basket', $result['data']['type'] ); |
113
|
|
|
$this->assertGreaterThan( 9, count( $result['data']['attributes'] ) ); |
114
|
|
|
|
115
|
|
|
$this->assertArrayNotHasKey( 'errors', $result ); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
|
119
|
|
|
public function testGetById() |
120
|
|
|
{ |
121
|
|
|
$user = \Aimeos\MShop::create( $this->context, 'customer' )->find( '[email protected]' ); |
122
|
|
|
$this->context->setUserId( $user->getId() ); |
123
|
|
|
|
124
|
|
|
$params = ['id' => $this->getOrderItem()->getId()]; |
125
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $params ); |
126
|
|
|
$this->view->addHelper( 'param', $helper ); |
127
|
|
|
|
128
|
|
|
$response = $this->object->get( $this->view->request(), $this->view->response() ); |
129
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
130
|
|
|
|
131
|
|
|
$this->assertEquals( 200, $response->getStatusCode() ); |
132
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Allow' ) ) ); |
133
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
134
|
|
|
|
135
|
|
|
$this->assertEquals( 1, $result['meta']['total'] ); |
136
|
|
|
$this->assertEquals( 'basket', $result['data']['type'] ); |
137
|
|
|
$this->assertNotNull( $result['data']['id'] ); |
138
|
|
|
$this->assertEquals( 19, count( $result['data']['attributes'] ) ); |
139
|
|
|
$this->assertEquals( 'This is another comment.', $result['data']['attributes']['order.comment'] ); |
140
|
|
|
$this->assertEquals( 8, count( $result['included'] ) ); |
141
|
|
|
|
142
|
|
|
$this->assertArrayNotHasKey( 'errors', $result ); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
|
146
|
|
|
public function testGetNoAccess() |
147
|
|
|
{ |
148
|
|
|
$this->context->setUserId( null ); |
149
|
|
|
|
150
|
|
|
$params = array( |
151
|
|
|
'id' => $this->getOrderItem()->getId(), |
152
|
|
|
); |
153
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $params ); |
154
|
|
|
$this->view->addHelper( 'param', $helper ); |
155
|
|
|
|
156
|
|
|
$response = $this->object->get( $this->view->request(), $this->view->response() ); |
157
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
158
|
|
|
|
159
|
|
|
$this->assertEquals( 200, $response->getStatusCode() ); |
160
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Allow' ) ) ); |
161
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
162
|
|
|
|
163
|
|
|
$this->assertEquals( 1, $result['meta']['total'] ); |
164
|
|
|
$this->assertEquals( 'basket', $result['data']['type'] ); |
165
|
|
|
$this->assertEquals( '', $result['data']['attributes']['order.customerid'] ); |
166
|
|
|
|
167
|
|
|
$this->assertArrayNotHasKey( 'errors', $result ); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
|
171
|
|
|
public function testGetIncluded() |
172
|
|
|
{ |
173
|
|
|
$user = \Aimeos\MShop::create( $this->context, 'customer' )->find( '[email protected]' ); |
174
|
|
|
$this->context->setUserId( $user->getId() ); |
175
|
|
|
|
176
|
|
|
$params = array( |
177
|
|
|
'id' => $this->getOrderItem()->getId(), |
178
|
|
|
'include' => 'basket/product,customer', |
179
|
|
|
); |
180
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $params ); |
181
|
|
|
$this->view->addHelper( 'param', $helper ); |
182
|
|
|
|
183
|
|
|
$response = $this->object->get( $this->view->request(), $this->view->response() ); |
184
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
185
|
|
|
|
186
|
|
|
|
187
|
|
|
$this->assertEquals( 200, $response->getStatusCode() ); |
188
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Allow' ) ) ); |
189
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
190
|
|
|
|
191
|
|
|
$this->assertEquals( 1, $result['meta']['total'] ); |
192
|
|
|
$this->assertEquals( 'basket', $result['data']['type'] ); |
193
|
|
|
$this->assertEquals( 2, count( $result['data']['relationships'] ) ); |
194
|
|
|
$this->assertArrayHasKey( 'customer', $result['data']['relationships'] ); |
195
|
|
|
$this->assertArrayHasKey( 'basket/product', $result['data']['relationships'] ); |
196
|
|
|
$this->assertEquals( 2, count( $result['data']['relationships']['basket/product']['data'] ) ); |
197
|
|
|
$this->assertEquals( 1, count( $result['data']['relationships']['customer']['data'] ) ); |
198
|
|
|
$this->assertEquals( 3, count( $result['included'] ) ); |
199
|
|
|
|
200
|
|
|
$this->assertArrayNotHasKey( 'errors', $result ); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
|
204
|
|
|
public function testGetFieldsIncluded() |
205
|
|
|
{ |
206
|
|
|
$user = \Aimeos\MShop::create( $this->context, 'customer' )->find( '[email protected]' ); |
207
|
|
|
$this->context->setUserId( $user->getId() ); |
208
|
|
|
|
209
|
|
|
$params = array( |
210
|
|
|
'id' => $this->getOrderItem()->getId(), |
211
|
|
|
'fields' => array( |
212
|
|
|
'basket' => 'order.comment', |
213
|
|
|
'basket/address' => 'order.address.firstname,order.address.lastname', |
214
|
|
|
'basket/product' => 'order.product.name,order.product.price', |
215
|
|
|
'basket/service' => 'order.service.name,order.service.price', |
216
|
|
|
'customer' => 'customer.id,customer.email' |
217
|
|
|
), |
218
|
|
|
'include' => 'basket/address,basket/product,basket/service,customer' |
219
|
|
|
); |
220
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $params ); |
221
|
|
|
$this->view->addHelper( 'param', $helper ); |
222
|
|
|
|
223
|
|
|
$response = $this->object->get( $this->view->request(), $this->view->response() ); |
224
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
225
|
|
|
|
226
|
|
|
$this->assertEquals( 200, $response->getStatusCode() ); |
227
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Allow' ) ) ); |
228
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
229
|
|
|
|
230
|
|
|
$this->assertEquals( 1, $result['meta']['total'] ); |
231
|
|
|
$this->assertEquals( 'basket', $result['data']['type'] ); |
232
|
|
|
$this->assertEquals( 1, count( $result['data']['attributes'] ) ); |
233
|
|
|
$this->assertEquals( 7, count( $result['included'] ) ); |
234
|
|
|
|
235
|
|
|
foreach( $result['included'] as $entry ) { |
236
|
|
|
$this->assertCount( 2, $entry['attributes'] ); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
$this->assertArrayNotHasKey( 'errors', $result ); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
|
243
|
|
|
public function testGetIncludedNone() |
244
|
|
|
{ |
245
|
|
|
$user = \Aimeos\MShop::create( $this->context, 'customer' )->find( '[email protected]' ); |
246
|
|
|
$this->context->setUserId( $user->getId() ); |
247
|
|
|
|
248
|
|
|
$params = array( |
249
|
|
|
'id' => $this->getOrderItem()->getId(), |
250
|
|
|
'include' => '', |
251
|
|
|
); |
252
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $params ); |
253
|
|
|
$this->view->addHelper( 'param', $helper ); |
254
|
|
|
|
255
|
|
|
$response = $this->object->get( $this->view->request(), $this->view->response() ); |
256
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
257
|
|
|
|
258
|
|
|
$this->assertEquals( 200, $response->getStatusCode() ); |
259
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Allow' ) ) ); |
260
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
261
|
|
|
|
262
|
|
|
$this->assertEquals( 1, $result['meta']['total'] ); |
263
|
|
|
$this->assertEquals( 'basket', $result['data']['type'] ); |
264
|
|
|
$this->assertEquals( 0, count( $result['data']['relationships'] ) ); |
265
|
|
|
$this->assertEquals( 0, count( $result['included'] ) ); |
266
|
|
|
|
267
|
|
|
$this->assertArrayNotHasKey( 'errors', $result ); |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
|
271
|
|
|
public function testGetMShopException() |
272
|
|
|
{ |
273
|
|
|
$object = $this->object( 'setType', $this->throwException( new \Aimeos\MShop\Exception() ) ); |
274
|
|
|
|
275
|
|
|
$response = $object->get( $this->view->request(), $this->view->response() ); |
276
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
277
|
|
|
|
278
|
|
|
|
279
|
|
|
$this->assertEquals( 404, $response->getStatusCode() ); |
280
|
|
|
$this->assertArrayHasKey( 'errors', $result ); |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
|
284
|
|
|
public function testGetException() |
285
|
|
|
{ |
286
|
|
|
$object = $this->object( 'setType', $this->throwException( new \Exception() ) ); |
287
|
|
|
|
288
|
|
|
$response = $object->get( $this->view->request(), $this->view->response() ); |
289
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
290
|
|
|
|
291
|
|
|
|
292
|
|
|
$this->assertEquals( 500, $response->getStatusCode() ); |
293
|
|
|
$this->assertArrayHasKey( 'errors', $result ); |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
|
297
|
|
|
public function testPatch() |
298
|
|
|
{ |
299
|
|
|
$body = '{"data": {"attributes": {"order.comment": "test", "order.customerref": "abc"}}} '; |
300
|
|
|
$request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
301
|
|
|
|
302
|
|
|
$response = $this->object->patch( $request, $this->view->response() ); |
303
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
304
|
|
|
|
305
|
|
|
|
306
|
|
|
$this->assertEquals( 200, $response->getStatusCode() ); |
307
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Allow' ) ) ); |
308
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
309
|
|
|
|
310
|
|
|
$this->assertEquals( 1, $result['meta']['total'] ); |
311
|
|
|
$this->assertEquals( 'basket', $result['data']['type'] ); |
312
|
|
|
$this->assertGreaterThan( 10, count( $result['data']['attributes'] ) ); |
313
|
|
|
$this->assertEquals( 'test', $result['data']['attributes']['order.comment'] ); |
314
|
|
|
$this->assertEquals( 'abc', $result['data']['attributes']['order.customerref'] ); |
315
|
|
|
|
316
|
|
|
$this->assertArrayNotHasKey( 'errors', $result ); |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
|
320
|
|
|
public function testPatchPluginException() |
321
|
|
|
{ |
322
|
|
|
$object = $this->object( 'setType', $this->throwException( new \Aimeos\MShop\Plugin\Provider\Exception() ) ); |
323
|
|
|
|
324
|
|
|
$body = '{"data": {"attributes": []}}'; |
325
|
|
|
$request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
326
|
|
|
|
327
|
|
|
$response = $object->patch( $request, $this->view->response() ); |
328
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
329
|
|
|
|
330
|
|
|
|
331
|
|
|
$this->assertEquals( 409, $response->getStatusCode() ); |
332
|
|
|
$this->assertArrayHasKey( 'errors', $result ); |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
|
336
|
|
|
public function testPatchMShopException() |
337
|
|
|
{ |
338
|
|
|
$object = $this->object( 'setType', $this->throwException( new \Aimeos\MShop\Exception() ) ); |
339
|
|
|
|
340
|
|
|
$body = '{"data": {"attributes": []}}'; |
341
|
|
|
$request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
342
|
|
|
|
343
|
|
|
$response = $object->patch( $request, $this->view->response() ); |
344
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
345
|
|
|
|
346
|
|
|
|
347
|
|
|
$this->assertEquals( 404, $response->getStatusCode() ); |
348
|
|
|
$this->assertArrayHasKey( 'errors', $result ); |
349
|
|
|
} |
350
|
|
|
|
351
|
|
|
|
352
|
|
|
public function testPatchException() |
353
|
|
|
{ |
354
|
|
|
$object = $this->object( 'setType', $this->throwException( new \Exception() ) ); |
355
|
|
|
|
356
|
|
|
$body = '{"data": {"attributes": []}}'; |
357
|
|
|
$request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
358
|
|
|
|
359
|
|
|
$response = $object->patch( $request, $this->view->response() ); |
360
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
361
|
|
|
|
362
|
|
|
|
363
|
|
|
$this->assertEquals( 500, $response->getStatusCode() ); |
364
|
|
|
$this->assertArrayHasKey( 'errors', $result ); |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
|
368
|
|
|
public function testPost() |
369
|
|
|
{ |
370
|
|
|
$price = \Aimeos\MShop::create( $this->context, 'price' )->create(); |
371
|
|
|
$locale = \Aimeos\MShop::create( $this->context, 'locale' )->create(); |
372
|
|
|
|
373
|
|
|
$basket = $this->getMockBuilder( \Aimeos\MShop\Order\Item\Standard::class ) |
374
|
|
|
->setConstructorArgs( [$price, $locale] ) |
375
|
|
|
->setMethods( ['check'] ) |
376
|
|
|
->getMock(); |
377
|
|
|
|
378
|
|
|
$basket->expects( $this->once() )->method( 'check' )->will( $this->returnSelf() ); |
379
|
|
|
|
380
|
|
|
$object = $this->object( ['get', 'store'], $this->returnValue( $basket ) ); |
381
|
|
|
|
382
|
|
|
|
383
|
|
|
$body = '{"data": {"attributes": {"order.comment": "test"}}}'; |
384
|
|
|
$request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
385
|
|
|
|
386
|
|
|
$response = $object->post( $request, $this->view->response() ); |
387
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
388
|
|
|
|
389
|
|
|
$this->assertEquals( 200, $response->getStatusCode() ); |
390
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Allow' ) ) ); |
391
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
392
|
|
|
|
393
|
|
|
$this->assertEquals( 1, $result['meta']['total'] ); |
394
|
|
|
$this->assertNotNull( $result['data']['id'] ); |
395
|
|
|
$this->assertEquals( 'basket', $result['data']['type'] ); |
396
|
|
|
$this->assertGreaterThan( 9, count( $result['data']['attributes'] ) ); |
397
|
|
|
|
398
|
|
|
$this->assertArrayNotHasKey( 'errors', $result ); |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
|
402
|
|
|
public function testPostPluginException() |
403
|
|
|
{ |
404
|
|
|
$object = $this->object( 'get', $this->throwException( new \Aimeos\MShop\Plugin\Provider\Exception() ) ); |
405
|
|
|
|
406
|
|
|
$response = $object->post( $this->view->request(), $this->view->response() ); |
407
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
408
|
|
|
|
409
|
|
|
|
410
|
|
|
$this->assertEquals( 409, $response->getStatusCode() ); |
411
|
|
|
$this->assertArrayHasKey( 'errors', $result ); |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
|
415
|
|
|
public function testPostMShopException() |
416
|
|
|
{ |
417
|
|
|
$object = $this->object( 'get', $this->throwException( new \Aimeos\MShop\Exception() ) ); |
418
|
|
|
|
419
|
|
|
$response = $object->post( $this->view->request(), $this->view->response() ); |
420
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
421
|
|
|
|
422
|
|
|
|
423
|
|
|
$this->assertEquals( 404, $response->getStatusCode() ); |
424
|
|
|
$this->assertArrayHasKey( 'errors', $result ); |
425
|
|
|
} |
426
|
|
|
|
427
|
|
|
|
428
|
|
|
public function testPostException() |
429
|
|
|
{ |
430
|
|
|
$object = $this->object( 'get', $this->throwException( new \Exception() ) ); |
431
|
|
|
|
432
|
|
|
$response = $object->post( $this->view->request(), $this->view->response() ); |
433
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
434
|
|
|
|
435
|
|
|
|
436
|
|
|
$this->assertEquals( 500, $response->getStatusCode() ); |
437
|
|
|
$this->assertArrayHasKey( 'errors', $result ); |
438
|
|
|
} |
439
|
|
|
|
440
|
|
|
|
441
|
|
|
public function testOptions() |
442
|
|
|
{ |
443
|
|
|
$response = $this->object->options( $this->view->request(), $this->view->response() ); |
444
|
|
|
$result = json_decode( (string) $response->getBody(), true ); |
445
|
|
|
|
446
|
|
|
$this->assertEquals( 200, $response->getStatusCode() ); |
447
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Allow' ) ) ); |
448
|
|
|
$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
449
|
|
|
|
450
|
|
|
$this->assertEquals( null, $result['meta']['prefix'] ); |
451
|
|
|
$this->assertEquals( 2, count( $result['meta']['attributes'] ) ); |
452
|
|
|
$this->assertArrayNotHasKey( 'filter', $result['meta'] ); |
453
|
|
|
$this->assertArrayNotHasKey( 'sort', $result['meta'] ); |
454
|
|
|
$this->assertArrayNotHasKey( 'errors', $result ); |
455
|
|
|
} |
456
|
|
|
|
457
|
|
|
|
458
|
|
|
/** |
459
|
|
|
* Returns a stored order |
460
|
|
|
* |
461
|
|
|
* @return \Aimeos\MShop\Order\Item\Iface Order object |
462
|
|
|
*/ |
463
|
|
|
protected function getOrderItem() |
464
|
|
|
{ |
465
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'order' ); |
466
|
|
|
|
467
|
|
|
$search = $manager->filter(); |
468
|
|
|
$search->setConditions( $search->compare( '==', 'order.price', '672.00' ) ); |
469
|
|
|
|
470
|
|
|
if( ( $item = $manager->search( $search, ['order/product'] )->first() ) === null ) { |
471
|
|
|
throw new \Exception( 'No order item with price "672.00" found' ); |
472
|
|
|
} |
473
|
|
|
|
474
|
|
|
return $item; |
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
|
478
|
|
|
/** |
479
|
|
|
* Returns a test object with a mocked basket controller |
480
|
|
|
* |
481
|
|
|
* @param array|string $method Basket controller method name to mock |
482
|
|
|
* @param mixed $result Return value of the mocked method |
483
|
|
|
*/ |
484
|
|
|
protected function object( $method, $result ) |
485
|
|
|
{ |
486
|
|
|
$methods = (array) $method; |
487
|
|
|
|
488
|
|
|
$cntl = $this->getMockBuilder( \Aimeos\Controller\Frontend\Basket\Standard::class ) |
489
|
|
|
->setConstructorArgs( [$this->context] ) |
490
|
|
|
->setMethods( $methods ) |
491
|
|
|
->getMock(); |
492
|
|
|
|
493
|
|
|
foreach( $methods as $method ) { |
|
|
|
|
494
|
|
|
$cntl->expects( $this->once() )->method( $method )->will( $result ); |
495
|
|
|
} |
496
|
|
|
|
497
|
|
|
\Aimeos\Controller\Frontend::inject( '\Aimeos\Controller\Frontend\Basket\Standard', $cntl ); |
498
|
|
|
|
499
|
|
|
$object = new \Aimeos\Client\JsonApi\Basket\Standard( $this->context ); |
500
|
|
|
$object->setView( $this->view ); |
501
|
|
|
|
502
|
|
|
return $object; |
503
|
|
|
} |
504
|
|
|
} |
505
|
|
|
|