Completed
Push — master ( 9ee11d...42e540 )
by Aimeos
02:00
created
admin/jsonadm/tests/Admin/JsonAdm/Locale/Site/StandardTest.php 1 patch
Spacing   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -22,32 +22,32 @@  discard block
 block discarded – undo
22 22
 		$this->context = \TestHelperJadm::getContext();
23 23
 		$this->view = $this->context->getView();
24 24
 
25
-		$this->object = new \Aimeos\Admin\JsonAdm\Locale\Site\Standard( $this->context, $this->view, $templatePaths, 'locale/site' );
25
+		$this->object = new \Aimeos\Admin\JsonAdm\Locale\Site\Standard($this->context, $this->view, $templatePaths, 'locale/site');
26 26
 	}
27 27
 
28 28
 
29 29
 	public function testGet()
30 30
 	{
31 31
 		$params = array(
32
-			'id' => $this->getSiteItem( 'unittest' )->getId(),
32
+			'id' => $this->getSiteItem('unittest')->getId(),
33 33
 			'filter' => array(
34
-				'==' => array( 'locale.status' => 0 )
34
+				'==' => array('locale.status' => 0)
35 35
 			),
36 36
 		);
37
-		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params );
38
-		$this->view->addHelper( 'param', $helper );
37
+		$helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params);
38
+		$this->view->addHelper('param', $helper);
39 39
 
40
-		$response = $this->object->get( $this->view->request(), $this->view->response() );
41
-		$result = json_decode( (string) $response->getBody(), true );
40
+		$response = $this->object->get($this->view->request(), $this->view->response());
41
+		$result = json_decode((string) $response->getBody(), true);
42 42
 
43 43
 
44
-		$this->assertEquals( 200, $response->getStatusCode() );
45
-		$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) );
44
+		$this->assertEquals(200, $response->getStatusCode());
45
+		$this->assertEquals(1, count($response->getHeader('Content-Type')));
46 46
 
47
-		$this->assertEquals( 1, $result['meta']['total'] );
48
-		$this->assertEquals( 'locale/site', $result['data']['type'] );
47
+		$this->assertEquals(1, $result['meta']['total']);
48
+		$this->assertEquals('locale/site', $result['data']['type']);
49 49
 
50
-		$this->assertArrayNotHasKey( 'errors', $result );
50
+		$this->assertArrayNotHasKey('errors', $result);
51 51
 	}
52 52
 
53 53
 
@@ -55,125 +55,125 @@  discard block
 block discarded – undo
55 55
 	{
56 56
 		$params = array(
57 57
 			'filter' => array(
58
-				'==' => array( 'locale.site.code' => 'unittest' )
58
+				'==' => array('locale.site.code' => 'unittest')
59 59
 			),
60 60
 		);
61
-		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params );
62
-		$this->view->addHelper( 'param', $helper );
61
+		$helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params);
62
+		$this->view->addHelper('param', $helper);
63 63
 
64
-		$response = $this->object->get( $this->view->request(), $this->view->response() );
65
-		$result = json_decode( (string) $response->getBody(), true );
64
+		$response = $this->object->get($this->view->request(), $this->view->response());
65
+		$result = json_decode((string) $response->getBody(), true);
66 66
 
67 67
 
68
-		$this->assertEquals( 200, $response->getStatusCode() );
69
-		$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) );
68
+		$this->assertEquals(200, $response->getStatusCode());
69
+		$this->assertEquals(1, count($response->getHeader('Content-Type')));
70 70
 
71
-		$this->assertEquals( 1, $result['meta']['total'] );
72
-		$this->assertEquals( 1, count( $result['data'] ) );
73
-		$this->assertEquals( 'locale/site', $result['data'][0]['type'] );
71
+		$this->assertEquals(1, $result['meta']['total']);
72
+		$this->assertEquals(1, count($result['data']));
73
+		$this->assertEquals('locale/site', $result['data'][0]['type']);
74 74
 
75
-		$this->assertArrayNotHasKey( 'errors', $result );
75
+		$this->assertArrayNotHasKey('errors', $result);
76 76
 	}
77 77
 
78 78
 
79 79
 	public function testPatch()
80 80
 	{
81
-		$stub = $this->getSiteMock( array( 'getItem', 'moveItem', 'saveItem' ) );
81
+		$stub = $this->getSiteMock(array('getItem', 'moveItem', 'saveItem'));
82 82
 		$item = $stub->createItem();
83 83
 
84
-		$stub->expects( $this->once() )->method( 'moveItem' );
85
-		$stub->expects( $this->once() )->method( 'saveItem' )
86
-			->will( $this->returnValue( $stub->createItem() ) );
87
-		$stub->expects( $this->exactly( 2 ) )->method( 'getItem' ) // 2x due to decorator
88
-			->will( $this->returnValue( $item ) );
84
+		$stub->expects($this->once())->method('moveItem');
85
+		$stub->expects($this->once())->method('saveItem')
86
+			->will($this->returnValue($stub->createItem()));
87
+		$stub->expects($this->exactly(2))->method('getItem') // 2x due to decorator
88
+			->will($this->returnValue($item));
89 89
 
90 90
 
91
-		$params = array( 'id' => '-1' );
92
-		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params );
93
-		$this->view->addHelper( 'param', $helper );
91
+		$params = array('id' => '-1');
92
+		$helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params);
93
+		$this->view->addHelper('param', $helper);
94 94
 
95 95
 		$body = '{"data": {"parentid": "1", "targetid": 2, "type": "locale/site", "attributes": {"locale.site.label": "test"}}}';
96
-		$request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) );
96
+		$request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body));
97 97
 
98
-		$response = $this->object->patch( $request, $this->view->response() );
99
-		$result = json_decode( (string) $response->getBody(), true );
98
+		$response = $this->object->patch($request, $this->view->response());
99
+		$result = json_decode((string) $response->getBody(), true);
100 100
 
101 101
 
102
-		$this->assertEquals( 200, $response->getStatusCode() );
103
-		$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) );
102
+		$this->assertEquals(200, $response->getStatusCode());
103
+		$this->assertEquals(1, count($response->getHeader('Content-Type')));
104 104
 
105
-		$this->assertEquals( 1, $result['meta']['total'] );
106
-		$this->assertArrayHasKey( 'data', $result );
107
-		$this->assertEquals( 'locale/site', $result['data']['type'] );
105
+		$this->assertEquals(1, $result['meta']['total']);
106
+		$this->assertArrayHasKey('data', $result);
107
+		$this->assertEquals('locale/site', $result['data']['type']);
108 108
 
109
-		$this->assertArrayNotHasKey( 'included', $result );
110
-		$this->assertArrayNotHasKey( 'errors', $result );
109
+		$this->assertArrayNotHasKey('included', $result);
110
+		$this->assertArrayNotHasKey('errors', $result);
111 111
 	}
112 112
 
113 113
 
114 114
 	public function testPost()
115 115
 	{
116
-		$stub = $this->getSiteMock( array( 'getItem', 'insertItem' ) );
116
+		$stub = $this->getSiteMock(array('getItem', 'insertItem'));
117 117
 		$item = $stub->createItem();
118 118
 
119
-		$stub->expects( $this->any() )->method( 'getItem' )
120
-			->will( $this->returnValue( $item ) );
121
-		$stub->expects( $this->once() )->method( 'insertItem' );
119
+		$stub->expects($this->any())->method('getItem')
120
+			->will($this->returnValue($item));
121
+		$stub->expects($this->once())->method('insertItem');
122 122
 
123 123
 
124 124
 		$body = '{"data": {"type": "locale/site", "attributes": {"locale.site.code": "unittest", "locale.site.label": "Unit test"}}}';
125
-		$request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) );
125
+		$request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body));
126 126
 
127
-		$response = $this->object->post( $request, $this->view->response() );
128
-		$result = json_decode( (string) $response->getBody(), true );
127
+		$response = $this->object->post($request, $this->view->response());
128
+		$result = json_decode((string) $response->getBody(), true);
129 129
 
130 130
 
131
-		$this->assertEquals( 201, $response->getStatusCode() );
132
-		$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) );
131
+		$this->assertEquals(201, $response->getStatusCode());
132
+		$this->assertEquals(1, count($response->getHeader('Content-Type')));
133 133
 
134
-		$this->assertEquals( 1, $result['meta']['total'] );
135
-		$this->assertArrayHasKey( 'data', $result );
136
-		$this->assertEquals( 'locale/site', $result['data']['type'] );
134
+		$this->assertEquals(1, $result['meta']['total']);
135
+		$this->assertArrayHasKey('data', $result);
136
+		$this->assertEquals('locale/site', $result['data']['type']);
137 137
 
138
-		$this->assertArrayNotHasKey( 'included', $result );
139
-		$this->assertArrayNotHasKey( 'errors', $result );
138
+		$this->assertArrayNotHasKey('included', $result);
139
+		$this->assertArrayNotHasKey('errors', $result);
140 140
 	}
141 141
 
142 142
 
143
-	protected function getSiteItem( $code )
143
+	protected function getSiteItem($code)
144 144
 	{
145
-		$manager = \Aimeos\MShop\Locale\Manager\Factory::createManager( $this->context )->getSubManager( 'site' );
145
+		$manager = \Aimeos\MShop\Locale\Manager\Factory::createManager($this->context)->getSubManager('site');
146 146
 		$search = $manager->createSearch();
147
-		$search->setConditions( $search->compare( '==', 'locale.site.code', $code ) );
148
-		$items = $manager->searchItems( $search );
147
+		$search->setConditions($search->compare('==', 'locale.site.code', $code));
148
+		$items = $manager->searchItems($search);
149 149
 
150
-		if( ( $item = reset( $items ) ) === false ) {
151
-			throw new \RuntimeException( sprintf( 'No locale site item with code "%1$s" found', $code ) );
150
+		if (($item = reset($items)) === false) {
151
+			throw new \RuntimeException(sprintf('No locale site item with code "%1$s" found', $code));
152 152
 		}
153 153
 
154 154
 		return $item;
155 155
 	}
156 156
 
157 157
 
158
-	protected function getSiteMock( array $methods )
158
+	protected function getSiteMock(array $methods)
159 159
 	{
160 160
 		$name = 'ClientJsonAdmStandard';
161
-		$this->context->getConfig()->set( 'mshop/locale/manager/name', $name );
161
+		$this->context->getConfig()->set('mshop/locale/manager/name', $name);
162 162
 
163
-		$stub = $this->getMockBuilder( '\\Aimeos\\MShop\\Locale\\Manager\\Standard' )
164
-			->setConstructorArgs( array( $this->context ) )
165
-			->setMethods( array( 'getSubManager' ) )
163
+		$stub = $this->getMockBuilder('\\Aimeos\\MShop\\Locale\\Manager\\Standard')
164
+			->setConstructorArgs(array($this->context))
165
+			->setMethods(array('getSubManager'))
166 166
 			->getMock();
167 167
 
168
-		$siteStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Locale\\Manager\\Site\\Standard' )
169
-			->setConstructorArgs( array( $this->context ) )
170
-			->setMethods( $methods )
168
+		$siteStub = $this->getMockBuilder('\\Aimeos\\MShop\\Locale\\Manager\\Site\\Standard')
169
+			->setConstructorArgs(array($this->context))
170
+			->setMethods($methods)
171 171
 			->getMock();
172 172
 
173
-		$stub->expects( $this->once() )->method( 'getSubManager' )
174
-			->will( $this->returnValue( $siteStub ) );
173
+		$stub->expects($this->once())->method('getSubManager')
174
+			->will($this->returnValue($siteStub));
175 175
 
176
-		\Aimeos\MShop\Locale\Manager\Factory::injectManager( '\\Aimeos\\MShop\\Locale\\Manager\\' . $name, $stub );
176
+		\Aimeos\MShop\Locale\Manager\Factory::injectManager('\\Aimeos\\MShop\\Locale\\Manager\\' . $name, $stub);
177 177
 
178 178
 		return $siteStub;
179 179
 	}
Please login to merge, or discard this patch.
admin/jsonadm/src/Admin/JsonAdm/Locale/Site/Standard.php 2 patches
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	 * @param \Psr\Http\Message\ResponseInterface $response Response object
111 111
 	 * @return \Psr\Http\Message\ResponseInterface Modified response object
112 112
 	 */
113
-	public function get( ServerRequestInterface $request, ResponseInterface $response )
113
+	public function get(ServerRequestInterface $request, ResponseInterface $response)
114 114
 	{
115 115
 		/** admin/jsonadm/partials/locale/site/template-data
116 116
 		 * Relative path to the data partial template file for the locale site  client
@@ -127,9 +127,9 @@  discard block
 block discarded – undo
127 127
 		 * @since 2016.07
128 128
 		 * @category Developer
129 129
 		 */
130
-		$this->getView()->assign( array( 'partial-data' => 'admin/jsonadm/partials/locale/site/template-data' ) );
130
+		$this->getView()->assign(array('partial-data' => 'admin/jsonadm/partials/locale/site/template-data'));
131 131
 
132
-		return parent::get( $request, $response );
132
+		return parent::get($request, $response);
133 133
 	}
134 134
 
135 135
 
@@ -141,18 +141,18 @@  discard block
 block discarded – undo
141 141
 	 * @param \Psr\Http\Message\ResponseInterface $response Response object
142 142
 	 * @return \Psr\Http\Message\ResponseInterface Modified response object
143 143
 	 */
144
-	protected function getItems( \Aimeos\MW\View\Iface $view, ServerRequestInterface $request, ResponseInterface $response )
144
+	protected function getItems(\Aimeos\MW\View\Iface $view, ServerRequestInterface $request, ResponseInterface $response)
145 145
 	{
146
-		$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'locale/site' );
146
+		$manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'locale/site');
147 147
 
148
-		$include = ( ( $include = $view->param( 'include' ) ) !== null ? explode( ',', $include ) : [] );
149
-		$search = $this->initCriteria( $manager->createSearch(), $view->param() );
148
+		$include = (($include = $view->param('include')) !== null ? explode(',', $include) : []);
149
+		$search = $this->initCriteria($manager->createSearch(), $view->param());
150 150
 		$total = 1;
151 151
 
152
-		if( ( $id = $view->param( 'id' ) ) == null ) {
153
-			$view->data = $manager->searchItems( $search, [], $total );
152
+		if (($id = $view->param('id')) == null) {
153
+			$view->data = $manager->searchItems($search, [], $total);
154 154
 		} else {
155
-			$view->data = $manager->getTree( $id, [], \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE, $search );
155
+			$view->data = $manager->getTree($id, [], \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE, $search);
156 156
 		}
157 157
 
158 158
 		$view->childItems = [];
@@ -171,32 +171,32 @@  discard block
 block discarded – undo
171 171
 	 * @param \stdClass $entry Object including "id" and "attributes" elements
172 172
 	 * @return \Aimeos\MShop\Common\Item\Iface New or updated item
173 173
 	 */
174
-	protected function saveEntry( \Aimeos\MShop\Common\Manager\Iface $manager, \stdClass $entry )
174
+	protected function saveEntry(\Aimeos\MShop\Common\Manager\Iface $manager, \stdClass $entry)
175 175
 	{
176
-		$targetId = ( isset( $entry->targetid ) ? $entry->targetid : null );
177
-		$refId = ( isset( $entry->refid ) ? $entry->refid : null );
176
+		$targetId = (isset($entry->targetid) ? $entry->targetid : null);
177
+		$refId = (isset($entry->refid) ? $entry->refid : null);
178 178
 
179
-		if( isset( $entry->id ) )
179
+		if (isset($entry->id))
180 180
 		{
181
-			$item = $manager->getItem( $entry->id );
182
-			$item = $this->addItemData( $manager, $item, $entry, $item->getResourceType() );
183
-			$item = $manager->saveItem( $item );
181
+			$item = $manager->getItem($entry->id);
182
+			$item = $this->addItemData($manager, $item, $entry, $item->getResourceType());
183
+			$item = $manager->saveItem($item);
184 184
 
185
-			if( isset( $entry->parentid ) && $targetId !== null ) {
186
-				$manager->moveItem( $item->getId(), $entry->parentid, $targetId, $refId );
185
+			if (isset($entry->parentid) && $targetId !== null) {
186
+				$manager->moveItem($item->getId(), $entry->parentid, $targetId, $refId);
187 187
 			}
188 188
 		}
189 189
 		else
190 190
 		{
191 191
 			$item = $manager->createItem();
192
-			$item = $this->addItemData( $manager, $item, $entry, $item->getResourceType() );
193
-			$manager->insertItem( $item, $targetId, $refId );
192
+			$item = $this->addItemData($manager, $item, $entry, $item->getResourceType());
193
+			$manager->insertItem($item, $targetId, $refId);
194 194
 		}
195 195
 
196
-		if( isset( $entry->relationships ) ) {
197
-			$this->saveRelationships( $manager, $item, $entry->relationships );
196
+		if (isset($entry->relationships)) {
197
+			$this->saveRelationships($manager, $item, $entry->relationships);
198 198
 		}
199 199
 
200
-		return $manager->getItem( $item->getId() );
200
+		return $manager->getItem($item->getId());
201 201
 	}
202 202
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -185,8 +185,7 @@
 block discarded – undo
185 185
 			if( isset( $entry->parentid ) && $targetId !== null ) {
186 186
 				$manager->moveItem( $item->getId(), $entry->parentid, $targetId, $refId );
187 187
 			}
188
-		}
189
-		else
188
+		} else
190 189
 		{
191 190
 			$item = $manager->createItem();
192 191
 			$item = $this->addItemData( $manager, $item, $entry, $item->getResourceType() );
Please login to merge, or discard this patch.