@@ -8,37 +8,37 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | |
11 | -$target = $this->config( 'client/jsonapi/url/target' ); |
|
12 | -$cntl = $this->config( 'client/jsonapi/url/controller', 'jsonapi' ); |
|
13 | -$action = $this->config( 'client/jsonapi/url/action', 'get' ); |
|
14 | -$config = $this->config( 'client/jsonapi/url/config', array() ); |
|
11 | +$target = $this->config('client/jsonapi/url/target'); |
|
12 | +$cntl = $this->config('client/jsonapi/url/controller', 'jsonapi'); |
|
13 | +$action = $this->config('client/jsonapi/url/action', 'get'); |
|
14 | +$config = $this->config('client/jsonapi/url/config', array()); |
|
15 | 15 | |
16 | 16 | |
17 | 17 | $view = $this; |
18 | 18 | $enc = $this->encoder(); |
19 | 19 | |
20 | -$ref = array( 'id', 'resource', 'filter', 'page', 'sort', 'include', 'fields' ); |
|
21 | -$params = array_intersect_key( $this->param(), array_flip( $ref ) ); |
|
20 | +$ref = array('id', 'resource', 'filter', 'page', 'sort', 'include', 'fields'); |
|
21 | +$params = array_intersect_key($this->param(), array_flip($ref)); |
|
22 | 22 | |
23 | -$offset = max( $this->param( 'page/offset', 0 ), 0 ); |
|
24 | -$limit = max( $this->param( 'page/limit', 100 ), 1 ); |
|
23 | +$offset = max($this->param('page/offset', 0), 0); |
|
24 | +$limit = max($this->param('page/limit', 100), 1); |
|
25 | 25 | |
26 | 26 | |
27 | -$fields = $this->param( 'fields', array() ); |
|
27 | +$fields = $this->param('fields', array()); |
|
28 | 28 | |
29 | -foreach( (array) $fields as $resource => $list ) { |
|
30 | - $fields[$resource] = array_flip( explode( ',', $list ) ); |
|
29 | +foreach ((array) $fields as $resource => $list) { |
|
30 | + $fields[$resource] = array_flip(explode(',', $list)); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | |
34 | -$entryFcn = function( \Aimeos\MShop\Locale\Item\Iface $item ) use ( $fields, $view, $target, $cntl, $action, $config ) |
|
34 | +$entryFcn = function(\Aimeos\MShop\Locale\Item\Iface $item) use ($fields, $view, $target, $cntl, $action, $config) |
|
35 | 35 | { |
36 | 36 | $attributes = $item->toArray(); |
37 | 37 | $type = $item->getResourceType(); |
38 | - $params = array( 'resource' => $type, 'id' => $item->getId() ); |
|
38 | + $params = array('resource' => $type, 'id' => $item->getId()); |
|
39 | 39 | |
40 | - if( isset( $fields[$type] ) ) { |
|
41 | - $attributes = array_intersect_key( $attributes, $fields[$type] ); |
|
40 | + if (isset($fields[$type])) { |
|
41 | + $attributes = array_intersect_key($attributes, $fields[$type]); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | $entry = array( |
@@ -46,8 +46,8 @@ discard block |
||
46 | 46 | 'type' => $item->getResourceType(), |
47 | 47 | 'links' => array( |
48 | 48 | 'self' => array( |
49 | - 'href' => $view->url( $target, $cntl, $action, $params, array(), $config ), |
|
50 | - 'allow' => array( 'GET' ), |
|
49 | + 'href' => $view->url($target, $cntl, $action, $params, array(), $config), |
|
50 | + 'allow' => array('GET'), |
|
51 | 51 | ), |
52 | 52 | ), |
53 | 53 | 'attributes' => $attributes, |
@@ -60,37 +60,37 @@ discard block |
||
60 | 60 | ?> |
61 | 61 | { |
62 | 62 | "meta": { |
63 | - "total": <?php echo $this->get( 'total', 0 ); ?> |
|
63 | + "total": <?php echo $this->get('total', 0); ?> |
|
64 | 64 | |
65 | 65 | }, |
66 | 66 | |
67 | 67 | "links": { |
68 | - "self": "<?php echo $this->url( $target, $cntl, $action, $params, array(), $config ); ?>" |
|
68 | + "self": "<?php echo $this->url($target, $cntl, $action, $params, array(), $config); ?>" |
|
69 | 69 | }, |
70 | 70 | |
71 | - <?php if( isset( $this->errors ) ) : ?> |
|
71 | + <?php if (isset($this->errors)) : ?> |
|
72 | 72 | |
73 | - "errors": <?php echo json_encode( $this->errors, JSON_PRETTY_PRINT ); ?> |
|
73 | + "errors": <?php echo json_encode($this->errors, JSON_PRETTY_PRINT); ?> |
|
74 | 74 | |
75 | - <?php elseif( isset( $this->items ) ) : ?> |
|
75 | + <?php elseif (isset($this->items)) : ?> |
|
76 | 76 | |
77 | 77 | <?php |
78 | 78 | $data = []; |
79 | - $items = $this->get( 'items', [] ); |
|
79 | + $items = $this->get('items', []); |
|
80 | 80 | |
81 | - if( is_array( $items ) ) |
|
81 | + if (is_array($items)) |
|
82 | 82 | { |
83 | - foreach( $items as $localeItem ) { |
|
84 | - $data[] = $entryFcn( $localeItem ); |
|
83 | + foreach ($items as $localeItem) { |
|
84 | + $data[] = $entryFcn($localeItem); |
|
85 | 85 | } |
86 | 86 | } |
87 | 87 | else |
88 | 88 | { |
89 | - $data = $entryFcn( $items ); |
|
89 | + $data = $entryFcn($items); |
|
90 | 90 | } |
91 | 91 | ?> |
92 | 92 | |
93 | - "data": <?php echo json_encode( $data ); ?> |
|
93 | + "data": <?php echo json_encode($data); ?> |
|
94 | 94 | |
95 | 95 | <?php endif; ?> |
96 | 96 |
@@ -83,8 +83,7 @@ |
||
83 | 83 | foreach( $items as $localeItem ) { |
84 | 84 | $data[] = $entryFcn( $localeItem ); |
85 | 85 | } |
86 | - } |
|
87 | - else |
|
86 | + } else |
|
88 | 87 | { |
89 | 88 | $data = $entryFcn( $items ); |
90 | 89 | } |
@@ -16,8 +16,8 @@ discard block |
||
16 | 16 | $context = \TestHelperJapi::getContext(); |
17 | 17 | $templatePaths = \TestHelperJapi::getTemplatePaths(); |
18 | 18 | |
19 | - $client = \Aimeos\Client\JsonApi\Locale\Factory::createClient( $context, $templatePaths, 'locale' ); |
|
20 | - $this->assertInstanceOf( '\Aimeos\Client\JsonApi\Iface', $client ); |
|
19 | + $client = \Aimeos\Client\JsonApi\Locale\Factory::createClient($context, $templatePaths, 'locale'); |
|
20 | + $this->assertInstanceOf('\Aimeos\Client\JsonApi\Iface', $client); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | |
@@ -26,8 +26,8 @@ discard block |
||
26 | 26 | $context = \TestHelperJapi::getContext(); |
27 | 27 | $templatePaths = \TestHelperJapi::getTemplatePaths(); |
28 | 28 | |
29 | - $this->setExpectedException( '\Aimeos\Client\JsonApi\Exception' ); |
|
30 | - \Aimeos\Client\JsonApi\Locale\Factory::createClient( $context, $templatePaths, '' ); |
|
29 | + $this->setExpectedException('\Aimeos\Client\JsonApi\Exception'); |
|
30 | + \Aimeos\Client\JsonApi\Locale\Factory::createClient($context, $templatePaths, ''); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | |
@@ -36,8 +36,8 @@ discard block |
||
36 | 36 | $context = \TestHelperJapi::getContext(); |
37 | 37 | $templatePaths = \TestHelperJapi::getTemplatePaths(); |
38 | 38 | |
39 | - $this->setExpectedException( '\Aimeos\Client\JsonApi\Exception' ); |
|
40 | - \Aimeos\Client\JsonApi\Locale\Factory::createClient( $context, $templatePaths, '%^' ); |
|
39 | + $this->setExpectedException('\Aimeos\Client\JsonApi\Exception'); |
|
40 | + \Aimeos\Client\JsonApi\Locale\Factory::createClient($context, $templatePaths, '%^'); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | $context = \TestHelperJapi::getContext(); |
47 | 47 | $templatePaths = \TestHelperJapi::getTemplatePaths(); |
48 | 48 | |
49 | - $this->setExpectedException( '\Aimeos\Client\JsonApi\Exception' ); |
|
50 | - \Aimeos\Client\JsonApi\Locale\Factory::createClient( $context, $templatePaths, 'locale', '%^' ); |
|
49 | + $this->setExpectedException('\Aimeos\Client\JsonApi\Exception'); |
|
50 | + \Aimeos\Client\JsonApi\Locale\Factory::createClient($context, $templatePaths, 'locale', '%^'); |
|
51 | 51 | } |
52 | 52 | } |
53 | 53 | \ No newline at end of file |
@@ -22,20 +22,20 @@ discard block |
||
22 | 22 | $templatePaths = \TestHelperJapi::getTemplatePaths(); |
23 | 23 | $this->view = $this->context->getView(); |
24 | 24 | |
25 | - $this->object = new \Aimeos\Client\JsonApi\Locale\Standard( $this->context, $this->view, $templatePaths, 'locale' ); |
|
25 | + $this->object = new \Aimeos\Client\JsonApi\Locale\Standard($this->context, $this->view, $templatePaths, 'locale'); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | |
29 | 29 | public function testGetItem() |
30 | 30 | { |
31 | - $localeManager = \Aimeos\MShop\Factory::createManager( $this->context, 'locale' ); |
|
31 | + $localeManager = \Aimeos\MShop\Factory::createManager($this->context, 'locale'); |
|
32 | 32 | $search = $localeManager->createSearch(); |
33 | - $search->setSortations( [$search->sort( '+', 'locale.position' )] ); |
|
34 | - $search->setSlice( 0, 1 ); |
|
35 | - $localeItems = $localeManager->searchItems( $search ); |
|
33 | + $search->setSortations([$search->sort('+', 'locale.position')]); |
|
34 | + $search->setSlice(0, 1); |
|
35 | + $localeItems = $localeManager->searchItems($search); |
|
36 | 36 | |
37 | - if( ( $localeItem = reset( $localeItems ) ) === false ) { |
|
38 | - throw new \Exception( 'No locale item found' ); |
|
37 | + if (($localeItem = reset($localeItems)) === false) { |
|
38 | + throw new \Exception('No locale item found'); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | |
@@ -46,24 +46,24 @@ discard block |
||
46 | 46 | ) |
47 | 47 | ); |
48 | 48 | |
49 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
50 | - $this->view->addHelper( 'param', $helper ); |
|
49 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
50 | + $this->view->addHelper('param', $helper); |
|
51 | 51 | |
52 | - $response = $this->object->get( $this->view->request(), $this->view->response() ); |
|
53 | - $result = json_decode( (string) $response->getBody(), true ); |
|
52 | + $response = $this->object->get($this->view->request(), $this->view->response()); |
|
53 | + $result = json_decode((string) $response->getBody(), true); |
|
54 | 54 | |
55 | 55 | |
56 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
57 | - $this->assertEquals( 1, count( $response->getHeader( 'Allow' ) ) ); |
|
58 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
56 | + $this->assertEquals(200, $response->getStatusCode()); |
|
57 | + $this->assertEquals(1, count($response->getHeader('Allow'))); |
|
58 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
59 | 59 | |
60 | - $this->assertEquals( 1, $result['meta']['total'] ); |
|
61 | - $this->assertEquals( 'locale', $result['data']['type'] ); |
|
62 | - $this->assertGreaterThan( 0, $result['data']['attributes']['locale.id'] ); |
|
63 | - $this->assertEquals( 'de', $result['data']['attributes']['locale.languageid'] ); |
|
64 | - $this->assertEquals( 'EUR', $result['data']['attributes']['locale.currencyid'] ); |
|
60 | + $this->assertEquals(1, $result['meta']['total']); |
|
61 | + $this->assertEquals('locale', $result['data']['type']); |
|
62 | + $this->assertGreaterThan(0, $result['data']['attributes']['locale.id']); |
|
63 | + $this->assertEquals('de', $result['data']['attributes']['locale.languageid']); |
|
64 | + $this->assertEquals('EUR', $result['data']['attributes']['locale.currencyid']); |
|
65 | 65 | |
66 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
66 | + $this->assertArrayNotHasKey('errors', $result); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | |
@@ -75,25 +75,25 @@ discard block |
||
75 | 75 | ), |
76 | 76 | 'sort' => 'locale.position', |
77 | 77 | ); |
78 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
79 | - $this->view->addHelper( 'param', $helper ); |
|
78 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
79 | + $this->view->addHelper('param', $helper); |
|
80 | 80 | |
81 | - $response = $this->object->get( $this->view->request(), $this->view->response() ); |
|
82 | - $result = json_decode( (string) $response->getBody(), true ); |
|
81 | + $response = $this->object->get($this->view->request(), $this->view->response()); |
|
82 | + $result = json_decode((string) $response->getBody(), true); |
|
83 | 83 | |
84 | 84 | |
85 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
86 | - $this->assertEquals( 1, count( $response->getHeader( 'Allow' ) ) ); |
|
87 | - $this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) ); |
|
85 | + $this->assertEquals(200, $response->getStatusCode()); |
|
86 | + $this->assertEquals(1, count($response->getHeader('Allow'))); |
|
87 | + $this->assertEquals(1, count($response->getHeader('Content-Type'))); |
|
88 | 88 | |
89 | - $this->assertEquals( 1, $result['meta']['total'] ); |
|
90 | - $this->assertEquals( 1, count( $result['data'] ) ); |
|
91 | - $this->assertEquals( 'locale', $result['data'][0]['type'] ); |
|
92 | - $this->assertEquals( 3, count( $result['data'][0]['attributes'] ) ); |
|
93 | - $this->assertEquals( 'en', $result['data'][0]['attributes']['locale.languageid'] ); |
|
94 | - $this->assertEquals( 'EUR', $result['data'][0]['attributes']['locale.currencyid'] ); |
|
89 | + $this->assertEquals(1, $result['meta']['total']); |
|
90 | + $this->assertEquals(1, count($result['data'])); |
|
91 | + $this->assertEquals('locale', $result['data'][0]['type']); |
|
92 | + $this->assertEquals(3, count($result['data'][0]['attributes'])); |
|
93 | + $this->assertEquals('en', $result['data'][0]['attributes']['locale.languageid']); |
|
94 | + $this->assertEquals('EUR', $result['data'][0]['attributes']['locale.currencyid']); |
|
95 | 95 | |
96 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
96 | + $this->assertArrayNotHasKey('errors', $result); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | |
@@ -101,20 +101,20 @@ discard block |
||
101 | 101 | { |
102 | 102 | $params = array( |
103 | 103 | 'filter' => array( |
104 | - '>=' => array( 'locale.position' => 0 ), |
|
104 | + '>=' => array('locale.position' => 0), |
|
105 | 105 | ), |
106 | 106 | 'sort' => '-locale.position', |
107 | 107 | ); |
108 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
109 | - $this->view->addHelper( 'param', $helper ); |
|
108 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
109 | + $this->view->addHelper('param', $helper); |
|
110 | 110 | |
111 | - $response = $this->object->get( $this->view->request(), $this->view->response() ); |
|
112 | - $result = json_decode( (string) $response->getBody(), true ); |
|
111 | + $response = $this->object->get($this->view->request(), $this->view->response()); |
|
112 | + $result = json_decode((string) $response->getBody(), true); |
|
113 | 113 | |
114 | 114 | |
115 | - $this->assertEquals( 200, $response->getStatusCode() ); |
|
116 | - $this->assertEquals( 1, $result['meta']['total'] ); |
|
117 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
115 | + $this->assertEquals(200, $response->getStatusCode()); |
|
116 | + $this->assertEquals(1, $result['meta']['total']); |
|
117 | + $this->assertArrayNotHasKey('errors', $result); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | |
@@ -122,21 +122,21 @@ discard block |
||
122 | 122 | { |
123 | 123 | $templatePaths = \TestHelperJapi::getTemplatePaths(); |
124 | 124 | |
125 | - $object = $this->getMockBuilder( '\Aimeos\Client\JsonApi\Locale\Standard' ) |
|
126 | - ->setConstructorArgs( [$this->context, $this->view, $templatePaths, 'locale'] ) |
|
127 | - ->setMethods( ['getItems'] ) |
|
125 | + $object = $this->getMockBuilder('\Aimeos\Client\JsonApi\Locale\Standard') |
|
126 | + ->setConstructorArgs([$this->context, $this->view, $templatePaths, 'locale']) |
|
127 | + ->setMethods(['getItems']) |
|
128 | 128 | ->getMock(); |
129 | 129 | |
130 | - $object->expects( $this->once() )->method( 'getItems' ) |
|
131 | - ->will( $this->throwException( new \Aimeos\MShop\Exception() ) ); |
|
130 | + $object->expects($this->once())->method('getItems') |
|
131 | + ->will($this->throwException(new \Aimeos\MShop\Exception())); |
|
132 | 132 | |
133 | 133 | |
134 | - $response = $object->get( $this->view->request(), $this->view->response() ); |
|
135 | - $result = json_decode( (string) $response->getBody(), true ); |
|
134 | + $response = $object->get($this->view->request(), $this->view->response()); |
|
135 | + $result = json_decode((string) $response->getBody(), true); |
|
136 | 136 | |
137 | 137 | |
138 | - $this->assertEquals( 404, $response->getStatusCode() ); |
|
139 | - $this->assertArrayHasKey( 'errors', $result ); |
|
138 | + $this->assertEquals(404, $response->getStatusCode()); |
|
139 | + $this->assertArrayHasKey('errors', $result); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | |
@@ -144,20 +144,20 @@ discard block |
||
144 | 144 | { |
145 | 145 | $templatePaths = \TestHelperJapi::getTemplatePaths(); |
146 | 146 | |
147 | - $object = $this->getMockBuilder( '\Aimeos\Client\JsonApi\Locale\Standard' ) |
|
148 | - ->setConstructorArgs( [$this->context, $this->view, $templatePaths, 'locale'] ) |
|
149 | - ->setMethods( ['getItems'] ) |
|
147 | + $object = $this->getMockBuilder('\Aimeos\Client\JsonApi\Locale\Standard') |
|
148 | + ->setConstructorArgs([$this->context, $this->view, $templatePaths, 'locale']) |
|
149 | + ->setMethods(['getItems']) |
|
150 | 150 | ->getMock(); |
151 | 151 | |
152 | - $object->expects( $this->once() )->method( 'getItems' ) |
|
153 | - ->will( $this->throwException( new \Exception() ) ); |
|
152 | + $object->expects($this->once())->method('getItems') |
|
153 | + ->will($this->throwException(new \Exception())); |
|
154 | 154 | |
155 | 155 | |
156 | - $response = $object->get( $this->view->request(), $this->view->response() ); |
|
157 | - $result = json_decode( (string) $response->getBody(), true ); |
|
156 | + $response = $object->get($this->view->request(), $this->view->response()); |
|
157 | + $result = json_decode((string) $response->getBody(), true); |
|
158 | 158 | |
159 | 159 | |
160 | - $this->assertEquals( 500, $response->getStatusCode() ); |
|
161 | - $this->assertArrayHasKey( 'errors', $result ); |
|
160 | + $this->assertEquals(500, $response->getStatusCode()); |
|
161 | + $this->assertArrayHasKey('errors', $result); |
|
162 | 162 | } |
163 | 163 | } |
164 | 164 | \ No newline at end of file |