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