Completed
Push — master ( a775dd...8d0f0f )
by Aimeos
03:13
created

StandardTest::testSaveJQAdmException()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 24
rs 8.9713
cc 1
eloc 16
nc 1
nop 0
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' );
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

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.

Loading history...
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 testGetViewException()
207
	{
208
		$object = new \Aimeos\Admin\JQAdm\Product\Standard( $this->context, array() );
209
210
		$this->setExpectedException( '\Aimeos\Admin\JQAdm\Exception' );
1 ignored issue
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0

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.

Loading history...
211
		$object->getView();
212
	}
213
214
215
	public function testSave()
216
	{
217
		$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'product' );
218
		$typeManager = \Aimeos\MShop\Factory::createManager( $this->context, 'product/type' );
219
220
		$search = $typeManager->createSearch();
221
		$search->setSlice( 0, 1 );
222
		$typeItems = $typeManager->searchItems( $search );
223
224
		if( ( $typeItem = reset( $typeItems ) ) === false ) {
225
			throw new \Exception( 'No product type item found' );
226
		}
227
228
229
		$param = array(
230
			'item' => array(
231
				'product.id' => '',
232
				'product.typeid' => $typeItem->getId(),
233
				'product.code' => 'test',
234
				'product.label' => 'test label',
235
				'product.datestart' => null,
236
				'product.dateend' => null,
237
				'config' => array(
238
					'key' => array( 0 => 'test key' ),
239
					'val' => array( 0 => 'test value' ),
240
				),
241
			),
242
		);
243
244
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param );
245
		$this->view->addHelper( 'param', $helper );
246
247
		$this->object->save();
248
249
		$manager->deleteItem( $manager->findItem( 'test' )->getId() );
250
	}
251
252
253
	public function testSaveException()
254
	{
255
		$object = $this->getMockBuilder( '\Aimeos\Admin\JQAdm\Product\Standard' )
256
			->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) )
257
			->setMethods( array( 'getSubClients' ) )
258
			->getMock();
259
260
		$name = 'AdminJQAdmStandard';
261
		$this->context->getConfig()->set( 'mshop/product/manager/name', $name );
262
263
		$mock = $this->getMockBuilder( '\Aimeos\MShop\Product\Manager\Standard' )
264
			->setConstructorArgs( array( $this->context ) )
265
			->setMethods( array( 'createItem' ) )
266
			->getMock();
267
268
		$mock->expects( $this->exactly( 2 ) )->method( 'createItem' )
269
			->will( $this->throwException( new \Exception() ) );
270
271
		\Aimeos\MShop\Product\Manager\Factory::injectManager( '\\Aimeos\\MShop\\Product\\Manager\\' . $name, $mock );
272
273
		$object->setView( $this->getViewNoRender() );
274
275
		$object->save();
276
	}
277
278
279
	public function testSaveMShopException()
280
	{
281
		$object = $this->getMockBuilder( '\Aimeos\Admin\JQAdm\Product\Standard' )
282
			->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) )
283
			->setMethods( array( 'getSubClients' ) )
284
			->getMock();
285
286
		$name = 'AdminJQAdmStandard';
287
		$this->context->getConfig()->set( 'mshop/product/manager/name', $name );
288
289
		$mock = $this->getMockBuilder( '\Aimeos\MShop\Product\Manager\Standard' )
290
			->setConstructorArgs( array( $this->context ) )
291
			->setMethods( array( 'createItem' ) )
292
			->getMock();
293
294
		$mock->expects( $this->exactly( 2 ) )->method( 'createItem' )
295
			->will( $this->throwException( new \Aimeos\MShop\Exception() ) );
296
297
		\Aimeos\MShop\Product\Manager\Factory::injectManager( '\\Aimeos\\MShop\\Product\\Manager\\' . $name, $mock );
298
299
		$object->setView( $this->getViewNoRender() );
300
301
		$object->save();
302
	}
303
304
305
	public function testSaveJQAdmException()
306
	{
307
		$object = $this->getMockBuilder( '\Aimeos\Admin\JQAdm\Product\Standard' )
308
			->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) )
309
			->setMethods( array( 'getSubClients' ) )
310
			->getMock();
311
312
		$name = 'AdminJQAdmStandard';
313
		$this->context->getConfig()->set( 'mshop/product/manager/name', $name );
314
315
		$mock = $this->getMockBuilder( '\Aimeos\MShop\Product\Manager\Standard' )
316
			->setConstructorArgs( array( $this->context ) )
317
			->setMethods( array( 'createItem' ) )
318
			->getMock();
319
320
		$mock->expects( $this->exactly( 2 ) )->method( 'createItem' )
321
			->will( $this->throwException( new \Aimeos\Admin\JQAdm\Exception() ) );
322
323
		\Aimeos\MShop\Product\Manager\Factory::injectManager( '\\Aimeos\\MShop\\Product\\Manager\\' . $name, $mock );
324
325
		$object->setView( $this->getViewNoRender() );
326
327
		$object->save();
328
	}
329
330
331
	public function testSearch()
332
	{
333
		$param = array(
334
			'site' => 'unittest', 'lang' => 'de',
335
			'filter' => array(
336
				'key' => array( 0 => 'product.code' ),
337
				'op' => array( 0 => '==' ),
338
				'val' => array( 0 => 'CNE' ),
339
			),
340
			'sort' => array( 'product.label', '-product.id' ),
341
		);
342
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param );
343
		$this->view->addHelper( 'param', $helper );
344
345
		$result = $this->object->search();
346
347
		$this->assertContains( '>CNE<', $result );
348
	}
349
350
351
	public function testSearchException()
352
	{
353
		$object = $this->getMockBuilder( '\Aimeos\Admin\JQAdm\Product\Standard' )
354
			->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) )
355
			->setMethods( array( 'getSubClients' ) )
356
			->getMock();
357
358
		$object->expects( $this->once() )->method( 'getSubClients' )
359
			->will( $this->throwException( new \Exception() ) );
360
361
		$object->setView( $this->getViewNoRender() );
362
363
		$object->search();
364
	}
365
366
367
	public function testSearchMShopException()
368
	{
369
		$object = $this->getMockBuilder( '\Aimeos\Admin\JQAdm\Product\Standard' )
370
			->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) )
371
			->setMethods( array( 'getSubClients' ) )
372
			->getMock();
373
374
		$object->expects( $this->once() )->method( 'getSubClients' )
375
			->will( $this->throwException( new \Aimeos\MShop\Exception() ) );
376
377
		$object->setView( $this->getViewNoRender() );
378
379
		$object->search();
380
	}
381
382
383
	public function testGetSubClient()
384
	{
385
		$result = $this->object->getSubClient( 'image' );
386
		$this->assertInstanceOf( '\Aimeos\Admin\JQAdm\Iface', $result );
387
	}
388
389
390
	public function testGetSubClientEmpty()
391
	{
392
		$this->setExpectedException( '\Aimeos\Admin\JQAdm\Exception' );
1 ignored issue
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0

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.

Loading history...
393
		$this->object->getSubClient( '' );
394
	}
395
396
397
	public function testGetSubClientInvalid()
398
	{
399
		$this->setExpectedException( '\Aimeos\Admin\JQAdm\Exception' );
1 ignored issue
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0

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.

Loading history...
400
		$this->object->getSubClient( 'invalid' );
401
	}
402
403
404
	public function testGetSubClientDecorators()
405
	{
406
		$this->context->getConfig()->set( 'admin/jqadm/product/image/decorators/global', array( 'Cache' ) );
407
408
		$result = $this->object->getSubClient( 'image' );
409
		$this->assertInstanceOf( '\Aimeos\Admin\JQAdm\Iface', $result );
410
	}
411
412
413
	public function testGetSubClientDecoratorInvalid()
414
	{
415
		$this->context->getConfig()->set( 'admin/jqadm/product/image/decorators/global', array( 'Invalid' ) );
416
417
		$this->setExpectedException( '\Aimeos\Admin\JQAdm\Exception' );
1 ignored issue
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0

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.

Loading history...
418
		$this->object->getSubClient( 'image' );
419
	}
420
421
422
	protected function getViewNoRender()
423
	{
424
		return $this->getMockBuilder( '\Aimeos\MW\View\Standard' )
425
			->setConstructorArgs( array( array() ) )
426
			->setMethods( array( 'render', 'config' ) )
427
			->getMock();
428
	}
429
}
430