@@ -415,6 +415,7 @@ |
||
415 | 415 | * @param \Psr\Http\Message\ServerRequestInterface $request Request object |
416 | 416 | * @param \Psr\Http\Message\ResponseInterface $response Response object |
417 | 417 | * @param string|null Form parameter prefix when nesting parameters is required |
418 | + * @param string $prefix |
|
418 | 419 | * @return \Psr\Http\Message\ResponseInterface Modified response object |
419 | 420 | */ |
420 | 421 | public function options( ServerRequestInterface $request, ResponseInterface $response, $prefix = null ) |
@@ -31,38 +31,38 @@ discard block |
||
31 | 31 | * @param \Psr\Http\Message\ResponseInterface $response Response object |
32 | 32 | * @return \Psr\Http\Message\ResponseInterface Modified response object |
33 | 33 | */ |
34 | - public function delete( ServerRequestInterface $request, ResponseInterface $response ) |
|
34 | + public function delete(ServerRequestInterface $request, ResponseInterface $response) |
|
35 | 35 | { |
36 | 36 | $view = $this->getView(); |
37 | 37 | |
38 | 38 | try |
39 | 39 | { |
40 | - $response = $this->deleteItems( $view, $request, $response ); |
|
40 | + $response = $this->deleteItems($view, $request, $response); |
|
41 | 41 | $status = 200; |
42 | 42 | } |
43 | - catch( \Aimeos\Admin\JsonAdm\Exception $e ) |
|
43 | + catch (\Aimeos\Admin\JsonAdm\Exception $e) |
|
44 | 44 | { |
45 | 45 | $status = $e->getCode(); |
46 | - $view->errors = array( array( |
|
47 | - 'title' => $this->getContext()->getI18n()->dt( 'admin/jsonadm', $e->getMessage() ), |
|
46 | + $view->errors = array(array( |
|
47 | + 'title' => $this->getContext()->getI18n()->dt('admin/jsonadm', $e->getMessage()), |
|
48 | 48 | 'detail' => $e->getTraceAsString(), |
49 | - ) ); |
|
49 | + )); |
|
50 | 50 | } |
51 | - catch( \Aimeos\MShop\Exception $e ) |
|
51 | + catch (\Aimeos\MShop\Exception $e) |
|
52 | 52 | { |
53 | 53 | $status = 404; |
54 | - $view->errors = array( array( |
|
55 | - 'title' => $this->getContext()->getI18n()->dt( 'mshop', $e->getMessage() ), |
|
54 | + $view->errors = array(array( |
|
55 | + 'title' => $this->getContext()->getI18n()->dt('mshop', $e->getMessage()), |
|
56 | 56 | 'detail' => $e->getTraceAsString(), |
57 | - ) ); |
|
57 | + )); |
|
58 | 58 | } |
59 | - catch( \Exception $e ) |
|
59 | + catch (\Exception $e) |
|
60 | 60 | { |
61 | 61 | $status = 500; |
62 | - $view->errors = array( array( |
|
62 | + $view->errors = array(array( |
|
63 | 63 | 'title' => $e->getMessage(), |
64 | 64 | 'detail' => $e->getTraceAsString(), |
65 | - ) ); |
|
65 | + )); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** admin/jsonadm/standard/template-delete |
@@ -93,11 +93,11 @@ discard block |
||
93 | 93 | $tplconf = 'admin/jsonadm/standard/template-delete'; |
94 | 94 | $default = 'delete-default.php'; |
95 | 95 | |
96 | - $body = $view->render( $view->config( $tplconf, $default ) ); |
|
96 | + $body = $view->render($view->config($tplconf, $default)); |
|
97 | 97 | |
98 | - return $response->withHeader( 'Content-Type', 'application/vnd.api+json; supported-ext="bulk"' ) |
|
99 | - ->withBody( $view->response()->createStreamFromString( $body ) ) |
|
100 | - ->withStatus( $status ); |
|
98 | + return $response->withHeader('Content-Type', 'application/vnd.api+json; supported-ext="bulk"') |
|
99 | + ->withBody($view->response()->createStreamFromString($body)) |
|
100 | + ->withStatus($status); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | |
@@ -108,33 +108,33 @@ discard block |
||
108 | 108 | * @param \Psr\Http\Message\ResponseInterface $response Response object |
109 | 109 | * @return \Psr\Http\Message\ResponseInterface Modified response object |
110 | 110 | */ |
111 | - public function get( ServerRequestInterface $request, ResponseInterface $response ) |
|
111 | + public function get(ServerRequestInterface $request, ResponseInterface $response) |
|
112 | 112 | { |
113 | 113 | $view = $this->getView(); |
114 | 114 | |
115 | 115 | try |
116 | 116 | { |
117 | - $response = $this->getItems( $view, $request, $response ); |
|
117 | + $response = $this->getItems($view, $request, $response); |
|
118 | 118 | $status = 200; |
119 | 119 | } |
120 | - catch( \Aimeos\MShop\Exception $e ) |
|
120 | + catch (\Aimeos\MShop\Exception $e) |
|
121 | 121 | { |
122 | 122 | $status = 404; |
123 | - $view->errors = array( array( |
|
124 | - 'title' => $this->getContext()->getI18n()->dt( 'mshop', $e->getMessage() ), |
|
123 | + $view->errors = array(array( |
|
124 | + 'title' => $this->getContext()->getI18n()->dt('mshop', $e->getMessage()), |
|
125 | 125 | 'detail' => $e->getTraceAsString(), |
126 | - ) ); |
|
126 | + )); |
|
127 | 127 | } |
128 | - catch( \Exception $e ) |
|
128 | + catch (\Exception $e) |
|
129 | 129 | { |
130 | 130 | $status = 500; |
131 | - $view->errors = array( array( |
|
131 | + $view->errors = array(array( |
|
132 | 132 | 'title' => $e->getMessage(), |
133 | 133 | 'detail' => $e->getTraceAsString(), |
134 | - ) ); |
|
134 | + )); |
|
135 | 135 | } |
136 | 136 | |
137 | - if( $view->param( 'aggregate' ) !== null ) |
|
137 | + if ($view->param('aggregate') !== null) |
|
138 | 138 | { |
139 | 139 | /** admin/jsonadm/standard/template-aggregate |
140 | 140 | * Relative path to the JSON API template for GET aggregate requests |
@@ -195,11 +195,11 @@ discard block |
||
195 | 195 | $default = 'get-default.php'; |
196 | 196 | } |
197 | 197 | |
198 | - $body = $view->render( $view->config( $tplconf, $default ) ); |
|
198 | + $body = $view->render($view->config($tplconf, $default)); |
|
199 | 199 | |
200 | - return $response->withHeader( 'Content-Type', 'application/vnd.api+json; supported-ext="bulk"' ) |
|
201 | - ->withBody( $view->response()->createStreamFromString( $body ) ) |
|
202 | - ->withStatus( $status ); |
|
200 | + return $response->withHeader('Content-Type', 'application/vnd.api+json; supported-ext="bulk"') |
|
201 | + ->withBody($view->response()->createStreamFromString($body)) |
|
202 | + ->withStatus($status); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | |
@@ -210,38 +210,38 @@ discard block |
||
210 | 210 | * @param \Psr\Http\Message\ResponseInterface $response Response object |
211 | 211 | * @return \Psr\Http\Message\ResponseInterface Modified response object |
212 | 212 | */ |
213 | - public function patch( ServerRequestInterface $request, ResponseInterface $response ) |
|
213 | + public function patch(ServerRequestInterface $request, ResponseInterface $response) |
|
214 | 214 | { |
215 | 215 | $view = $this->getView(); |
216 | 216 | |
217 | 217 | try |
218 | 218 | { |
219 | - $response = $this->patchItems( $view, $request, $response ); |
|
219 | + $response = $this->patchItems($view, $request, $response); |
|
220 | 220 | $status = 200; |
221 | 221 | } |
222 | - catch( \Aimeos\Admin\JsonAdm\Exception $e ) |
|
222 | + catch (\Aimeos\Admin\JsonAdm\Exception $e) |
|
223 | 223 | { |
224 | 224 | $status = $e->getCode(); |
225 | - $view->errors = array( array( |
|
226 | - 'title' => $this->getContext()->getI18n()->dt( 'admin/jsonadm', $e->getMessage() ), |
|
225 | + $view->errors = array(array( |
|
226 | + 'title' => $this->getContext()->getI18n()->dt('admin/jsonadm', $e->getMessage()), |
|
227 | 227 | 'detail' => $e->getTraceAsString(), |
228 | - ) ); |
|
228 | + )); |
|
229 | 229 | } |
230 | - catch( \Aimeos\MShop\Exception $e ) |
|
230 | + catch (\Aimeos\MShop\Exception $e) |
|
231 | 231 | { |
232 | 232 | $status = 404; |
233 | - $view->errors = array( array( |
|
234 | - 'title' => $this->getContext()->getI18n()->dt( 'mshop', $e->getMessage() ), |
|
233 | + $view->errors = array(array( |
|
234 | + 'title' => $this->getContext()->getI18n()->dt('mshop', $e->getMessage()), |
|
235 | 235 | 'detail' => $e->getTraceAsString(), |
236 | - ) ); |
|
236 | + )); |
|
237 | 237 | } |
238 | - catch( \Exception $e ) |
|
238 | + catch (\Exception $e) |
|
239 | 239 | { |
240 | 240 | $status = 500; |
241 | - $view->errors = array( array( |
|
241 | + $view->errors = array(array( |
|
242 | 242 | 'title' => $e->getMessage(), |
243 | 243 | 'detail' => $e->getTraceAsString(), |
244 | - ) ); |
|
244 | + )); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | /** admin/jsonadm/standard/template-patch |
@@ -272,11 +272,11 @@ discard block |
||
272 | 272 | $tplconf = 'admin/jsonadm/standard/template-patch'; |
273 | 273 | $default = 'patch-default.php'; |
274 | 274 | |
275 | - $body = $view->render( $view->config( $tplconf, $default ) ); |
|
275 | + $body = $view->render($view->config($tplconf, $default)); |
|
276 | 276 | |
277 | - return $response->withHeader( 'Content-Type', 'application/vnd.api+json; supported-ext="bulk"' ) |
|
278 | - ->withBody( $view->response()->createStreamFromString( $body ) ) |
|
279 | - ->withStatus( $status ); |
|
277 | + return $response->withHeader('Content-Type', 'application/vnd.api+json; supported-ext="bulk"') |
|
278 | + ->withBody($view->response()->createStreamFromString($body)) |
|
279 | + ->withStatus($status); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | |
@@ -287,38 +287,38 @@ discard block |
||
287 | 287 | * @param \Psr\Http\Message\ResponseInterface $response Response object |
288 | 288 | * @return \Psr\Http\Message\ResponseInterface Modified response object |
289 | 289 | */ |
290 | - public function post( ServerRequestInterface $request, ResponseInterface $response ) |
|
290 | + public function post(ServerRequestInterface $request, ResponseInterface $response) |
|
291 | 291 | { |
292 | 292 | $view = $this->getView(); |
293 | 293 | |
294 | 294 | try |
295 | 295 | { |
296 | - $response = $this->postItems( $view, $request, $response ); |
|
296 | + $response = $this->postItems($view, $request, $response); |
|
297 | 297 | $status = 201; |
298 | 298 | } |
299 | - catch( \Aimeos\Admin\JsonAdm\Exception $e ) |
|
299 | + catch (\Aimeos\Admin\JsonAdm\Exception $e) |
|
300 | 300 | { |
301 | 301 | $status = $e->getCode(); |
302 | - $view->errors = array( array( |
|
303 | - 'title' => $this->getContext()->getI18n()->dt( 'admin/jsonadm', $e->getMessage() ), |
|
302 | + $view->errors = array(array( |
|
303 | + 'title' => $this->getContext()->getI18n()->dt('admin/jsonadm', $e->getMessage()), |
|
304 | 304 | 'detail' => $e->getTraceAsString(), |
305 | - ) ); |
|
305 | + )); |
|
306 | 306 | } |
307 | - catch( \Aimeos\MShop\Exception $e ) |
|
307 | + catch (\Aimeos\MShop\Exception $e) |
|
308 | 308 | { |
309 | 309 | $status = 404; |
310 | - $view->errors = array( array( |
|
311 | - 'title' => $this->getContext()->getI18n()->dt( 'mshop', $e->getMessage() ), |
|
310 | + $view->errors = array(array( |
|
311 | + 'title' => $this->getContext()->getI18n()->dt('mshop', $e->getMessage()), |
|
312 | 312 | 'detail' => $e->getTraceAsString(), |
313 | - ) ); |
|
313 | + )); |
|
314 | 314 | } |
315 | - catch( \Exception $e ) |
|
315 | + catch (\Exception $e) |
|
316 | 316 | { |
317 | 317 | $status = 500; |
318 | - $view->errors = array( array( |
|
318 | + $view->errors = array(array( |
|
319 | 319 | 'title' => $e->getMessage(), |
320 | 320 | 'detail' => $e->getTraceAsString(), |
321 | - ) ); |
|
321 | + )); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | /** admin/jsonadm/standard/template-post |
@@ -349,11 +349,11 @@ discard block |
||
349 | 349 | $tplconf = 'admin/jsonadm/standard/template-post'; |
350 | 350 | $default = 'post-default.php'; |
351 | 351 | |
352 | - $body = $view->render( $view->config( $tplconf, $default ) ); |
|
352 | + $body = $view->render($view->config($tplconf, $default)); |
|
353 | 353 | |
354 | - return $response->withHeader( 'Content-Type', 'application/vnd.api+json; supported-ext="bulk"' ) |
|
355 | - ->withBody( $view->response()->createStreamFromString( $body ) ) |
|
356 | - ->withStatus( $status ); |
|
354 | + return $response->withHeader('Content-Type', 'application/vnd.api+json; supported-ext="bulk"') |
|
355 | + ->withBody($view->response()->createStreamFromString($body)) |
|
356 | + ->withStatus($status); |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | |
@@ -364,14 +364,14 @@ discard block |
||
364 | 364 | * @param \Psr\Http\Message\ResponseInterface $response Response object |
365 | 365 | * @return \Psr\Http\Message\ResponseInterface Modified response object |
366 | 366 | */ |
367 | - public function put( ServerRequestInterface $request, ResponseInterface $response ) |
|
367 | + public function put(ServerRequestInterface $request, ResponseInterface $response) |
|
368 | 368 | { |
369 | 369 | $status = 501; |
370 | 370 | $view = $this->getView(); |
371 | 371 | |
372 | - $view->errors = array( array( |
|
373 | - 'title' => $this->getContext()->getI18n()->dt( 'admin/jsonadm', 'Not implemented, use PATCH instead' ), |
|
374 | - ) ); |
|
372 | + $view->errors = array(array( |
|
373 | + 'title' => $this->getContext()->getI18n()->dt('admin/jsonadm', 'Not implemented, use PATCH instead'), |
|
374 | + )); |
|
375 | 375 | |
376 | 376 | /** admin/jsonadm/standard/template-put |
377 | 377 | * Relative path to the JSON API template for PUT requests |
@@ -401,11 +401,11 @@ discard block |
||
401 | 401 | $tplconf = 'admin/jsonadm/standard/template-put'; |
402 | 402 | $default = 'put-default.php'; |
403 | 403 | |
404 | - $body = $view->render( $view->config( $tplconf, $default ) ); |
|
404 | + $body = $view->render($view->config($tplconf, $default)); |
|
405 | 405 | |
406 | - return $response->withHeader( 'Content-Type', 'application/vnd.api+json; supported-ext="bulk"' ) |
|
407 | - ->withBody( $view->response()->createStreamFromString( $body ) ) |
|
408 | - ->withStatus( $status ); |
|
406 | + return $response->withHeader('Content-Type', 'application/vnd.api+json; supported-ext="bulk"') |
|
407 | + ->withBody($view->response()->createStreamFromString($body)) |
|
408 | + ->withStatus($status); |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | |
@@ -417,7 +417,7 @@ discard block |
||
417 | 417 | * @param string|null Form parameter prefix when nesting parameters is required |
418 | 418 | * @return \Psr\Http\Message\ResponseInterface Modified response object |
419 | 419 | */ |
420 | - public function options( ServerRequestInterface $request, ResponseInterface $response, $prefix = null ) |
|
420 | + public function options(ServerRequestInterface $request, ResponseInterface $response, $prefix = null) |
|
421 | 421 | { |
422 | 422 | $context = $this->getContext(); |
423 | 423 | $view = $this->getView(); |
@@ -426,11 +426,11 @@ discard block |
||
426 | 426 | { |
427 | 427 | $resources = $attributes = array(); |
428 | 428 | |
429 | - foreach( $this->getDomains( $view ) as $domain ) |
|
429 | + foreach ($this->getDomains($view) as $domain) |
|
430 | 430 | { |
431 | - $manager = \Aimeos\MShop\Factory::createManager( $context, $domain ); |
|
432 | - $resources = array_merge( $resources, $manager->getResourceType( true ) ); |
|
433 | - $attributes = array_merge( $attributes, $manager->getSearchAttributes( true ) ); |
|
431 | + $manager = \Aimeos\MShop\Factory::createManager($context, $domain); |
|
432 | + $resources = array_merge($resources, $manager->getResourceType(true)); |
|
433 | + $attributes = array_merge($attributes, $manager->getSearchAttributes(true)); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | $view->prefix = $prefix; |
@@ -439,21 +439,21 @@ discard block |
||
439 | 439 | |
440 | 440 | $status = 200; |
441 | 441 | } |
442 | - catch( \Aimeos\MShop\Exception $e ) |
|
442 | + catch (\Aimeos\MShop\Exception $e) |
|
443 | 443 | { |
444 | 444 | $status = 404; |
445 | - $view->errors = array( array( |
|
446 | - 'title' => $context->getI18n()->dt( 'mshop', $e->getMessage() ), |
|
445 | + $view->errors = array(array( |
|
446 | + 'title' => $context->getI18n()->dt('mshop', $e->getMessage()), |
|
447 | 447 | 'detail' => $e->getTraceAsString(), |
448 | - ) ); |
|
448 | + )); |
|
449 | 449 | } |
450 | - catch( \Exception $e ) |
|
450 | + catch (\Exception $e) |
|
451 | 451 | { |
452 | 452 | $status = 500; |
453 | - $view->errors = array( array( |
|
453 | + $view->errors = array(array( |
|
454 | 454 | 'title' => $e->getMessage(), |
455 | 455 | 'detail' => $e->getTraceAsString(), |
456 | - ) ); |
|
456 | + )); |
|
457 | 457 | } |
458 | 458 | |
459 | 459 | /** admin/jsonadm/standard/template-options |
@@ -484,12 +484,12 @@ discard block |
||
484 | 484 | $tplconf = 'admin/jsonadm/standard/template-options'; |
485 | 485 | $default = 'options-default.php'; |
486 | 486 | |
487 | - $body = $view->render( $view->config( $tplconf, $default ) ); |
|
487 | + $body = $view->render($view->config($tplconf, $default)); |
|
488 | 488 | |
489 | - return $response->withHeader( 'Allow', 'DELETE,GET,PATCH,POST,OPTIONS' ) |
|
490 | - ->withHeader( 'Content-Type', 'application/vnd.api+json; supported-ext="bulk"' ) |
|
491 | - ->withBody( $view->response()->createStreamFromString( $body ) ) |
|
492 | - ->withStatus( $status ); |
|
489 | + return $response->withHeader('Allow', 'DELETE,GET,PATCH,POST,OPTIONS') |
|
490 | + ->withHeader('Content-Type', 'application/vnd.api+json; supported-ext="bulk"') |
|
491 | + ->withBody($view->response()->createStreamFromString($body)) |
|
492 | + ->withStatus($status); |
|
493 | 493 | } |
494 | 494 | |
495 | 495 | |
@@ -502,25 +502,25 @@ discard block |
||
502 | 502 | * @return \Psr\Http\Message\ResponseInterface Modified response object |
503 | 503 | * @throws \Aimeos\Admin\JsonAdm\Exception If the request body is invalid |
504 | 504 | */ |
505 | - protected function deleteItems( \Aimeos\MW\View\Iface $view, ServerRequestInterface $request, ResponseInterface $response ) |
|
505 | + protected function deleteItems(\Aimeos\MW\View\Iface $view, ServerRequestInterface $request, ResponseInterface $response) |
|
506 | 506 | { |
507 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), $this->getPath() ); |
|
507 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), $this->getPath()); |
|
508 | 508 | |
509 | - if( ( $id = $view->param( 'id' ) ) == null ) |
|
509 | + if (($id = $view->param('id')) == null) |
|
510 | 510 | { |
511 | 511 | $body = (string) $request->getBody(); |
512 | 512 | |
513 | - if( ( $payload = json_decode( $body ) ) === null || !isset( $payload->data ) || !is_array( $payload->data ) ) { |
|
514 | - throw new \Aimeos\Admin\JsonAdm\Exception( sprintf( 'Invalid JSON in body' ), 400 ); |
|
513 | + if (($payload = json_decode($body)) === null || !isset($payload->data) || !is_array($payload->data)) { |
|
514 | + throw new \Aimeos\Admin\JsonAdm\Exception(sprintf('Invalid JSON in body'), 400); |
|
515 | 515 | } |
516 | 516 | |
517 | - $ids = $this->getIds( $payload ); |
|
518 | - $manager->deleteItems( $ids ); |
|
519 | - $view->total = count( $ids ); |
|
517 | + $ids = $this->getIds($payload); |
|
518 | + $manager->deleteItems($ids); |
|
519 | + $view->total = count($ids); |
|
520 | 520 | } |
521 | 521 | else |
522 | 522 | { |
523 | - $manager->deleteItem( $id ); |
|
523 | + $manager->deleteItem($id); |
|
524 | 524 | $view->total = 1; |
525 | 525 | } |
526 | 526 | |
@@ -536,35 +536,35 @@ discard block |
||
536 | 536 | * @param \Psr\Http\Message\ResponseInterface $response Response object |
537 | 537 | * @return \Psr\Http\Message\ResponseInterface Modified response object |
538 | 538 | */ |
539 | - protected function getItems( \Aimeos\MW\View\Iface $view, ServerRequestInterface $request, ResponseInterface $response ) |
|
539 | + protected function getItems(\Aimeos\MW\View\Iface $view, ServerRequestInterface $request, ResponseInterface $response) |
|
540 | 540 | { |
541 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), $this->getPath() ); |
|
541 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), $this->getPath()); |
|
542 | 542 | |
543 | - if( ( $key = $view->param( 'aggregate' ) ) !== null ) |
|
543 | + if (($key = $view->param('aggregate')) !== null) |
|
544 | 544 | { |
545 | - $search = $this->initCriteria( $manager->createSearch(), $view->param() ); |
|
546 | - $view->data = $manager->aggregate( $search, $key ); |
|
545 | + $search = $this->initCriteria($manager->createSearch(), $view->param()); |
|
546 | + $view->data = $manager->aggregate($search, $key); |
|
547 | 547 | return $response; |
548 | 548 | } |
549 | 549 | |
550 | 550 | $total = 1; |
551 | - $include = ( ( $include = $view->param( 'include' ) ) !== null ? explode( ',', $include ) : array() ); |
|
551 | + $include = (($include = $view->param('include')) !== null ? explode(',', $include) : array()); |
|
552 | 552 | |
553 | - if( ( $id = $view->param( 'id' ) ) == null ) |
|
553 | + if (($id = $view->param('id')) == null) |
|
554 | 554 | { |
555 | - $search = $this->initCriteria( $manager->createSearch(), $view->param() ); |
|
556 | - $view->data = $manager->searchItems( $search, array(), $total ); |
|
557 | - $view->childItems = $this->getChildItems( $view->data, $include ); |
|
558 | - $view->listItems = $this->getListItems( $view->data, $include ); |
|
555 | + $search = $this->initCriteria($manager->createSearch(), $view->param()); |
|
556 | + $view->data = $manager->searchItems($search, array(), $total); |
|
557 | + $view->childItems = $this->getChildItems($view->data, $include); |
|
558 | + $view->listItems = $this->getListItems($view->data, $include); |
|
559 | 559 | } |
560 | 560 | else |
561 | 561 | { |
562 | - $view->data = $manager->getItem( $id, array() ); |
|
563 | - $view->childItems = $this->getChildItems( array( $id => $view->data ), $include ); |
|
564 | - $view->listItems = $this->getListItems( array( $id => $view->data ), $include ); |
|
562 | + $view->data = $manager->getItem($id, array()); |
|
563 | + $view->childItems = $this->getChildItems(array($id => $view->data), $include); |
|
564 | + $view->listItems = $this->getListItems(array($id => $view->data), $include); |
|
565 | 565 | } |
566 | 566 | |
567 | - $view->refItems = $this->getRefItems( $view->listItems ); |
|
567 | + $view->refItems = $this->getRefItems($view->listItems); |
|
568 | 568 | $view->total = $total; |
569 | 569 | |
570 | 570 | return $response; |
@@ -580,35 +580,35 @@ discard block |
||
580 | 580 | * @return \Psr\Http\Message\ResponseInterface Modified response object |
581 | 581 | * @throws \Aimeos\Admin\JsonAdm\Exception If "id" parameter isn't available or the body is invalid |
582 | 582 | */ |
583 | - protected function patchItems( \Aimeos\MW\View\Iface $view, ServerRequestInterface $request, ResponseInterface $response ) |
|
583 | + protected function patchItems(\Aimeos\MW\View\Iface $view, ServerRequestInterface $request, ResponseInterface $response) |
|
584 | 584 | { |
585 | 585 | $body = (string) $request->getBody(); |
586 | 586 | |
587 | - if( ( $payload = json_decode( $body ) ) === null || !isset( $payload->data ) ) { |
|
588 | - throw new \Aimeos\Admin\JsonAdm\Exception( sprintf( 'Invalid JSON in body' ), 400 ); |
|
587 | + if (($payload = json_decode($body)) === null || !isset($payload->data)) { |
|
588 | + throw new \Aimeos\Admin\JsonAdm\Exception(sprintf('Invalid JSON in body'), 400); |
|
589 | 589 | } |
590 | 590 | |
591 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), $this->getPath() ); |
|
591 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), $this->getPath()); |
|
592 | 592 | |
593 | - if( is_array( $payload->data ) ) |
|
593 | + if (is_array($payload->data)) |
|
594 | 594 | { |
595 | - $data = $this->saveData( $manager, $payload ); |
|
595 | + $data = $this->saveData($manager, $payload); |
|
596 | 596 | |
597 | 597 | $view->data = $data; |
598 | - $view->total = count( $data ); |
|
599 | - $response = $response->withHeader( 'Content-Type', 'application/vnd.api+json; ext="bulk"; supported-ext="bulk"' ); |
|
598 | + $view->total = count($data); |
|
599 | + $response = $response->withHeader('Content-Type', 'application/vnd.api+json; ext="bulk"; supported-ext="bulk"'); |
|
600 | 600 | } |
601 | - elseif( ( $id = $view->param( 'id' ) ) != null ) |
|
601 | + elseif (($id = $view->param('id')) != null) |
|
602 | 602 | { |
603 | 603 | $payload->data->id = $id; |
604 | - $data = $this->saveEntry( $manager, $payload->data ); |
|
604 | + $data = $this->saveEntry($manager, $payload->data); |
|
605 | 605 | |
606 | 606 | $view->data = $data; |
607 | 607 | $view->total = 1; |
608 | 608 | } |
609 | 609 | else |
610 | 610 | { |
611 | - throw new \Aimeos\Admin\JsonAdm\Exception( sprintf( 'No ID given' ), 400 ); |
|
611 | + throw new \Aimeos\Admin\JsonAdm\Exception(sprintf('No ID given'), 400); |
|
612 | 612 | } |
613 | 613 | |
614 | 614 | return $response; |
@@ -623,33 +623,33 @@ discard block |
||
623 | 623 | * @param \Psr\Http\Message\ResponseInterface $response Response object |
624 | 624 | * @return \Psr\Http\Message\ResponseInterface Modified response object |
625 | 625 | */ |
626 | - protected function postItems( \Aimeos\MW\View\Iface $view, ServerRequestInterface $request, ResponseInterface $response ) |
|
626 | + protected function postItems(\Aimeos\MW\View\Iface $view, ServerRequestInterface $request, ResponseInterface $response) |
|
627 | 627 | { |
628 | 628 | $body = (string) $request->getBody(); |
629 | 629 | |
630 | - if( ( $payload = json_decode( $body ) ) === null || !isset( $payload->data ) ) { |
|
631 | - throw new \Aimeos\Admin\JsonAdm\Exception( sprintf( 'Invalid JSON in body' ), 400 ); |
|
630 | + if (($payload = json_decode($body)) === null || !isset($payload->data)) { |
|
631 | + throw new \Aimeos\Admin\JsonAdm\Exception(sprintf('Invalid JSON in body'), 400); |
|
632 | 632 | } |
633 | 633 | |
634 | - if( isset( $payload->data->id ) || $view->param( 'id' ) != null ) { |
|
635 | - throw new \Aimeos\Admin\JsonAdm\Exception( sprintf( 'Client generated IDs are not supported' ), 403 ); |
|
634 | + if (isset($payload->data->id) || $view->param('id') != null) { |
|
635 | + throw new \Aimeos\Admin\JsonAdm\Exception(sprintf('Client generated IDs are not supported'), 403); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | |
639 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), $this->getPath() ); |
|
639 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), $this->getPath()); |
|
640 | 640 | |
641 | - if( is_array( $payload->data ) ) |
|
641 | + if (is_array($payload->data)) |
|
642 | 642 | { |
643 | - $data = $this->saveData( $manager, $payload ); |
|
643 | + $data = $this->saveData($manager, $payload); |
|
644 | 644 | |
645 | 645 | $view->data = $data; |
646 | - $view->total = count( $data ); |
|
647 | - $response = $response->withHeader( 'Content-Type', 'application/vnd.api+json; ext="bulk"; supported-ext="bulk"' ); |
|
646 | + $view->total = count($data); |
|
647 | + $response = $response->withHeader('Content-Type', 'application/vnd.api+json; ext="bulk"; supported-ext="bulk"'); |
|
648 | 648 | } |
649 | 649 | else |
650 | 650 | { |
651 | 651 | $payload->data->id = null; |
652 | - $data = $this->saveEntry( $manager, $payload->data ); |
|
652 | + $data = $this->saveEntry($manager, $payload->data); |
|
653 | 653 | |
654 | 654 | $view->data = $data; |
655 | 655 | $view->total = 1; |
@@ -1,30 +1,30 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -$target = $this->config( 'admin/jsonadm/url/target' ); |
|
4 | -$cntl = $this->config( 'admin/jsonadm/url/controller', 'jsonadm' ); |
|
5 | -$action = $this->config( 'admin/jsonadm/url/action', 'get' ); |
|
6 | -$config = $this->config( 'admin/jsonadm/url/config', array() ); |
|
3 | +$target = $this->config('admin/jsonadm/url/target'); |
|
4 | +$cntl = $this->config('admin/jsonadm/url/controller', 'jsonadm'); |
|
5 | +$action = $this->config('admin/jsonadm/url/action', 'get'); |
|
6 | +$config = $this->config('admin/jsonadm/url/config', array()); |
|
7 | 7 | |
8 | 8 | $resources = $attributes = array(); |
9 | -$site = $this->param( 'site', 'default' ); |
|
9 | +$site = $this->param('site', 'default'); |
|
10 | 10 | |
11 | -foreach( $this->get( 'resources', array() ) as $resource ) { |
|
12 | - $resources[$resource] = $this->url( $target, $cntl, $action, array( 'site' => $site, 'resource' => $resource, 'id' => '' ), array(), $config ); |
|
11 | +foreach ($this->get('resources', array()) as $resource) { |
|
12 | + $resources[$resource] = $this->url($target, $cntl, $action, array('site' => $site, 'resource' => $resource, 'id' => ''), array(), $config); |
|
13 | 13 | } |
14 | 14 | |
15 | -foreach( $this->get( 'attributes', array() ) as $attr ) { |
|
15 | +foreach ($this->get('attributes', array()) as $attr) { |
|
16 | 16 | $attributes[$attr->getCode()] = $attr->toArray(); |
17 | 17 | } |
18 | 18 | |
19 | 19 | ?> |
20 | 20 | { |
21 | 21 | "meta": { |
22 | - "prefix": <?php echo json_encode( $this->get( 'prefix' ) ); ?>, |
|
23 | - "resources": <?php echo json_encode( $resources ); ?>, |
|
24 | - "attributes": <?php echo json_encode( $attributes ); ?> |
|
22 | + "prefix": <?php echo json_encode($this->get('prefix')); ?>, |
|
23 | + "resources": <?php echo json_encode($resources); ?>, |
|
24 | + "attributes": <?php echo json_encode($attributes); ?> |
|
25 | 25 | } |
26 | -<?php if( isset( $this->errors ) ) : ?> |
|
27 | - ,"errors": <?php echo $this->partial( $this->config( 'admin/jsonadm/partials/template-errors', 'partials/errors-standard.php' ), array( 'errors' => $this->errors ) ); ?> |
|
26 | +<?php if (isset($this->errors)) : ?> |
|
27 | + ,"errors": <?php echo $this->partial($this->config('admin/jsonadm/partials/template-errors', 'partials/errors-standard.php'), array('errors' => $this->errors)); ?> |
|
28 | 28 | <?php endif; ?> |
29 | 29 | |
30 | 30 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | $templatePaths = \TestHelperJadm::getJsonadmPaths(); |
23 | 23 | $this->view = $this->context->getView(); |
24 | 24 | |
25 | - $this->object = new \Aimeos\Admin\JsonAdm\Standard( $this->context, $this->view, $templatePaths, 'product' ); |
|
25 | + $this->object = new \Aimeos\Admin\JsonAdm\Standard($this->context, $this->view, $templatePaths, 'product'); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | |
@@ -34,193 +34,193 @@ discard block |
||
34 | 34 | |
35 | 35 | public function testDelete() |
36 | 36 | { |
37 | - $this->getProductMock( array( 'deleteItem' ) )->expects( $this->once() )->method( 'deleteItem' ); |
|
37 | + $this->getProductMock(array('deleteItem'))->expects($this->once())->method('deleteItem'); |
|
38 | 38 | |
39 | - $params = array( 'id' => $this->getProductItem()->getId() ); |
|
40 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
41 | - $this->view->addHelper( 'param', $helper ); |
|
39 | + $params = array('id' => $this->getProductItem()->getId()); |
|
40 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
41 | + $this->view->addHelper('param', $helper); |
|
42 | 42 | |
43 | - $response = $this->object->delete( $this->view->request(), $this->view->response() ); |
|
44 | - $result = json_decode( (string) $response->getBody(), true ); |
|
43 | + $response = $this->object->delete($this->view->request(), $this->view->response()); |
|
44 | + $result = json_decode((string) $response->getBody(), true); |
|
45 | 45 | |
46 | 46 | |
47 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
48 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
47 | + $this->assertEquals(200, $response->getStatusCode()); |
|
48 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
49 | 49 | |
50 | - $this->assertEquals( 1, $result['meta']['total'] ); |
|
50 | + $this->assertEquals(1, $result['meta']['total']); |
|
51 | 51 | |
52 | - $this->assertArrayNotHasKey( 'included', $result ); |
|
53 | - $this->assertArrayNotHasKey( 'data', $result ); |
|
54 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
52 | + $this->assertArrayNotHasKey('included', $result); |
|
53 | + $this->assertArrayNotHasKey('data', $result); |
|
54 | + $this->assertArrayNotHasKey('errors', $result); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | |
58 | 58 | public function testDeleteBulk() |
59 | 59 | { |
60 | - $this->getProductMock( array( 'deleteItems' ) )->expects( $this->once() )->method( 'deleteItems' ); |
|
60 | + $this->getProductMock(array('deleteItems'))->expects($this->once())->method('deleteItems'); |
|
61 | 61 | |
62 | 62 | $body = '{"data":[{"type": "product", "id": "-1"},{"type": "product", "id": "-2"}]}'; |
63 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
63 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
64 | 64 | |
65 | - $response = $this->object->delete( $request, $this->view->response() ); |
|
66 | - $result = json_decode( (string) $response->getBody(), true ); |
|
65 | + $response = $this->object->delete($request, $this->view->response()); |
|
66 | + $result = json_decode((string) $response->getBody(), true); |
|
67 | 67 | |
68 | 68 | |
69 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
70 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
69 | + $this->assertEquals(200, $response->getStatusCode()); |
|
70 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
71 | 71 | |
72 | - $this->assertEquals( 2, $result['meta']['total'] ); |
|
73 | - $this->assertArrayNotHasKey( 'included', $result ); |
|
74 | - $this->assertArrayNotHasKey( 'data', $result ); |
|
75 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
72 | + $this->assertEquals(2, $result['meta']['total']); |
|
73 | + $this->assertArrayNotHasKey('included', $result); |
|
74 | + $this->assertArrayNotHasKey('data', $result); |
|
75 | + $this->assertArrayNotHasKey('errors', $result); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | |
79 | 79 | public function testDeleteInvalid() |
80 | 80 | { |
81 | 81 | $body = '{"data":null}'; |
82 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
82 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
83 | 83 | |
84 | - $response = $this->object->delete( $request, $this->view->response() ); |
|
85 | - $result = json_decode( (string) $response->getBody(), true ); |
|
84 | + $response = $this->object->delete($request, $this->view->response()); |
|
85 | + $result = json_decode((string) $response->getBody(), true); |
|
86 | 86 | |
87 | 87 | |
88 | - $this->assertEquals( 400, $response->getStatusCode() ); |
|
89 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
88 | + $this->assertEquals(400, $response->getStatusCode()); |
|
89 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
90 | 90 | |
91 | - $this->assertEquals( 0, $result['meta']['total'] ); |
|
92 | - $this->assertArrayHasKey( 'errors', $result ); |
|
93 | - $this->assertArrayNotHasKey( 'included', $result ); |
|
94 | - $this->assertArrayNotHasKey( 'data', $result ); |
|
91 | + $this->assertEquals(0, $result['meta']['total']); |
|
92 | + $this->assertArrayHasKey('errors', $result); |
|
93 | + $this->assertArrayNotHasKey('included', $result); |
|
94 | + $this->assertArrayNotHasKey('data', $result); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | |
98 | 98 | public function testDeleteException() |
99 | 99 | { |
100 | - $this->getProductMock( array( 'deleteItem' ) )->expects( $this->once() )->method( 'deleteItem' ) |
|
101 | - ->will( $this->throwException( new \RuntimeException( 'test exception' ) ) ); |
|
100 | + $this->getProductMock(array('deleteItem'))->expects($this->once())->method('deleteItem') |
|
101 | + ->will($this->throwException(new \RuntimeException('test exception'))); |
|
102 | 102 | |
103 | - $params = array( 'id' => $this->getProductItem()->getId() ); |
|
104 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
105 | - $this->view->addHelper( 'param', $helper ); |
|
103 | + $params = array('id' => $this->getProductItem()->getId()); |
|
104 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
105 | + $this->view->addHelper('param', $helper); |
|
106 | 106 | |
107 | - $response = $this->object->delete( $this->view->request(), $this->view->response() ); |
|
108 | - $result = json_decode( (string) $response->getBody(), true ); |
|
107 | + $response = $this->object->delete($this->view->request(), $this->view->response()); |
|
108 | + $result = json_decode((string) $response->getBody(), true); |
|
109 | 109 | |
110 | - $this->assertEquals( 500, $response->getStatusCode() ); |
|
111 | - $this->assertArrayHasKey( 'errors', $result ); |
|
110 | + $this->assertEquals(500, $response->getStatusCode()); |
|
111 | + $this->assertArrayHasKey('errors', $result); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | |
115 | 115 | public function testDeleteMShopException() |
116 | 116 | { |
117 | - $this->getProductMock( array( 'deleteItem' ) )->expects( $this->once() )->method( 'deleteItem' ) |
|
118 | - ->will( $this->throwException( new \Aimeos\MShop\Exception( 'test exception' ) ) ); |
|
117 | + $this->getProductMock(array('deleteItem'))->expects($this->once())->method('deleteItem') |
|
118 | + ->will($this->throwException(new \Aimeos\MShop\Exception('test exception'))); |
|
119 | 119 | |
120 | - $params = array( 'id' => $this->getProductItem()->getId() ); |
|
121 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
122 | - $this->view->addHelper( 'param', $helper ); |
|
120 | + $params = array('id' => $this->getProductItem()->getId()); |
|
121 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
122 | + $this->view->addHelper('param', $helper); |
|
123 | 123 | |
124 | - $response = $this->object->delete( $this->view->request(), $this->view->response() ); |
|
125 | - $result = json_decode( (string) $response->getBody(), true ); |
|
124 | + $response = $this->object->delete($this->view->request(), $this->view->response()); |
|
125 | + $result = json_decode((string) $response->getBody(), true); |
|
126 | 126 | |
127 | - $this->assertEquals( 404, $response->getStatusCode() ); |
|
128 | - $this->assertArrayHasKey( 'errors', $result ); |
|
127 | + $this->assertEquals(404, $response->getStatusCode()); |
|
128 | + $this->assertArrayHasKey('errors', $result); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | |
132 | 132 | public function testGet() |
133 | 133 | { |
134 | - $response = $this->object->get( $this->view->request(), $this->view->response() ); |
|
135 | - $result = json_decode( (string) $response->getBody(), true ); |
|
134 | + $response = $this->object->get($this->view->request(), $this->view->response()); |
|
135 | + $result = json_decode((string) $response->getBody(), true); |
|
136 | 136 | |
137 | 137 | |
138 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
139 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
138 | + $this->assertEquals(200, $response->getStatusCode()); |
|
139 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
140 | 140 | |
141 | - $this->assertEquals( 28, $result['meta']['total'] ); |
|
142 | - $this->assertEquals( 25, count( $result['data'] ) ); |
|
143 | - $this->assertEquals( 'product', $result['data'][0]['type'] ); |
|
144 | - $this->assertEquals( 0, count( $result['included'] ) ); |
|
145 | - $this->assertArrayHasKey( 'next', $result['links'] ); |
|
146 | - $this->assertArrayHasKey( 'last', $result['links'] ); |
|
147 | - $this->assertArrayHasKey( 'self', $result['links'] ); |
|
148 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
141 | + $this->assertEquals(28, $result['meta']['total']); |
|
142 | + $this->assertEquals(25, count($result['data'])); |
|
143 | + $this->assertEquals('product', $result['data'][0]['type']); |
|
144 | + $this->assertEquals(0, count($result['included'])); |
|
145 | + $this->assertArrayHasKey('next', $result['links']); |
|
146 | + $this->assertArrayHasKey('last', $result['links']); |
|
147 | + $this->assertArrayHasKey('self', $result['links']); |
|
148 | + $this->assertArrayNotHasKey('errors', $result); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | |
152 | 152 | public function testGetType() |
153 | 153 | { |
154 | 154 | $templatePaths = \TestHelperJadm::getJsonadmPaths(); |
155 | - $object = new \Aimeos\Admin\JsonAdm\Standard( $this->context, $this->view, $templatePaths, 'product/property/type' ); |
|
155 | + $object = new \Aimeos\Admin\JsonAdm\Standard($this->context, $this->view, $templatePaths, 'product/property/type'); |
|
156 | 156 | |
157 | - $response = $object->get( $this->view->request(), $this->view->response() ); |
|
158 | - $result = json_decode( (string) $response->getBody(), true ); |
|
157 | + $response = $object->get($this->view->request(), $this->view->response()); |
|
158 | + $result = json_decode((string) $response->getBody(), true); |
|
159 | 159 | |
160 | 160 | |
161 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
162 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
161 | + $this->assertEquals(200, $response->getStatusCode()); |
|
162 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
163 | 163 | |
164 | - $this->assertEquals( 4, $result['meta']['total'] ); |
|
165 | - $this->assertEquals( 4, count( $result['data'] ) ); |
|
166 | - $this->assertEquals( 'product/property/type', $result['data'][0]['type'] ); |
|
167 | - $this->assertEquals( 0, count( $result['included'] ) ); |
|
164 | + $this->assertEquals(4, $result['meta']['total']); |
|
165 | + $this->assertEquals(4, count($result['data'])); |
|
166 | + $this->assertEquals('product/property/type', $result['data'][0]['type']); |
|
167 | + $this->assertEquals(0, count($result['included'])); |
|
168 | 168 | |
169 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
169 | + $this->assertArrayNotHasKey('errors', $result); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | |
173 | 173 | public function testGetInvalid() |
174 | 174 | { |
175 | 175 | $templatePaths = \TestHelperJadm::getJsonadmPaths(); |
176 | - $object = new \Aimeos\Admin\JsonAdm\Standard( $this->context, $this->view, $templatePaths, 'invalid' ); |
|
176 | + $object = new \Aimeos\Admin\JsonAdm\Standard($this->context, $this->view, $templatePaths, 'invalid'); |
|
177 | 177 | |
178 | - $response = $object->get( $this->view->request(), $this->view->response() ); |
|
179 | - $result = json_decode( (string) $response->getBody(), true ); |
|
178 | + $response = $object->get($this->view->request(), $this->view->response()); |
|
179 | + $result = json_decode((string) $response->getBody(), true); |
|
180 | 180 | |
181 | 181 | |
182 | - $this->assertEquals( 404, $response->getStatusCode() ); |
|
183 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
182 | + $this->assertEquals(404, $response->getStatusCode()); |
|
183 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
184 | 184 | |
185 | - $this->assertEquals( 1, count( $result['errors'] ) ); |
|
186 | - $this->assertArrayHasKey( 'title', $result['errors'][0] ); |
|
187 | - $this->assertArrayHasKey( 'detail', $result['errors'][0] ); |
|
188 | - $this->assertArrayNotHasKey( 'data', $result ); |
|
189 | - $this->assertArrayNotHasKey( 'indluded', $result ); |
|
185 | + $this->assertEquals(1, count($result['errors'])); |
|
186 | + $this->assertArrayHasKey('title', $result['errors'][0]); |
|
187 | + $this->assertArrayHasKey('detail', $result['errors'][0]); |
|
188 | + $this->assertArrayNotHasKey('data', $result); |
|
189 | + $this->assertArrayNotHasKey('indluded', $result); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | |
193 | 193 | public function testGetException() |
194 | 194 | { |
195 | - $this->getProductMock( array( 'getItem' ) )->expects( $this->once() )->method( 'getItem' ) |
|
196 | - ->will( $this->throwException( new \RuntimeException( 'test exception' ) ) ); |
|
195 | + $this->getProductMock(array('getItem'))->expects($this->once())->method('getItem') |
|
196 | + ->will($this->throwException(new \RuntimeException('test exception'))); |
|
197 | 197 | |
198 | - $params = array( 'id' => -1 ); |
|
199 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
200 | - $this->view->addHelper( 'param', $helper ); |
|
198 | + $params = array('id' => -1); |
|
199 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
200 | + $this->view->addHelper('param', $helper); |
|
201 | 201 | |
202 | - $response = $this->object->get( $this->view->request(), $this->view->response() ); |
|
203 | - $result = json_decode( (string) $response->getBody(), true ); |
|
202 | + $response = $this->object->get($this->view->request(), $this->view->response()); |
|
203 | + $result = json_decode((string) $response->getBody(), true); |
|
204 | 204 | |
205 | - $this->assertEquals( 500, $response->getStatusCode() ); |
|
206 | - $this->assertArrayHasKey( 'errors', $result ); |
|
205 | + $this->assertEquals(500, $response->getStatusCode()); |
|
206 | + $this->assertArrayHasKey('errors', $result); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | |
210 | 210 | public function testGetMShopException() |
211 | 211 | { |
212 | - $this->getProductMock( array( 'getItem' ) )->expects( $this->once() )->method( 'getItem' ) |
|
213 | - ->will( $this->throwException( new \Aimeos\MShop\Exception( 'test exception' ) ) ); |
|
212 | + $this->getProductMock(array('getItem'))->expects($this->once())->method('getItem') |
|
213 | + ->will($this->throwException(new \Aimeos\MShop\Exception('test exception'))); |
|
214 | 214 | |
215 | - $params = array( 'id' => -1 ); |
|
216 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
217 | - $this->view->addHelper( 'param', $helper ); |
|
215 | + $params = array('id' => -1); |
|
216 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
217 | + $this->view->addHelper('param', $helper); |
|
218 | 218 | |
219 | - $response = $this->object->get( $this->view->request(), $this->view->response() ); |
|
220 | - $result = json_decode( (string) $response->getBody(), true ); |
|
219 | + $response = $this->object->get($this->view->request(), $this->view->response()); |
|
220 | + $result = json_decode((string) $response->getBody(), true); |
|
221 | 221 | |
222 | - $this->assertEquals( 404, $response->getStatusCode() ); |
|
223 | - $this->assertArrayHasKey( 'errors', $result ); |
|
222 | + $this->assertEquals(404, $response->getStatusCode()); |
|
223 | + $this->assertArrayHasKey('errors', $result); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | |
@@ -228,25 +228,25 @@ discard block |
||
228 | 228 | { |
229 | 229 | $params = array( |
230 | 230 | 'filter' => array( |
231 | - '==' => array( 'product.type.code' => 'select' ) |
|
231 | + '==' => array('product.type.code' => 'select') |
|
232 | 232 | ) |
233 | 233 | ); |
234 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
235 | - $this->view->addHelper( 'param', $helper ); |
|
234 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
235 | + $this->view->addHelper('param', $helper); |
|
236 | 236 | |
237 | - $response = $this->object->get( $this->view->request(), $this->view->response() ); |
|
238 | - $result = json_decode( (string) $response->getBody(), true ); |
|
237 | + $response = $this->object->get($this->view->request(), $this->view->response()); |
|
238 | + $result = json_decode((string) $response->getBody(), true); |
|
239 | 239 | |
240 | 240 | |
241 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
242 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
241 | + $this->assertEquals(200, $response->getStatusCode()); |
|
242 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
243 | 243 | |
244 | - $this->assertEquals( 3, $result['meta']['total'] ); |
|
245 | - $this->assertEquals( 3, count( $result['data'] ) ); |
|
246 | - $this->assertEquals( 'product', $result['data'][0]['type'] ); |
|
247 | - $this->assertEquals( 0, count( $result['included'] ) ); |
|
244 | + $this->assertEquals(3, $result['meta']['total']); |
|
245 | + $this->assertEquals(3, count($result['data'])); |
|
246 | + $this->assertEquals('product', $result['data'][0]['type']); |
|
247 | + $this->assertEquals(0, count($result['included'])); |
|
248 | 248 | |
249 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
249 | + $this->assertArrayNotHasKey('errors', $result); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | |
@@ -255,27 +255,27 @@ discard block |
||
255 | 255 | $params = array( |
256 | 256 | 'filter' => array( |
257 | 257 | '&&' => array( |
258 | - array( '=~' => array( 'product.label' => 'Unittest: Test' ) ), |
|
259 | - array( '==' => array( 'product.type.code' => 'select' ) ), |
|
258 | + array('=~' => array('product.label' => 'Unittest: Test')), |
|
259 | + array('==' => array('product.type.code' => 'select')), |
|
260 | 260 | ) |
261 | 261 | ) |
262 | 262 | ); |
263 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
264 | - $this->view->addHelper( 'param', $helper ); |
|
263 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
264 | + $this->view->addHelper('param', $helper); |
|
265 | 265 | |
266 | - $response = $this->object->get( $this->view->request(), $this->view->response() ); |
|
267 | - $result = json_decode( (string) $response->getBody(), true ); |
|
266 | + $response = $this->object->get($this->view->request(), $this->view->response()); |
|
267 | + $result = json_decode((string) $response->getBody(), true); |
|
268 | 268 | |
269 | 269 | |
270 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
271 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
270 | + $this->assertEquals(200, $response->getStatusCode()); |
|
271 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
272 | 272 | |
273 | - $this->assertEquals( 2, $result['meta']['total'] ); |
|
274 | - $this->assertEquals( 2, count( $result['data'] ) ); |
|
275 | - $this->assertEquals( 'product', $result['data'][0]['type'] ); |
|
276 | - $this->assertEquals( 0, count( $result['included'] ) ); |
|
273 | + $this->assertEquals(2, $result['meta']['total']); |
|
274 | + $this->assertEquals(2, count($result['data'])); |
|
275 | + $this->assertEquals('product', $result['data'][0]['type']); |
|
276 | + $this->assertEquals(0, count($result['included'])); |
|
277 | 277 | |
278 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
278 | + $this->assertArrayNotHasKey('errors', $result); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | |
@@ -287,25 +287,25 @@ discard block |
||
287 | 287 | 'limit' => 25 |
288 | 288 | ) |
289 | 289 | ); |
290 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
291 | - $this->view->addHelper( 'param', $helper ); |
|
290 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
291 | + $this->view->addHelper('param', $helper); |
|
292 | 292 | |
293 | - $response = $this->object->get( $this->view->request(), $this->view->response() ); |
|
294 | - $result = json_decode( (string) $response->getBody(), true ); |
|
293 | + $response = $this->object->get($this->view->request(), $this->view->response()); |
|
294 | + $result = json_decode((string) $response->getBody(), true); |
|
295 | 295 | |
296 | 296 | |
297 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
298 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
297 | + $this->assertEquals(200, $response->getStatusCode()); |
|
298 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
299 | 299 | |
300 | - $this->assertEquals( 28, $result['meta']['total'] ); |
|
301 | - $this->assertEquals( 3, count( $result['data'] ) ); |
|
302 | - $this->assertEquals( 'product', $result['data'][0]['type'] ); |
|
303 | - $this->assertEquals( 0, count( $result['included'] ) ); |
|
304 | - $this->assertArrayHasKey( 'first', $result['links'] ); |
|
305 | - $this->assertArrayHasKey( 'prev', $result['links'] ); |
|
306 | - $this->assertArrayHasKey( 'self', $result['links'] ); |
|
300 | + $this->assertEquals(28, $result['meta']['total']); |
|
301 | + $this->assertEquals(3, count($result['data'])); |
|
302 | + $this->assertEquals('product', $result['data'][0]['type']); |
|
303 | + $this->assertEquals(0, count($result['included'])); |
|
304 | + $this->assertArrayHasKey('first', $result['links']); |
|
305 | + $this->assertArrayHasKey('prev', $result['links']); |
|
306 | + $this->assertArrayHasKey('self', $result['links']); |
|
307 | 307 | |
308 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
308 | + $this->assertArrayNotHasKey('errors', $result); |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | |
@@ -314,24 +314,24 @@ discard block |
||
314 | 314 | $params = array( |
315 | 315 | 'sort' => 'product.label,-product.code' |
316 | 316 | ); |
317 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
318 | - $this->view->addHelper( 'param', $helper ); |
|
317 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
318 | + $this->view->addHelper('param', $helper); |
|
319 | 319 | |
320 | - $response = $this->object->get( $this->view->request(), $this->view->response() ); |
|
321 | - $result = json_decode( (string) $response->getBody(), true ); |
|
320 | + $response = $this->object->get($this->view->request(), $this->view->response()); |
|
321 | + $result = json_decode((string) $response->getBody(), true); |
|
322 | 322 | |
323 | 323 | |
324 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
325 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
324 | + $this->assertEquals(200, $response->getStatusCode()); |
|
325 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
326 | 326 | |
327 | - $this->assertEquals( 28, $result['meta']['total'] ); |
|
328 | - $this->assertEquals( 25, count( $result['data'] ) ); |
|
329 | - $this->assertEquals( 'product', $result['data'][0]['type'] ); |
|
330 | - $this->assertEquals( 'QRST', $result['data'][0]['attributes']['product.code'] ); |
|
331 | - $this->assertEquals( '16 discs', $result['data'][0]['attributes']['product.label'] ); |
|
332 | - $this->assertEquals( 0, count( $result['included'] ) ); |
|
327 | + $this->assertEquals(28, $result['meta']['total']); |
|
328 | + $this->assertEquals(25, count($result['data'])); |
|
329 | + $this->assertEquals('product', $result['data'][0]['type']); |
|
330 | + $this->assertEquals('QRST', $result['data'][0]['attributes']['product.code']); |
|
331 | + $this->assertEquals('16 discs', $result['data'][0]['attributes']['product.label']); |
|
332 | + $this->assertEquals(0, count($result['included'])); |
|
333 | 333 | |
334 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
334 | + $this->assertArrayNotHasKey('errors', $result); |
|
335 | 335 | } |
336 | 336 | |
337 | 337 | |
@@ -344,258 +344,258 @@ discard block |
||
344 | 344 | 'sort' => 'product.id', |
345 | 345 | 'include' => 'product' |
346 | 346 | ); |
347 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
348 | - $this->view->addHelper( 'param', $helper ); |
|
347 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
348 | + $this->view->addHelper('param', $helper); |
|
349 | 349 | |
350 | - $response = $this->object->get( $this->view->request(), $this->view->response() ); |
|
351 | - $result = json_decode( (string) $response->getBody(), true ); |
|
350 | + $response = $this->object->get($this->view->request(), $this->view->response()); |
|
351 | + $result = json_decode((string) $response->getBody(), true); |
|
352 | 352 | |
353 | 353 | |
354 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
355 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
354 | + $this->assertEquals(200, $response->getStatusCode()); |
|
355 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
356 | 356 | |
357 | - $this->assertEquals( 28, $result['meta']['total'] ); |
|
358 | - $this->assertEquals( 25, count( $result['data'] ) ); |
|
359 | - $this->assertEquals( 'product', $result['data'][0]['type'] ); |
|
360 | - $this->assertEquals( 2, count( $result['data'][0]['attributes'] ) ); |
|
357 | + $this->assertEquals(28, $result['meta']['total']); |
|
358 | + $this->assertEquals(25, count($result['data'])); |
|
359 | + $this->assertEquals('product', $result['data'][0]['type']); |
|
360 | + $this->assertEquals(2, count($result['data'][0]['attributes'])); |
|
361 | 361 | |
362 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
362 | + $this->assertArrayNotHasKey('errors', $result); |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | |
366 | 366 | public function testPatch() |
367 | 367 | { |
368 | - $productManagerStub = $this->getProductMock( array( 'getItem', 'saveItem' ) ); |
|
368 | + $productManagerStub = $this->getProductMock(array('getItem', 'saveItem')); |
|
369 | 369 | |
370 | 370 | $item = $productManagerStub->createItem(); |
371 | - $item->setLabel( 'test' ); |
|
372 | - $item->setId( '-1' ); |
|
371 | + $item->setLabel('test'); |
|
372 | + $item->setId('-1'); |
|
373 | 373 | |
374 | - $productManagerStub->expects( $this->once() )->method( 'saveItem' ); |
|
375 | - $productManagerStub->expects( $this->atLeastOnce() )->method( 'getItem' ) |
|
376 | - ->will( $this->returnValue( $item ) ); |
|
374 | + $productManagerStub->expects($this->once())->method('saveItem'); |
|
375 | + $productManagerStub->expects($this->atLeastOnce())->method('getItem') |
|
376 | + ->will($this->returnValue($item)); |
|
377 | 377 | |
378 | 378 | |
379 | - $params = array( 'id' => '-1' ); |
|
380 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
381 | - $this->view->addHelper( 'param', $helper ); |
|
379 | + $params = array('id' => '-1'); |
|
380 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
381 | + $this->view->addHelper('param', $helper); |
|
382 | 382 | |
383 | 383 | $body = '{"data": {"type": "product", "attributes": {"product.label": "test"}}}'; |
384 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
384 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
385 | 385 | |
386 | - $response = $this->object->patch( $request, $this->view->response() ); |
|
387 | - $result = json_decode( (string) $response->getBody(), true ); |
|
386 | + $response = $this->object->patch($request, $this->view->response()); |
|
387 | + $result = json_decode((string) $response->getBody(), true); |
|
388 | 388 | |
389 | 389 | |
390 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
391 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
390 | + $this->assertEquals(200, $response->getStatusCode()); |
|
391 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
392 | 392 | |
393 | - $this->assertEquals( 1, $result['meta']['total'] ); |
|
394 | - $this->assertArrayHasKey( 'data', $result ); |
|
395 | - $this->assertEquals( '-1', $result['data']['id'] ); |
|
396 | - $this->assertEquals( 'product', $result['data']['type'] ); |
|
397 | - $this->assertEquals( 'test', $result['data']['attributes']['product.label'] ); |
|
393 | + $this->assertEquals(1, $result['meta']['total']); |
|
394 | + $this->assertArrayHasKey('data', $result); |
|
395 | + $this->assertEquals('-1', $result['data']['id']); |
|
396 | + $this->assertEquals('product', $result['data']['type']); |
|
397 | + $this->assertEquals('test', $result['data']['attributes']['product.label']); |
|
398 | 398 | |
399 | - $this->assertArrayNotHasKey( 'included', $result ); |
|
400 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
399 | + $this->assertArrayNotHasKey('included', $result); |
|
400 | + $this->assertArrayNotHasKey('errors', $result); |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | |
404 | 404 | public function testPatchBulk() |
405 | 405 | { |
406 | - $productManagerStub = $this->getProductMock( array( 'getItem', 'saveItem' ) ); |
|
406 | + $productManagerStub = $this->getProductMock(array('getItem', 'saveItem')); |
|
407 | 407 | |
408 | 408 | $item = $productManagerStub->createItem(); |
409 | - $item->setLabel( 'test' ); |
|
410 | - $item->setId( '-1' ); |
|
409 | + $item->setLabel('test'); |
|
410 | + $item->setId('-1'); |
|
411 | 411 | |
412 | - $productManagerStub->expects( $this->exactly( 2 ) )->method( 'saveItem' ); |
|
413 | - $productManagerStub->expects( $this->atLeastOnce() )->method( 'getItem' ) |
|
414 | - ->will( $this->returnValue( $item ) ); |
|
412 | + $productManagerStub->expects($this->exactly(2))->method('saveItem'); |
|
413 | + $productManagerStub->expects($this->atLeastOnce())->method('getItem') |
|
414 | + ->will($this->returnValue($item)); |
|
415 | 415 | |
416 | 416 | |
417 | 417 | $body = '{"data": [{"id": "-1", "type": "product", "attributes": {"product.label": "test"}}, {"id": "-1", "type": "product", "attributes": {"product.label": "test"}}]}'; |
418 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
418 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
419 | 419 | |
420 | - $response = $this->object->patch( $request, $this->view->response() ); |
|
421 | - $result = json_decode( (string) $response->getBody(), true ); |
|
420 | + $response = $this->object->patch($request, $this->view->response()); |
|
421 | + $result = json_decode((string) $response->getBody(), true); |
|
422 | 422 | |
423 | 423 | |
424 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
425 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
424 | + $this->assertEquals(200, $response->getStatusCode()); |
|
425 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
426 | 426 | |
427 | - $this->assertEquals( 2, $result['meta']['total'] ); |
|
428 | - $this->assertArrayHasKey( 'data', $result ); |
|
429 | - $this->assertEquals( 2, count( $result['data'] ) ); |
|
430 | - $this->assertEquals( '-1', $result['data'][0]['id'] ); |
|
431 | - $this->assertEquals( 'product', $result['data'][0]['type'] ); |
|
432 | - $this->assertEquals( 'test', $result['data'][0]['attributes']['product.label'] ); |
|
427 | + $this->assertEquals(2, $result['meta']['total']); |
|
428 | + $this->assertArrayHasKey('data', $result); |
|
429 | + $this->assertEquals(2, count($result['data'])); |
|
430 | + $this->assertEquals('-1', $result['data'][0]['id']); |
|
431 | + $this->assertEquals('product', $result['data'][0]['type']); |
|
432 | + $this->assertEquals('test', $result['data'][0]['attributes']['product.label']); |
|
433 | 433 | |
434 | - $this->assertArrayNotHasKey( 'included', $result ); |
|
435 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
434 | + $this->assertArrayNotHasKey('included', $result); |
|
435 | + $this->assertArrayNotHasKey('errors', $result); |
|
436 | 436 | } |
437 | 437 | |
438 | 438 | |
439 | 439 | public function testPatchInvalid() |
440 | 440 | { |
441 | 441 | $body = '{"data":null}'; |
442 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
442 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
443 | 443 | |
444 | - $response = $this->object->patch( $request, $this->view->response() ); |
|
445 | - $result = json_decode( (string) $response->getBody(), true ); |
|
444 | + $response = $this->object->patch($request, $this->view->response()); |
|
445 | + $result = json_decode((string) $response->getBody(), true); |
|
446 | 446 | |
447 | 447 | |
448 | - $this->assertEquals( 400, $response->getStatusCode() ); |
|
449 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
448 | + $this->assertEquals(400, $response->getStatusCode()); |
|
449 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
450 | 450 | |
451 | - $this->assertEquals( 0, $result['meta']['total'] ); |
|
452 | - $this->assertArrayHasKey( 'errors', $result ); |
|
453 | - $this->assertArrayNotHasKey( 'included', $result ); |
|
454 | - $this->assertArrayNotHasKey( 'data', $result ); |
|
451 | + $this->assertEquals(0, $result['meta']['total']); |
|
452 | + $this->assertArrayHasKey('errors', $result); |
|
453 | + $this->assertArrayNotHasKey('included', $result); |
|
454 | + $this->assertArrayNotHasKey('data', $result); |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | |
458 | 458 | public function testPatchInvalidId() |
459 | 459 | { |
460 | 460 | $body = '{"data":{"id":-1}}'; |
461 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
461 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
462 | 462 | |
463 | - $response = $this->object->patch( $request, $this->view->response() ); |
|
464 | - $result = json_decode( (string) $response->getBody(), true ); |
|
463 | + $response = $this->object->patch($request, $this->view->response()); |
|
464 | + $result = json_decode((string) $response->getBody(), true); |
|
465 | 465 | |
466 | 466 | |
467 | - $this->assertEquals( 400, $response->getStatusCode() ); |
|
468 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
467 | + $this->assertEquals(400, $response->getStatusCode()); |
|
468 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
469 | 469 | |
470 | - $this->assertEquals( 0, $result['meta']['total'] ); |
|
471 | - $this->assertArrayHasKey( 'errors', $result ); |
|
470 | + $this->assertEquals(0, $result['meta']['total']); |
|
471 | + $this->assertArrayHasKey('errors', $result); |
|
472 | 472 | } |
473 | 473 | |
474 | 474 | |
475 | 475 | public function testPatchException() |
476 | 476 | { |
477 | - $this->getProductMock( array( 'getItem' ) )->expects( $this->once() )->method( 'getItem' ) |
|
478 | - ->will( $this->throwException( new \RuntimeException( 'test exception' ) ) ); |
|
477 | + $this->getProductMock(array('getItem'))->expects($this->once())->method('getItem') |
|
478 | + ->will($this->throwException(new \RuntimeException('test exception'))); |
|
479 | 479 | |
480 | 480 | $body = '{"data":[{"id":-1}]}'; |
481 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
481 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
482 | 482 | |
483 | - $response = $this->object->patch( $request, $this->view->response() ); |
|
484 | - $result = json_decode( (string) $response->getBody(), true ); |
|
483 | + $response = $this->object->patch($request, $this->view->response()); |
|
484 | + $result = json_decode((string) $response->getBody(), true); |
|
485 | 485 | |
486 | 486 | |
487 | - $this->assertEquals( 500, $response->getStatusCode() ); |
|
488 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
489 | - $this->assertArrayHasKey( 'errors', $result ); |
|
487 | + $this->assertEquals(500, $response->getStatusCode()); |
|
488 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
489 | + $this->assertArrayHasKey('errors', $result); |
|
490 | 490 | } |
491 | 491 | |
492 | 492 | |
493 | 493 | public function testPatchMShopException() |
494 | 494 | { |
495 | - $this->getProductMock( array( 'getItem' ) )->expects( $this->once() )->method( 'getItem' ) |
|
496 | - ->will( $this->throwException( new \Aimeos\MShop\Exception( 'test exception' ) ) ); |
|
495 | + $this->getProductMock(array('getItem'))->expects($this->once())->method('getItem') |
|
496 | + ->will($this->throwException(new \Aimeos\MShop\Exception('test exception'))); |
|
497 | 497 | |
498 | 498 | $body = '{"data":[{"id":-1}]}'; |
499 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
499 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
500 | 500 | |
501 | - $response = $this->object->patch( $request, $this->view->response() ); |
|
502 | - $result = json_decode( (string) $response->getBody(), true ); |
|
501 | + $response = $this->object->patch($request, $this->view->response()); |
|
502 | + $result = json_decode((string) $response->getBody(), true); |
|
503 | 503 | |
504 | 504 | |
505 | - $this->assertEquals( 404, $response->getStatusCode() ); |
|
506 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
507 | - $this->assertArrayHasKey( 'errors', $result ); |
|
505 | + $this->assertEquals(404, $response->getStatusCode()); |
|
506 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
507 | + $this->assertArrayHasKey('errors', $result); |
|
508 | 508 | } |
509 | 509 | |
510 | 510 | |
511 | 511 | public function testPost() |
512 | 512 | { |
513 | - $productManagerStub = $this->getProductMock( array( 'createItem', 'getItem', 'saveItem' ) ); |
|
513 | + $productManagerStub = $this->getProductMock(array('createItem', 'getItem', 'saveItem')); |
|
514 | 514 | |
515 | 515 | $item = new \Aimeos\MShop\Product\Item\Standard(); |
516 | - $item->setId( '-1' ); |
|
516 | + $item->setId('-1'); |
|
517 | 517 | |
518 | - $productManagerStub->expects( $this->once() )->method( 'createItem' ) |
|
519 | - ->will( $this->returnValue( $item ) ); |
|
520 | - $productManagerStub->expects( $this->any() )->method( 'getItem' ) |
|
521 | - ->will( $this->returnValue( $item ) ); |
|
522 | - $productManagerStub->expects( $this->once() )->method( 'saveItem' ); |
|
518 | + $productManagerStub->expects($this->once())->method('createItem') |
|
519 | + ->will($this->returnValue($item)); |
|
520 | + $productManagerStub->expects($this->any())->method('getItem') |
|
521 | + ->will($this->returnValue($item)); |
|
522 | + $productManagerStub->expects($this->once())->method('saveItem'); |
|
523 | 523 | |
524 | 524 | |
525 | 525 | $body = '{"data": {"type": "product", "attributes": {"product.type": "default", "product.label": "test"}}}'; |
526 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
526 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
527 | 527 | |
528 | - $response = $this->object->post( $request, $this->view->response() ); |
|
529 | - $result = json_decode( (string) $response->getBody(), true ); |
|
528 | + $response = $this->object->post($request, $this->view->response()); |
|
529 | + $result = json_decode((string) $response->getBody(), true); |
|
530 | 530 | |
531 | 531 | |
532 | - $this->assertEquals( 201, $response->getStatusCode() ); |
|
533 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
532 | + $this->assertEquals(201, $response->getStatusCode()); |
|
533 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
534 | 534 | |
535 | - $this->assertEquals( 1, $result['meta']['total'] ); |
|
536 | - $this->assertArrayHasKey( 'data', $result ); |
|
537 | - $this->assertEquals( '-1', $result['data']['id'] ); |
|
538 | - $this->assertEquals( 'product', $result['data']['type'] ); |
|
539 | - $this->assertGreaterThan( 0, $result['data']['attributes']['product.typeid'] ); |
|
540 | - $this->assertEquals( 'test', $result['data']['attributes']['product.label'] ); |
|
535 | + $this->assertEquals(1, $result['meta']['total']); |
|
536 | + $this->assertArrayHasKey('data', $result); |
|
537 | + $this->assertEquals('-1', $result['data']['id']); |
|
538 | + $this->assertEquals('product', $result['data']['type']); |
|
539 | + $this->assertGreaterThan(0, $result['data']['attributes']['product.typeid']); |
|
540 | + $this->assertEquals('test', $result['data']['attributes']['product.label']); |
|
541 | 541 | |
542 | - $this->assertArrayNotHasKey( 'included', $result ); |
|
543 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
542 | + $this->assertArrayNotHasKey('included', $result); |
|
543 | + $this->assertArrayNotHasKey('errors', $result); |
|
544 | 544 | } |
545 | 545 | |
546 | 546 | |
547 | 547 | public function testPostBulk() |
548 | 548 | { |
549 | - $productManagerStub = $this->getProductMock( array( 'getItem', 'saveItem' ) ); |
|
549 | + $productManagerStub = $this->getProductMock(array('getItem', 'saveItem')); |
|
550 | 550 | |
551 | 551 | $item = $productManagerStub->createItem(); |
552 | - $item->setLabel( 'test' ); |
|
553 | - $item->setId( '-1' ); |
|
552 | + $item->setLabel('test'); |
|
553 | + $item->setId('-1'); |
|
554 | 554 | |
555 | - $productManagerStub->expects( $this->exactly( 2 ) )->method( 'saveItem' ); |
|
556 | - $productManagerStub->expects( $this->exactly( 2 ) )->method( 'getItem' ) |
|
557 | - ->will( $this->returnValue( $item ) ); |
|
555 | + $productManagerStub->expects($this->exactly(2))->method('saveItem'); |
|
556 | + $productManagerStub->expects($this->exactly(2))->method('getItem') |
|
557 | + ->will($this->returnValue($item)); |
|
558 | 558 | |
559 | 559 | |
560 | 560 | $body = '{"data": [{"type": "product", "attributes": {"product.label": "test"}}, {"type": "product", "attributes": {"product.label": "test"}}]}'; |
561 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
561 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
562 | 562 | |
563 | - $response = $this->object->post( $request, $this->view->response() ); |
|
564 | - $result = json_decode( (string) $response->getBody(), true ); |
|
563 | + $response = $this->object->post($request, $this->view->response()); |
|
564 | + $result = json_decode((string) $response->getBody(), true); |
|
565 | 565 | |
566 | 566 | |
567 | - $this->assertEquals( 201, $response->getStatusCode() ); |
|
568 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
567 | + $this->assertEquals(201, $response->getStatusCode()); |
|
568 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
569 | 569 | |
570 | - $this->assertEquals( 2, $result['meta']['total'] ); |
|
571 | - $this->assertArrayHasKey( 'data', $result ); |
|
572 | - $this->assertEquals( 2, count( $result['data'] ) ); |
|
573 | - $this->assertEquals( '-1', $result['data'][0]['id'] ); |
|
574 | - $this->assertEquals( 'product', $result['data'][0]['type'] ); |
|
575 | - $this->assertEquals( 'test', $result['data'][0]['attributes']['product.label'] ); |
|
570 | + $this->assertEquals(2, $result['meta']['total']); |
|
571 | + $this->assertArrayHasKey('data', $result); |
|
572 | + $this->assertEquals(2, count($result['data'])); |
|
573 | + $this->assertEquals('-1', $result['data'][0]['id']); |
|
574 | + $this->assertEquals('product', $result['data'][0]['type']); |
|
575 | + $this->assertEquals('test', $result['data'][0]['attributes']['product.label']); |
|
576 | 576 | |
577 | - $this->assertArrayNotHasKey( 'included', $result ); |
|
578 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
577 | + $this->assertArrayNotHasKey('included', $result); |
|
578 | + $this->assertArrayNotHasKey('errors', $result); |
|
579 | 579 | } |
580 | 580 | |
581 | 581 | |
582 | 582 | public function testPostRelationships() |
583 | 583 | { |
584 | - $productManagerStub = $this->getProductMock( array( 'getSubManager', 'createItem', 'getItem', 'saveItem' ) ); |
|
585 | - $productManagerListsStub = $this->getProductListsMock( array( 'saveItem' ) ); |
|
584 | + $productManagerStub = $this->getProductMock(array('getSubManager', 'createItem', 'getItem', 'saveItem')); |
|
585 | + $productManagerListsStub = $this->getProductListsMock(array('saveItem')); |
|
586 | 586 | |
587 | 587 | $item = new \Aimeos\MShop\Product\Item\Standard(); |
588 | - $item->setId( '-1' ); |
|
588 | + $item->setId('-1'); |
|
589 | 589 | |
590 | - $productManagerStub->expects( $this->once() )->method( 'createItem' ) |
|
591 | - ->will( $this->returnValue( $item ) ); |
|
592 | - $productManagerStub->expects( $this->any() )->method( 'getItem' ) |
|
593 | - ->will( $this->returnValue( $item ) ); |
|
594 | - $productManagerStub->expects( $this->once() )->method( 'getSubManager' ) |
|
595 | - ->will( $this->returnValue( $productManagerListsStub ) ); |
|
596 | - $productManagerStub->expects( $this->once() )->method( 'saveItem' ); |
|
590 | + $productManagerStub->expects($this->once())->method('createItem') |
|
591 | + ->will($this->returnValue($item)); |
|
592 | + $productManagerStub->expects($this->any())->method('getItem') |
|
593 | + ->will($this->returnValue($item)); |
|
594 | + $productManagerStub->expects($this->once())->method('getSubManager') |
|
595 | + ->will($this->returnValue($productManagerListsStub)); |
|
596 | + $productManagerStub->expects($this->once())->method('saveItem'); |
|
597 | 597 | |
598 | - $productManagerListsStub->expects( $this->once() )->method( 'saveItem' ); |
|
598 | + $productManagerListsStub->expects($this->once())->method('saveItem'); |
|
599 | 599 | |
600 | 600 | $body = '{"data": {"type": "product", |
601 | 601 | "attributes": {"product.label": "test"}, |
@@ -603,212 +603,212 @@ discard block |
||
603 | 603 | {"type": "text", "id": "-2", "attributes": {"product.lists.type": "default"}} |
604 | 604 | ]}} |
605 | 605 | }}'; |
606 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
606 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
607 | 607 | |
608 | - $response = $this->object->post( $request, $this->view->response() ); |
|
609 | - $result = json_decode( (string) $response->getBody(), true ); |
|
608 | + $response = $this->object->post($request, $this->view->response()); |
|
609 | + $result = json_decode((string) $response->getBody(), true); |
|
610 | 610 | |
611 | 611 | |
612 | - $this->assertEquals( 201, $response->getStatusCode() ); |
|
613 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
612 | + $this->assertEquals(201, $response->getStatusCode()); |
|
613 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
614 | 614 | |
615 | - $this->assertEquals( 1, $result['meta']['total'] ); |
|
616 | - $this->assertArrayHasKey( 'data', $result ); |
|
617 | - $this->assertEquals( '-1', $result['data']['id'] ); |
|
618 | - $this->assertEquals( 'product', $result['data']['type'] ); |
|
619 | - $this->assertEquals( 'test', $result['data']['attributes']['product.label'] ); |
|
615 | + $this->assertEquals(1, $result['meta']['total']); |
|
616 | + $this->assertArrayHasKey('data', $result); |
|
617 | + $this->assertEquals('-1', $result['data']['id']); |
|
618 | + $this->assertEquals('product', $result['data']['type']); |
|
619 | + $this->assertEquals('test', $result['data']['attributes']['product.label']); |
|
620 | 620 | |
621 | - $this->assertArrayNotHasKey( 'included', $result ); |
|
622 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
621 | + $this->assertArrayNotHasKey('included', $result); |
|
622 | + $this->assertArrayNotHasKey('errors', $result); |
|
623 | 623 | } |
624 | 624 | |
625 | 625 | |
626 | 626 | public function testPostInvalid() |
627 | 627 | { |
628 | 628 | $body = '{"data":null}'; |
629 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
629 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
630 | 630 | |
631 | - $response = $this->object->post( $request, $this->view->response() ); |
|
632 | - $result = json_decode( (string) $response->getBody(), true ); |
|
631 | + $response = $this->object->post($request, $this->view->response()); |
|
632 | + $result = json_decode((string) $response->getBody(), true); |
|
633 | 633 | |
634 | 634 | |
635 | - $this->assertEquals( 400, $response->getStatusCode() ); |
|
636 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
635 | + $this->assertEquals(400, $response->getStatusCode()); |
|
636 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
637 | 637 | |
638 | - $this->assertEquals( 0, $result['meta']['total'] ); |
|
639 | - $this->assertArrayHasKey( 'errors', $result ); |
|
640 | - $this->assertArrayNotHasKey( 'included', $result ); |
|
641 | - $this->assertArrayNotHasKey( 'data', $result ); |
|
638 | + $this->assertEquals(0, $result['meta']['total']); |
|
639 | + $this->assertArrayHasKey('errors', $result); |
|
640 | + $this->assertArrayNotHasKey('included', $result); |
|
641 | + $this->assertArrayNotHasKey('data', $result); |
|
642 | 642 | } |
643 | 643 | |
644 | 644 | |
645 | 645 | public function testPostInvalidId() |
646 | 646 | { |
647 | 647 | $body = '{"data":{"id":-1}}'; |
648 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
648 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
649 | 649 | |
650 | - $response = $this->object->post( $request, $this->view->response() ); |
|
651 | - $result = json_decode( (string) $response->getBody(), true ); |
|
650 | + $response = $this->object->post($request, $this->view->response()); |
|
651 | + $result = json_decode((string) $response->getBody(), true); |
|
652 | 652 | |
653 | 653 | |
654 | - $this->assertEquals( 403, $response->getStatusCode() ); |
|
655 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
654 | + $this->assertEquals(403, $response->getStatusCode()); |
|
655 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
656 | 656 | |
657 | - $this->assertEquals( 0, $result['meta']['total'] ); |
|
658 | - $this->assertArrayHasKey( 'errors', $result ); |
|
657 | + $this->assertEquals(0, $result['meta']['total']); |
|
658 | + $this->assertArrayHasKey('errors', $result); |
|
659 | 659 | } |
660 | 660 | |
661 | 661 | |
662 | 662 | public function testPostException() |
663 | 663 | { |
664 | - $this->getProductMock( array( 'saveItem' ) )->expects( $this->once() )->method( 'saveItem' ) |
|
665 | - ->will( $this->throwException( new \RuntimeException( 'test exception' ) ) ); |
|
664 | + $this->getProductMock(array('saveItem'))->expects($this->once())->method('saveItem') |
|
665 | + ->will($this->throwException(new \RuntimeException('test exception'))); |
|
666 | 666 | |
667 | 667 | $body = '{"data":{}}'; |
668 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
668 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
669 | 669 | |
670 | - $response = $this->object->post( $request, $this->view->response() ); |
|
671 | - $result = json_decode( (string) $response->getBody(), true ); |
|
670 | + $response = $this->object->post($request, $this->view->response()); |
|
671 | + $result = json_decode((string) $response->getBody(), true); |
|
672 | 672 | |
673 | 673 | |
674 | - $this->assertEquals( 500, $response->getStatusCode() ); |
|
675 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
676 | - $this->assertArrayHasKey( 'errors', $result ); |
|
674 | + $this->assertEquals(500, $response->getStatusCode()); |
|
675 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
676 | + $this->assertArrayHasKey('errors', $result); |
|
677 | 677 | } |
678 | 678 | |
679 | 679 | |
680 | 680 | public function testPostMShopException() |
681 | 681 | { |
682 | - $this->getProductMock( array( 'saveItem' ) )->expects( $this->once() )->method( 'saveItem' ) |
|
683 | - ->will( $this->throwException( new \Aimeos\MShop\Exception( 'test exception' ) ) ); |
|
682 | + $this->getProductMock(array('saveItem'))->expects($this->once())->method('saveItem') |
|
683 | + ->will($this->throwException(new \Aimeos\MShop\Exception('test exception'))); |
|
684 | 684 | |
685 | 685 | $body = '{"data":{}}'; |
686 | - $request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) ); |
|
686 | + $request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body)); |
|
687 | 687 | |
688 | - $response = $this->object->post( $request, $this->view->response() ); |
|
689 | - $result = json_decode( (string) $response->getBody(), true ); |
|
688 | + $response = $this->object->post($request, $this->view->response()); |
|
689 | + $result = json_decode((string) $response->getBody(), true); |
|
690 | 690 | |
691 | 691 | |
692 | - $this->assertEquals( 404, $response->getStatusCode() ); |
|
693 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
694 | - $this->assertArrayHasKey( 'errors', $result ); |
|
692 | + $this->assertEquals(404, $response->getStatusCode()); |
|
693 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
694 | + $this->assertArrayHasKey('errors', $result); |
|
695 | 695 | } |
696 | 696 | |
697 | 697 | |
698 | 698 | public function testPut() |
699 | 699 | { |
700 | - $response = $this->object->put( $this->view->request(), $this->view->response() ); |
|
701 | - $result = json_decode( (string) $response->getBody(), true ); |
|
700 | + $response = $this->object->put($this->view->request(), $this->view->response()); |
|
701 | + $result = json_decode((string) $response->getBody(), true); |
|
702 | 702 | |
703 | - $this->assertEquals( 501, $response->getStatusCode() ); |
|
704 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
705 | - $this->assertArrayHasKey( 'errors', $result ); |
|
703 | + $this->assertEquals(501, $response->getStatusCode()); |
|
704 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
705 | + $this->assertArrayHasKey('errors', $result); |
|
706 | 706 | } |
707 | 707 | |
708 | 708 | |
709 | 709 | public function testOptions() |
710 | 710 | { |
711 | - $response = $this->object->options( $this->view->request(), $this->view->response() ); |
|
712 | - $result = json_decode( (string) $response->getBody(), true ); |
|
711 | + $response = $this->object->options($this->view->request(), $this->view->response()); |
|
712 | + $result = json_decode((string) $response->getBody(), true); |
|
713 | 713 | |
714 | 714 | |
715 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
716 | - $this->assertEquals( 1, count( $response->getHeader( 'Allow' ) ) ); |
|
717 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
715 | + $this->assertEquals(200, $response->getStatusCode()); |
|
716 | + $this->assertEquals(1, count($response->getHeader('Allow'))); |
|
717 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
718 | 718 | |
719 | - $this->assertNull( $result['meta']['prefix'] ); |
|
720 | - $this->assertEquals( 57, count( $result['meta']['resources'] ) ); |
|
721 | - $this->assertGreaterThan( 0, count( $result['meta']['attributes'] ) ); |
|
719 | + $this->assertNull($result['meta']['prefix']); |
|
720 | + $this->assertEquals(57, count($result['meta']['resources'])); |
|
721 | + $this->assertGreaterThan(0, count($result['meta']['attributes'])); |
|
722 | 722 | |
723 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
723 | + $this->assertArrayNotHasKey('errors', $result); |
|
724 | 724 | } |
725 | 725 | |
726 | 726 | |
727 | 727 | public function testOptionsWithPrefix() |
728 | 728 | { |
729 | - $response = $this->object->options( $this->view->request(), $this->view->response(), 'prefix' ); |
|
730 | - $result = json_decode( (string) $response->getBody(), true ); |
|
729 | + $response = $this->object->options($this->view->request(), $this->view->response(), 'prefix'); |
|
730 | + $result = json_decode((string) $response->getBody(), true); |
|
731 | 731 | |
732 | 732 | |
733 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
734 | - $this->assertEquals( 1, count( $response->getHeader( 'Allow' ) ) ); |
|
735 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
733 | + $this->assertEquals(200, $response->getStatusCode()); |
|
734 | + $this->assertEquals(1, count($response->getHeader('Allow'))); |
|
735 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
736 | 736 | |
737 | - $this->assertEquals( 'prefix', $result['meta']['prefix'] ); |
|
738 | - $this->assertEquals( 57, count( $result['meta']['resources'] ) ); |
|
739 | - $this->assertGreaterThan( 0, count( $result['meta']['attributes'] ) ); |
|
737 | + $this->assertEquals('prefix', $result['meta']['prefix']); |
|
738 | + $this->assertEquals(57, count($result['meta']['resources'])); |
|
739 | + $this->assertGreaterThan(0, count($result['meta']['attributes'])); |
|
740 | 740 | |
741 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
741 | + $this->assertArrayNotHasKey('errors', $result); |
|
742 | 742 | } |
743 | 743 | |
744 | 744 | |
745 | 745 | public function testOptionsException() |
746 | 746 | { |
747 | - $this->getProductMock( array( 'getResourceType' ) )->expects( $this->once() )->method( 'getResourceType' ) |
|
748 | - ->will( $this->throwException( new \RuntimeException( 'test exception' ) ) ); |
|
747 | + $this->getProductMock(array('getResourceType'))->expects($this->once())->method('getResourceType') |
|
748 | + ->will($this->throwException(new \RuntimeException('test exception'))); |
|
749 | 749 | |
750 | - $response = $this->object->options( $this->view->request(), $this->view->response() ); |
|
751 | - $result = json_decode( (string) $response->getBody(), true ); |
|
750 | + $response = $this->object->options($this->view->request(), $this->view->response()); |
|
751 | + $result = json_decode((string) $response->getBody(), true); |
|
752 | 752 | |
753 | - $this->assertEquals( 500, $response->getStatusCode() ); |
|
754 | - $this->assertArrayHasKey( 'errors', $result ); |
|
753 | + $this->assertEquals(500, $response->getStatusCode()); |
|
754 | + $this->assertArrayHasKey('errors', $result); |
|
755 | 755 | } |
756 | 756 | |
757 | 757 | |
758 | 758 | public function testOptionsMShopException() |
759 | 759 | { |
760 | - $this->getProductMock( array( 'getResourceType' ) )->expects( $this->once() )->method( 'getResourceType' ) |
|
761 | - ->will( $this->throwException( new \Aimeos\MShop\Exception( 'test exception' ) ) ); |
|
760 | + $this->getProductMock(array('getResourceType'))->expects($this->once())->method('getResourceType') |
|
761 | + ->will($this->throwException(new \Aimeos\MShop\Exception('test exception'))); |
|
762 | 762 | |
763 | - $response = $this->object->options( $this->view->request(), $this->view->response() ); |
|
764 | - $result = json_decode( (string) $response->getBody(), true ); |
|
763 | + $response = $this->object->options($this->view->request(), $this->view->response()); |
|
764 | + $result = json_decode((string) $response->getBody(), true); |
|
765 | 765 | |
766 | - $this->assertEquals( 404, $response->getStatusCode() ); |
|
767 | - $this->assertArrayHasKey( 'errors', $result ); |
|
766 | + $this->assertEquals(404, $response->getStatusCode()); |
|
767 | + $this->assertArrayHasKey('errors', $result); |
|
768 | 768 | } |
769 | 769 | |
770 | 770 | |
771 | - protected function getProductMock( array $methods ) |
|
771 | + protected function getProductMock(array $methods) |
|
772 | 772 | { |
773 | 773 | $name = 'ClientJsonAdmStandard'; |
774 | - $this->context->getConfig()->set( 'mshop/product/manager/name', $name ); |
|
774 | + $this->context->getConfig()->set('mshop/product/manager/name', $name); |
|
775 | 775 | |
776 | - $stub = $this->getMockBuilder( '\\Aimeos\\MShop\\Product\\Manager\\Standard' ) |
|
777 | - ->setConstructorArgs( array( $this->context ) ) |
|
778 | - ->setMethods( $methods ) |
|
776 | + $stub = $this->getMockBuilder('\\Aimeos\\MShop\\Product\\Manager\\Standard') |
|
777 | + ->setConstructorArgs(array($this->context)) |
|
778 | + ->setMethods($methods) |
|
779 | 779 | ->getMock(); |
780 | 780 | |
781 | - \Aimeos\MShop\Product\Manager\Factory::injectManager( '\\Aimeos\\MShop\\Product\\Manager\\' . $name, $stub ); |
|
781 | + \Aimeos\MShop\Product\Manager\Factory::injectManager('\\Aimeos\\MShop\\Product\\Manager\\' . $name, $stub); |
|
782 | 782 | |
783 | 783 | return $stub; |
784 | 784 | } |
785 | 785 | |
786 | 786 | |
787 | - protected function getProductListsMock( array $methods ) |
|
787 | + protected function getProductListsMock(array $methods) |
|
788 | 788 | { |
789 | 789 | $name = 'ClientJsonAdmStandard'; |
790 | - $this->context->getConfig()->set( 'mshop/product/manager/lists/name', $name ); |
|
790 | + $this->context->getConfig()->set('mshop/product/manager/lists/name', $name); |
|
791 | 791 | |
792 | - $stub = $this->getMockBuilder( '\\Aimeos\\MShop\\Product\\Manager\\Lists\\Standard' ) |
|
793 | - ->setConstructorArgs( array( $this->context ) ) |
|
794 | - ->setMethods( $methods ) |
|
792 | + $stub = $this->getMockBuilder('\\Aimeos\\MShop\\Product\\Manager\\Lists\\Standard') |
|
793 | + ->setConstructorArgs(array($this->context)) |
|
794 | + ->setMethods($methods) |
|
795 | 795 | ->getMock(); |
796 | 796 | |
797 | - \Aimeos\MShop\Product\Manager\Factory::injectManager( '\\Aimeos\\MShop\\Product\\Manager\\Lists\\' . $name, $stub ); |
|
797 | + \Aimeos\MShop\Product\Manager\Factory::injectManager('\\Aimeos\\MShop\\Product\\Manager\\Lists\\' . $name, $stub); |
|
798 | 798 | |
799 | 799 | return $stub; |
800 | 800 | } |
801 | 801 | |
802 | 802 | |
803 | - protected function getProductItem( $code = 'CNC' ) |
|
803 | + protected function getProductItem($code = 'CNC') |
|
804 | 804 | { |
805 | - $manager = \Aimeos\MShop\Product\Manager\Factory::createManager( $this->context ); |
|
805 | + $manager = \Aimeos\MShop\Product\Manager\Factory::createManager($this->context); |
|
806 | 806 | $search = $manager->createSearch(); |
807 | - $search->setConditions( $search->compare( '==', 'product.code', $code ) ); |
|
808 | - $items = $manager->searchItems( $search ); |
|
807 | + $search->setConditions($search->compare('==', 'product.code', $code)); |
|
808 | + $items = $manager->searchItems($search); |
|
809 | 809 | |
810 | - if( ( $item = reset( $items ) ) === false ) { |
|
811 | - throw new \RuntimeException( sprintf( 'No product item with code "%1$s" found', $code ) ); |
|
810 | + if (($item = reset($items)) === false) { |
|
811 | + throw new \RuntimeException(sprintf('No product item with code "%1$s" found', $code)); |
|
812 | 812 | } |
813 | 813 | |
814 | 814 | return $item; |
@@ -36,10 +36,10 @@ discard block |
||
36 | 36 | * @param array $templatePaths List of file system paths where the templates are stored |
37 | 37 | * @param string $path Name of the client separated by slashes, e.g "product/property" |
38 | 38 | */ |
39 | - public function __construct( \Aimeos\Admin\JsonAdm\Iface $client, |
|
40 | - \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MW\View\Iface $view, array $templatePaths, $path ) |
|
39 | + public function __construct(\Aimeos\Admin\JsonAdm\Iface $client, |
|
40 | + \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MW\View\Iface $view, array $templatePaths, $path) |
|
41 | 41 | { |
42 | - parent::__construct( $context, $view, $templatePaths, $path ); |
|
42 | + parent::__construct($context, $view, $templatePaths, $path); |
|
43 | 43 | |
44 | 44 | $this->client = $client; |
45 | 45 | } |
@@ -53,10 +53,10 @@ discard block |
||
53 | 53 | * @return mixed Returns the value of the called method |
54 | 54 | * @throws \Aimeos\Admin\JsonAdm\Exception If method call failed |
55 | 55 | */ |
56 | - public function __call( $name, array $param ) |
|
56 | + public function __call($name, array $param) |
|
57 | 57 | { |
58 | - if( ( $result = call_user_func_array( array( $this->client, $name ), $param ) ) === false ) { |
|
59 | - throw new \Aimeos\Admin\JsonAdm\Exception( sprintf( 'Unable to call method "%1$s"', $name ) ); |
|
58 | + if (($result = call_user_func_array(array($this->client, $name), $param)) === false) { |
|
59 | + throw new \Aimeos\Admin\JsonAdm\Exception(sprintf('Unable to call method "%1$s"', $name)); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | return $result; |
@@ -70,9 +70,9 @@ discard block |
||
70 | 70 | * @param \Psr\Http\Message\ResponseInterface $response Response object |
71 | 71 | * @return \Psr\Http\Message\ResponseInterface Modified response object |
72 | 72 | */ |
73 | - public function delete( ServerRequestInterface $request, ResponseInterface $response ) |
|
73 | + public function delete(ServerRequestInterface $request, ResponseInterface $response) |
|
74 | 74 | { |
75 | - return $this->client->delete( $request, $response ); |
|
75 | + return $this->client->delete($request, $response); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | * @param \Psr\Http\Message\ResponseInterface $response Response object |
84 | 84 | * @return \Psr\Http\Message\ResponseInterface Modified response object |
85 | 85 | */ |
86 | - public function get( ServerRequestInterface $request, ResponseInterface $response ) |
|
86 | + public function get(ServerRequestInterface $request, ResponseInterface $response) |
|
87 | 87 | { |
88 | - return $this->client->get( $request, $response ); |
|
88 | + return $this->client->get($request, $response); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | |
@@ -97,9 +97,9 @@ discard block |
||
97 | 97 | * @param \Psr\Http\Message\ResponseInterface $response Response object |
98 | 98 | * @return \Psr\Http\Message\ResponseInterface Modified response object |
99 | 99 | */ |
100 | - public function patch( ServerRequestInterface $request, ResponseInterface $response ) |
|
100 | + public function patch(ServerRequestInterface $request, ResponseInterface $response) |
|
101 | 101 | { |
102 | - return $this->client->patch( $request, $response ); |
|
102 | + return $this->client->patch($request, $response); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | * @param \Psr\Http\Message\ResponseInterface $response Response object |
112 | 112 | * @return \Psr\Http\Message\ResponseInterface Modified response object |
113 | 113 | */ |
114 | - public function post( ServerRequestInterface $request, ResponseInterface $response ) |
|
114 | + public function post(ServerRequestInterface $request, ResponseInterface $response) |
|
115 | 115 | { |
116 | - return $this->client->post( $request, $response ); |
|
116 | + return $this->client->post($request, $response); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | |
@@ -125,9 +125,9 @@ discard block |
||
125 | 125 | * @param \Psr\Http\Message\ResponseInterface $response Response object |
126 | 126 | * @return \Psr\Http\Message\ResponseInterface Modified response object |
127 | 127 | */ |
128 | - public function put( ServerRequestInterface $request, ResponseInterface $response ) |
|
128 | + public function put(ServerRequestInterface $request, ResponseInterface $response) |
|
129 | 129 | { |
130 | - return $this->client->put( $request, $response ); |
|
130 | + return $this->client->put($request, $response); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | |
@@ -140,8 +140,8 @@ discard block |
||
140 | 140 | * @param string|null Form parameter prefix when nesting parameters is required |
141 | 141 | * @return \Psr\Http\Message\ResponseInterface Modified response object |
142 | 142 | */ |
143 | - public function options( ServerRequestInterface $request, ResponseInterface $response, $prefix = null ) |
|
143 | + public function options(ServerRequestInterface $request, ResponseInterface $response, $prefix = null) |
|
144 | 144 | { |
145 | - return $this->client->options( $request, $response, $prefix ); |
|
145 | + return $this->client->options($request, $response, $prefix); |
|
146 | 146 | } |
147 | 147 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @param \Psr\Http\Message\ResponseInterface $response Response object |
30 | 30 | * @return \Psr\Http\Message\ResponseInterface Modified response object |
31 | 31 | */ |
32 | - public function delete( ServerRequestInterface $request, ResponseInterface $response ); |
|
32 | + public function delete(ServerRequestInterface $request, ResponseInterface $response); |
|
33 | 33 | |
34 | 34 | |
35 | 35 | /** |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | * @param \Psr\Http\Message\ResponseInterface $response Response object |
40 | 40 | * @return \Psr\Http\Message\ResponseInterface Modified response object |
41 | 41 | */ |
42 | - public function get( ServerRequestInterface $request, ResponseInterface $response ); |
|
42 | + public function get(ServerRequestInterface $request, ResponseInterface $response); |
|
43 | 43 | |
44 | 44 | |
45 | 45 | /** |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * @param \Psr\Http\Message\ResponseInterface $response Response object |
50 | 50 | * @return \Psr\Http\Message\ResponseInterface Modified response object |
51 | 51 | */ |
52 | - public function patch( ServerRequestInterface $request, ResponseInterface $response ); |
|
52 | + public function patch(ServerRequestInterface $request, ResponseInterface $response); |
|
53 | 53 | |
54 | 54 | |
55 | 55 | /** |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * @param \Psr\Http\Message\ResponseInterface $response Response object |
60 | 60 | * @return \Psr\Http\Message\ResponseInterface Modified response object |
61 | 61 | */ |
62 | - public function post( ServerRequestInterface $request, ResponseInterface $response ); |
|
62 | + public function post(ServerRequestInterface $request, ResponseInterface $response); |
|
63 | 63 | |
64 | 64 | |
65 | 65 | /** |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * @param \Psr\Http\Message\ResponseInterface $response Response object |
70 | 70 | * @return \Psr\Http\Message\ResponseInterface Modified response object |
71 | 71 | */ |
72 | - public function put( ServerRequestInterface $request, ResponseInterface $response ); |
|
72 | + public function put(ServerRequestInterface $request, ResponseInterface $response); |
|
73 | 73 | |
74 | 74 | |
75 | 75 | /** |
@@ -80,5 +80,5 @@ discard block |
||
80 | 80 | * @param string|null Form parameter prefix when nesting parameters is required |
81 | 81 | * @return \Psr\Http\Message\ResponseInterface Modified response object |
82 | 82 | */ |
83 | - public function options( ServerRequestInterface $request, ResponseInterface $response, $prefix = null ); |
|
83 | + public function options(ServerRequestInterface $request, ResponseInterface $response, $prefix = null); |
|
84 | 84 | } |