Completed
Push — master ( f157ac...a775dd )
by Aimeos
03:15
created

StandardTest::testGetSubClientEmpty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
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 \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 testSearch()
306
	{
307
		$param = array(
308
			'site' => 'unittest', 'lang' => 'de',
309
			'filter' => array(
310
				'key' => array( 0 => 'product.code' ),
311
				'op' => array( 0 => '==' ),
312
				'val' => array( 0 => 'CNE' ),
313
			),
314
			'sort' => array( '+product.label', '-product.id' ),
315
		);
316
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param );
317
		$this->view->addHelper( 'param', $helper );
318
319
		$result = $this->object->search();
320
321
		$this->assertContains( 'CNE', $result );
322
	}
323
324
325
	public function testSearchException()
326
	{
327
		$object = $this->getMockBuilder( '\Aimeos\Admin\JQAdm\Product\Standard' )
328
			->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) )
329
			->setMethods( array( 'getSubClients' ) )
330
			->getMock();
331
332
		$object->expects( $this->once() )->method( 'getSubClients' )
333
			->will( $this->throwException( new \Exception() ) );
334
335
		$object->setView( $this->getViewNoRender() );
336
337
		$object->search();
338
	}
339
340
341
	public function testSearchMShopException()
342
	{
343
		$object = $this->getMockBuilder( '\Aimeos\Admin\JQAdm\Product\Standard' )
344
			->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) )
345
			->setMethods( array( 'getSubClients' ) )
346
			->getMock();
347
348
		$object->expects( $this->once() )->method( 'getSubClients' )
349
			->will( $this->throwException( new \Aimeos\MShop\Exception() ) );
350
351
		$object->setView( $this->getViewNoRender() );
352
353
		$object->search();
354
	}
355
356
357
	public function testGetSubClient()
358
	{
359
		$result = $this->object->getSubClient( 'image' );
360
		$this->assertInstanceOf( '\Aimeos\Admin\JQAdm\Iface', $result );
361
	}
362
363
364
	public function testGetSubClientEmpty()
365
	{
366
		$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...
367
		$this->object->getSubClient( '' );
368
	}
369
370
371
	public function testGetSubClientInvalid()
372
	{
373
		$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...
374
		$this->object->getSubClient( 'invalid' );
375
	}
376
377
378
	public function testGetSubClientDecorators()
379
	{
380
		$this->context->getConfig()->set( 'admin/jqadm/product/image/decorators/global', array( 'Cache' ) );
381
382
		$result = $this->object->getSubClient( 'image' );
383
		$this->assertInstanceOf( '\Aimeos\Admin\JQAdm\Iface', $result );
384
	}
385
386
387
	public function testGetSubClientDecoratorInvalid()
388
	{
389
		$this->context->getConfig()->set( 'admin/jqadm/product/image/decorators/global', array( 'Invalid' ) );
390
391
		$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...
392
		$this->object->getSubClient( 'image' );
393
	}
394
395
396
	protected function getViewNoRender()
397
	{
398
		return $this->getMockBuilder( '\Aimeos\MW\View\Standard' )
399
			->setConstructorArgs( array( array() ) )
400
			->setMethods( array( 'render', 'config' ) )
401
			->getMock();
402
	}
403
}
404