1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Aimeos\Admin\JQAdm\Product; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
8
|
|
|
* @copyright Aimeos (aimeos.org), 2015 |
9
|
|
|
*/ |
10
|
|
|
class StandardTest extends \PHPUnit_Framework_TestCase |
11
|
|
|
{ |
12
|
|
|
private $context; |
13
|
|
|
private $object; |
14
|
|
|
private $view; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
protected function setUp() |
18
|
|
|
{ |
19
|
|
|
$this->view = \TestHelperJqadm::getView(); |
20
|
|
|
$request = $this->getMock( '\Psr\Http\Message\ServerRequestInterface' ); |
|
|
|
|
21
|
|
|
$helper = new \Aimeos\MW\View\Helper\Request\Standard( $this->view, $request, '127.0.0.1', 'test' ); |
22
|
|
|
$this->view ->addHelper( 'request', $helper ); |
23
|
|
|
|
24
|
|
|
$this->context = \TestHelperJqadm::getContext(); |
25
|
|
|
$templatePaths = \TestHelperJqadm::getTemplatePaths(); |
26
|
|
|
|
27
|
|
|
$this->object = new \Aimeos\Admin\JQAdm\Product\Standard( $this->context, $templatePaths ); |
28
|
|
|
$this->object->setView( $this->view ); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
protected function tearDown() |
33
|
|
|
{ |
34
|
|
|
unset( $this->object ); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
public function testCreate() |
39
|
|
|
{ |
40
|
|
|
$this->object->create(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
public function testCreateException() |
45
|
|
|
{ |
46
|
|
|
$object = $this->getMockBuilder( '\Aimeos\Admin\JQAdm\Product\Standard' ) |
47
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) ) |
48
|
|
|
->setMethods( array( 'getSubClients' ) ) |
49
|
|
|
->getMock(); |
50
|
|
|
|
51
|
|
|
$object->expects( $this->once() )->method( 'getSubClients' ) |
52
|
|
|
->will( $this->throwException( new \Exception() ) ); |
53
|
|
|
|
54
|
|
|
$object->setView( $this->getViewNoRender() ); |
55
|
|
|
|
56
|
|
|
$object->create(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
public function testCreateMShopException() |
61
|
|
|
{ |
62
|
|
|
$object = $this->getMockBuilder( '\Aimeos\Admin\JQAdm\Product\Standard' ) |
63
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) ) |
64
|
|
|
->setMethods( array( 'getSubClients' ) ) |
65
|
|
|
->getMock(); |
66
|
|
|
|
67
|
|
|
$object->expects( $this->once() )->method( 'getSubClients' ) |
68
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception() ) ); |
69
|
|
|
|
70
|
|
|
$object->setView( $this->getViewNoRender() ); |
71
|
|
|
|
72
|
|
|
$object->create(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
public function testCopy() |
77
|
|
|
{ |
78
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'product' ); |
79
|
|
|
|
80
|
|
|
$param = array( 'id' => $manager->findItem( 'CNC' )->getId() ); |
81
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param ); |
82
|
|
|
$this->view->addHelper( 'param', $helper ); |
83
|
|
|
|
84
|
|
|
$result = $this->object->copy(); |
85
|
|
|
|
86
|
|
|
$this->assertContains( 'CNC_copy', $result ); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
public function testCopyException() |
91
|
|
|
{ |
92
|
|
|
$object = $this->getMockBuilder( '\Aimeos\Admin\JQAdm\Product\Standard' ) |
93
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) ) |
94
|
|
|
->setMethods( array( 'getSubClients' ) ) |
95
|
|
|
->getMock(); |
96
|
|
|
|
97
|
|
|
$object->expects( $this->once() )->method( 'getSubClients' ) |
98
|
|
|
->will( $this->throwException( new \Exception() ) ); |
99
|
|
|
|
100
|
|
|
$object->setView( $this->getViewNoRender() ); |
101
|
|
|
|
102
|
|
|
$object->copy(); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
public function testCopyMShopException() |
107
|
|
|
{ |
108
|
|
|
$object = $this->getMockBuilder( '\Aimeos\Admin\JQAdm\Product\Standard' ) |
109
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) ) |
110
|
|
|
->setMethods( array( 'getSubClients' ) ) |
111
|
|
|
->getMock(); |
112
|
|
|
|
113
|
|
|
$object->expects( $this->once() )->method( 'getSubClients' ) |
114
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception() ) ); |
115
|
|
|
|
116
|
|
|
$object->setView( $this->getViewNoRender() ); |
117
|
|
|
|
118
|
|
|
$object->copy(); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
|
122
|
|
|
public function testDelete() |
123
|
|
|
{ |
124
|
|
|
$this->assertNull( $this->object->delete() ); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
|
128
|
|
|
public function testDeleteException() |
129
|
|
|
{ |
130
|
|
|
$object = $this->getMockBuilder( '\Aimeos\Admin\JQAdm\Product\Standard' ) |
131
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) ) |
132
|
|
|
->setMethods( array( 'getSubClients' ) ) |
133
|
|
|
->getMock(); |
134
|
|
|
|
135
|
|
|
$object->expects( $this->once() )->method( 'getSubClients' ) |
136
|
|
|
->will( $this->throwException( new \Exception() ) ); |
137
|
|
|
|
138
|
|
|
$object->setView( $this->getViewNoRender() ); |
139
|
|
|
|
140
|
|
|
$object->delete(); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
|
144
|
|
|
public function testDeleteMShopException() |
145
|
|
|
{ |
146
|
|
|
$object = $this->getMockBuilder( '\Aimeos\Admin\JQAdm\Product\Standard' ) |
147
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) ) |
148
|
|
|
->setMethods( array( 'getSubClients' ) ) |
149
|
|
|
->getMock(); |
150
|
|
|
|
151
|
|
|
$object->expects( $this->once() )->method( 'getSubClients' ) |
152
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception() ) ); |
153
|
|
|
|
154
|
|
|
$object->setView( $this->getViewNoRender() ); |
155
|
|
|
|
156
|
|
|
$object->delete(); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
|
160
|
|
|
public function testGet() |
161
|
|
|
{ |
162
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'product' ); |
163
|
|
|
|
164
|
|
|
$param = array( 'id' => $manager->findItem( 'CNC' )->getId() ); |
165
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param ); |
166
|
|
|
$this->view->addHelper( 'param', $helper ); |
167
|
|
|
|
168
|
|
|
$result = $this->object->get(); |
169
|
|
|
|
170
|
|
|
$this->assertContains( 'CNC', $result ); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
|
174
|
|
|
public function testGetException() |
175
|
|
|
{ |
176
|
|
|
$object = $this->getMockBuilder( '\Aimeos\Admin\JQAdm\Product\Standard' ) |
177
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) ) |
178
|
|
|
->setMethods( array( 'getSubClients' ) ) |
179
|
|
|
->getMock(); |
180
|
|
|
|
181
|
|
|
$object->expects( $this->once() )->method( 'getSubClients' ) |
182
|
|
|
->will( $this->throwException( new \Exception() ) ); |
183
|
|
|
|
184
|
|
|
$object->setView( $this->getViewNoRender() ); |
185
|
|
|
|
186
|
|
|
$object->get(); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
|
190
|
|
|
public function testGetMShopException() |
191
|
|
|
{ |
192
|
|
|
$object = $this->getMockBuilder( '\Aimeos\Admin\JQAdm\Product\Standard' ) |
193
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) ) |
194
|
|
|
->setMethods( array( 'getSubClients' ) ) |
195
|
|
|
->getMock(); |
196
|
|
|
|
197
|
|
|
$object->expects( $this->once() )->method( 'getSubClients' ) |
198
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception() ) ); |
199
|
|
|
|
200
|
|
|
$object->setView( $this->getViewNoRender() ); |
201
|
|
|
|
202
|
|
|
$object->get(); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
|
206
|
|
|
public function testSave() |
207
|
|
|
{ |
208
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'product' ); |
209
|
|
|
$typeManager = \Aimeos\MShop\Factory::createManager( $this->context, 'product/type' ); |
210
|
|
|
|
211
|
|
|
$search = $typeManager->createSearch(); |
212
|
|
|
$search->setSlice( 0, 1 ); |
213
|
|
|
$typeItems = $typeManager->searchItems( $search ); |
214
|
|
|
|
215
|
|
|
if( ( $typeItem = reset( $typeItems ) ) === false ) { |
216
|
|
|
throw new \Exception( 'No product type item found' ); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
|
220
|
|
|
$param = array( |
221
|
|
|
'item' => array( |
222
|
|
|
'product.id' => '', |
223
|
|
|
'product.typeid' => $typeItem->getId(), |
224
|
|
|
'product.code' => 'test', |
225
|
|
|
'product.label' => 'test label', |
226
|
|
|
'product.datestart' => null, |
227
|
|
|
'product.dateend' => null, |
228
|
|
|
'config' => array( |
229
|
|
|
'key' => array( 0 => 'test key' ), |
230
|
|
|
'val' => array( 0 => 'test value' ), |
231
|
|
|
), |
232
|
|
|
), |
233
|
|
|
); |
234
|
|
|
|
235
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param ); |
236
|
|
|
$this->view->addHelper( 'param', $helper ); |
237
|
|
|
|
238
|
|
|
$this->object->save(); |
239
|
|
|
|
240
|
|
|
$manager->deleteItem( $manager->findItem( 'test' )->getId() ); |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
|
244
|
|
|
public function testSaveException() |
245
|
|
|
{ |
246
|
|
|
$object = $this->getMockBuilder( '\Aimeos\Admin\JQAdm\Product\Standard' ) |
247
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) ) |
248
|
|
|
->setMethods( array( 'getSubClients' ) ) |
249
|
|
|
->getMock(); |
250
|
|
|
|
251
|
|
|
$name = 'AdminJQAdmStandard'; |
252
|
|
|
$this->context->getConfig()->set( 'mshop/product/manager/name', $name ); |
253
|
|
|
|
254
|
|
|
$mock = $this->getMockBuilder( '\Aimeos\MShop\Product\Manager\Standard' ) |
255
|
|
|
->setConstructorArgs( array( $this->context ) ) |
256
|
|
|
->setMethods( array( 'createItem' ) ) |
257
|
|
|
->getMock(); |
258
|
|
|
|
259
|
|
|
$mock->expects( $this->exactly( 2 ) )->method( 'createItem' ) |
260
|
|
|
->will( $this->throwException( new \Exception() ) ); |
261
|
|
|
|
262
|
|
|
\Aimeos\MShop\Product\Manager\Factory::injectManager( '\\Aimeos\\MShop\\Product\\Manager\\' . $name, $mock ); |
263
|
|
|
|
264
|
|
|
$object->setView( $this->getViewNoRender() ); |
265
|
|
|
|
266
|
|
|
$object->save(); |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
|
270
|
|
|
public function testSaveMShopException() |
271
|
|
|
{ |
272
|
|
|
$object = $this->getMockBuilder( '\Aimeos\Admin\JQAdm\Product\Standard' ) |
273
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) ) |
274
|
|
|
->setMethods( array( 'getSubClients' ) ) |
275
|
|
|
->getMock(); |
276
|
|
|
|
277
|
|
|
$name = 'AdminJQAdmStandard'; |
278
|
|
|
$this->context->getConfig()->set( 'mshop/product/manager/name', $name ); |
279
|
|
|
|
280
|
|
|
$mock = $this->getMockBuilder( '\Aimeos\MShop\Product\Manager\Standard' ) |
281
|
|
|
->setConstructorArgs( array( $this->context ) ) |
282
|
|
|
->setMethods( array( 'createItem' ) ) |
283
|
|
|
->getMock(); |
284
|
|
|
|
285
|
|
|
$mock->expects( $this->exactly( 2 ) )->method( 'createItem' ) |
286
|
|
|
->will( $this->throwException( new \Exception() ) ); |
287
|
|
|
|
288
|
|
|
\Aimeos\MShop\Product\Manager\Factory::injectManager( '\\Aimeos\\MShop\\Product\\Manager\\' . $name, $mock ); |
289
|
|
|
|
290
|
|
|
$object->setView( $this->getViewNoRender() ); |
291
|
|
|
|
292
|
|
|
$object->save(); |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
|
296
|
|
|
public function testSearch() |
297
|
|
|
{ |
298
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, array( 'site' => 'unittest', 'lang' => 'de' ) ); |
299
|
|
|
$this->view->addHelper( 'param', $helper ); |
300
|
|
|
|
301
|
|
|
$result = $this->object->search(); |
302
|
|
|
|
303
|
|
|
$this->assertContains( 'CNE', $result ); |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
|
307
|
|
|
public function testSearchException() |
308
|
|
|
{ |
309
|
|
|
$object = $this->getMockBuilder( '\Aimeos\Admin\JQAdm\Product\Standard' ) |
310
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) ) |
311
|
|
|
->setMethods( array( 'getSubClients' ) ) |
312
|
|
|
->getMock(); |
313
|
|
|
|
314
|
|
|
$object->expects( $this->once() )->method( 'getSubClients' ) |
315
|
|
|
->will( $this->throwException( new \Exception() ) ); |
316
|
|
|
|
317
|
|
|
$object->setView( $this->getViewNoRender() ); |
318
|
|
|
|
319
|
|
|
$object->search(); |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
|
323
|
|
|
public function testSearchMShopException() |
324
|
|
|
{ |
325
|
|
|
$object = $this->getMockBuilder( '\Aimeos\Admin\JQAdm\Product\Standard' ) |
326
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) ) |
327
|
|
|
->setMethods( array( 'getSubClients' ) ) |
328
|
|
|
->getMock(); |
329
|
|
|
|
330
|
|
|
$object->expects( $this->once() )->method( 'getSubClients' ) |
331
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception() ) ); |
332
|
|
|
|
333
|
|
|
$object->setView( $this->getViewNoRender() ); |
334
|
|
|
|
335
|
|
|
$object->search(); |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
|
339
|
|
|
public function testGetSubClient() |
340
|
|
|
{ |
341
|
|
|
$this->setExpectedException( '\Aimeos\Admin\JQAdm\Exception' ); |
|
|
|
|
342
|
|
|
$this->object->getSubClient( 'invalid' ); |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
|
346
|
|
|
protected function getViewNoRender() |
347
|
|
|
{ |
348
|
|
|
return $this->getMockBuilder( '\Aimeos\MW\View\Standard' ) |
349
|
|
|
->setConstructorArgs( array( array() ) ) |
350
|
|
|
->setMethods( array( 'render', 'config' ) ) |
351
|
|
|
->getMock(); |
352
|
|
|
} |
353
|
|
|
} |
354
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.