Completed
Push — master ( ba482a...3f4395 )
by Aimeos
01:54
created
admin/jsonadm/tests/Admin/JsonAdm/Locale/Site/StandardTest.php 1 patch
Spacing   +72 added lines, -72 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,124 +55,124 @@  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( 'saveItem' )
85
-			->will( $this->returnValue( $stub->createItem() ) );
86
-		$stub->expects( $this->exactly( 2 ) )->method( 'getItem' ) // 2x due to decorator
87
-			->will( $this->returnValue( $item ) );
84
+		$stub->expects($this->once())->method('saveItem')
85
+			->will($this->returnValue($stub->createItem()));
86
+		$stub->expects($this->exactly(2))->method('getItem') // 2x due to decorator
87
+			->will($this->returnValue($item));
88 88
 
89 89
 
90
-		$params = array( 'id' => '-1' );
91
-		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params );
92
-		$this->view->addHelper( 'param', $helper );
90
+		$params = array('id' => '-1');
91
+		$helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params);
92
+		$this->view->addHelper('param', $helper);
93 93
 
94 94
 		$body = '{"data": {"parentid": "1", "targetid": 2, "type": "locale/site", "attributes": {"locale.site.label": "test"}}}';
95
-		$request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) );
95
+		$request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body));
96 96
 
97
-		$response = $this->object->patch( $request, $this->view->response() );
98
-		$result = json_decode( (string) $response->getBody(), true );
97
+		$response = $this->object->patch($request, $this->view->response());
98
+		$result = json_decode((string) $response->getBody(), true);
99 99
 
100 100
 
101
-		$this->assertEquals( 200, $response->getStatusCode() );
102
-		$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) );
101
+		$this->assertEquals(200, $response->getStatusCode());
102
+		$this->assertEquals(1, count($response->getHeader('Content-Type')));
103 103
 
104
-		$this->assertEquals( 1, $result['meta']['total'] );
105
-		$this->assertArrayHasKey( 'data', $result );
106
-		$this->assertEquals( 'locale/site', $result['data']['type'] );
104
+		$this->assertEquals(1, $result['meta']['total']);
105
+		$this->assertArrayHasKey('data', $result);
106
+		$this->assertEquals('locale/site', $result['data']['type']);
107 107
 
108
-		$this->assertArrayNotHasKey( 'included', $result );
109
-		$this->assertArrayNotHasKey( 'errors', $result );
108
+		$this->assertArrayNotHasKey('included', $result);
109
+		$this->assertArrayNotHasKey('errors', $result);
110 110
 	}
111 111
 
112 112
 
113 113
 	public function testPost()
114 114
 	{
115
-		$stub = $this->getSiteMock( array( 'getItem', 'insertItem' ) );
115
+		$stub = $this->getSiteMock(array('getItem', 'insertItem'));
116 116
 		$item = $stub->createItem();
117 117
 
118
-		$stub->expects( $this->any() )->method( 'getItem' )
119
-			->will( $this->returnValue( $item ) );
120
-		$stub->expects( $this->once() )->method( 'insertItem' );
118
+		$stub->expects($this->any())->method('getItem')
119
+			->will($this->returnValue($item));
120
+		$stub->expects($this->once())->method('insertItem');
121 121
 
122 122
 
123 123
 		$body = '{"data": {"type": "locale/site", "attributes": {"locale.site.code": "unittest", "locale.site.label": "Unit test"}}}';
124
-		$request = $this->view->request()->withBody( $this->view->response()->createStreamFromString( $body ) );
124
+		$request = $this->view->request()->withBody($this->view->response()->createStreamFromString($body));
125 125
 
126
-		$response = $this->object->post( $request, $this->view->response() );
127
-		$result = json_decode( (string) $response->getBody(), true );
126
+		$response = $this->object->post($request, $this->view->response());
127
+		$result = json_decode((string) $response->getBody(), true);
128 128
 
129 129
 
130
-		$this->assertEquals( 201, $response->getStatusCode() );
131
-		$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) );
130
+		$this->assertEquals(201, $response->getStatusCode());
131
+		$this->assertEquals(1, count($response->getHeader('Content-Type')));
132 132
 
133
-		$this->assertEquals( 1, $result['meta']['total'] );
134
-		$this->assertArrayHasKey( 'data', $result );
135
-		$this->assertEquals( 'locale/site', $result['data']['type'] );
133
+		$this->assertEquals(1, $result['meta']['total']);
134
+		$this->assertArrayHasKey('data', $result);
135
+		$this->assertEquals('locale/site', $result['data']['type']);
136 136
 
137
-		$this->assertArrayNotHasKey( 'included', $result );
138
-		$this->assertArrayNotHasKey( 'errors', $result );
137
+		$this->assertArrayNotHasKey('included', $result);
138
+		$this->assertArrayNotHasKey('errors', $result);
139 139
 	}
140 140
 
141 141
 
142
-	protected function getSiteItem( $code )
142
+	protected function getSiteItem($code)
143 143
 	{
144
-		$manager = \Aimeos\MShop\Locale\Manager\Factory::createManager( $this->context )->getSubManager( 'site' );
144
+		$manager = \Aimeos\MShop\Locale\Manager\Factory::createManager($this->context)->getSubManager('site');
145 145
 		$search = $manager->createSearch();
146
-		$search->setConditions( $search->compare( '==', 'locale.site.code', $code ) );
147
-		$items = $manager->searchItems( $search );
146
+		$search->setConditions($search->compare('==', 'locale.site.code', $code));
147
+		$items = $manager->searchItems($search);
148 148
 
149
-		if( ( $item = reset( $items ) ) === false ) {
150
-			throw new \RuntimeException( sprintf( 'No locale site item with code "%1$s" found', $code ) );
149
+		if (($item = reset($items)) === false) {
150
+			throw new \RuntimeException(sprintf('No locale site item with code "%1$s" found', $code));
151 151
 		}
152 152
 
153 153
 		return $item;
154 154
 	}
155 155
 
156 156
 
157
-	protected function getSiteMock( array $methods )
157
+	protected function getSiteMock(array $methods)
158 158
 	{
159 159
 		$name = 'AdminJsonAdmStandard';
160
-		$this->context->getConfig()->set( 'mshop/locale/manager/name', $name );
160
+		$this->context->getConfig()->set('mshop/locale/manager/name', $name);
161 161
 
162
-		$stub = $this->getMockBuilder( '\\Aimeos\\MShop\\Locale\\Manager\\Standard' )
163
-			->setConstructorArgs( array( $this->context ) )
164
-			->setMethods( array( 'getSubManager' ) )
162
+		$stub = $this->getMockBuilder('\\Aimeos\\MShop\\Locale\\Manager\\Standard')
163
+			->setConstructorArgs(array($this->context))
164
+			->setMethods(array('getSubManager'))
165 165
 			->getMock();
166 166
 
167
-		$siteStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Locale\\Manager\\Site\\Standard' )
168
-			->setConstructorArgs( array( $this->context ) )
169
-			->setMethods( $methods )
167
+		$siteStub = $this->getMockBuilder('\\Aimeos\\MShop\\Locale\\Manager\\Site\\Standard')
168
+			->setConstructorArgs(array($this->context))
169
+			->setMethods($methods)
170 170
 			->getMock();
171 171
 
172
-		$stub->expects( $this->once() )->method( 'getSubManager' )
173
-			->will( $this->returnValue( $siteStub ) );
172
+		$stub->expects($this->once())->method('getSubManager')
173
+			->will($this->returnValue($siteStub));
174 174
 
175
-		\Aimeos\MShop\Locale\Manager\Factory::injectManager( '\\Aimeos\\MShop\\Locale\\Manager\\' . $name, $stub );
175
+		\Aimeos\MShop\Locale\Manager\Factory::injectManager('\\Aimeos\\MShop\\Locale\\Manager\\' . $name, $stub);
176 176
 
177 177
 		return $siteStub;
178 178
 	}
Please login to merge, or discard this patch.