Completed
Push — master ( 69ae10...ab8a43 )
by Aimeos
09:58
created

StandardTest::testGetPropertyItemsAll()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 10
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2011
6
 * @copyright Aimeos (aimeos.org), 2015-2017
7
 */
8
9
10
namespace Aimeos\MShop\Product\Item;
11
12
13
class StandardTest extends \PHPUnit\Framework\TestCase
14
{
15
	private $object;
16
	private $values;
17
18
19
	protected function setUp()
20
	{
21
		$this->values = array(
22
			'product.id' => 1,
23
			'product.siteid' => 99,
24
			'product.typeid' => 2,
25
			'product.type' => 'test',
26
			'product.typename' => 'Test',
27
			'product.status' => 0,
28
			'product.code' => 'TEST',
29
			'product.label' => 'testproduct',
30
			'product.config' => array( 'css-class' => 'test' ),
31
			'product.datestart' => null,
32
			'product.dateend' => null,
33
			'product.ctime' => '2011-01-19 17:04:32',
34
			'product.mtime' => '2011-01-19 18:04:32',
35
			'product.editor' => 'unitTestUser',
36
			'product.target' => 'testtarget',
37
		);
38
39
		$propItems = array(
40
			2 => new \Aimeos\MShop\Common\Item\Property\Standard( 'product.property.', array(
41
				'product.property.id' => 2,
42
				'product.property.parentid' => 1,
43
				'product.property.type' => 'proptest',
44
				'product.property.languageid' => 'de',
45
				'languageid' => 'de',
46
			) ),
47
			3 => new \Aimeos\MShop\Common\Item\Property\Standard( 'product.property.', array(
48
				'product.property.id' => 3,
49
				'product.property.parentid' => 1,
50
				'product.property.type' => 'proptype',
51
				'product.property.languageid' => 'de',
52
				'languageid' => 'fr',
53
			) ),
54
		);
55
56
		$this->object = new \Aimeos\MShop\Product\Item\Standard( $this->values, [], [], $propItems );
57
	}
58
59
60
	protected function tearDown()
61
	{
62
		unset( $this->object, $this->textListItems );
63
	}
64
65
66
	public function testGetId()
67
	{
68
		$this->assertEquals( '1', $this->object->getId() );
69
	}
70
71
72
	public function testSetId()
73
	{
74
		$return = $this->object->setId( null );
75
76
		$this->assertInstanceOf( '\Aimeos\MShop\Product\Item\Iface', $return );
77
		$this->assertNull( $this->object->getId() );
78
		$this->assertTrue( $this->object->isModified() );
79
80
		$return = $this->object->setId( 1 );
81
82
		$this->assertInstanceOf( '\Aimeos\MShop\Product\Item\Iface', $return );
83
		$this->assertEquals( '1', $this->object->getId() );
84
		$this->assertFalse( $this->object->isModified() );
85
86
		$this->setExpectedException( '\\Aimeos\\MShop\\Exception' );
87
		$this->object->setId( 2 );
88
	}
89
90
91
	public function testGetSiteId()
92
	{
93
		$this->assertEquals( 99, $this->object->getSiteId() );
94
	}
95
96
97
	public function testGetPropertyItems()
98
	{
99
		$propItems = $this->object->getPropertyItems();
100
101
		$this->assertEquals( 1, count( $propItems ) );
102
103
		foreach( $propItems as $propItem ) {
104
			$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Property\Iface', $propItem );
105
		}
106
	}
107
108
109
	public function testGetPropertyItemsAll()
110
	{
111
		$propItems = $this->object->getPropertyItems( null, false );
112
113
		$this->assertEquals( 2, count( $propItems ) );
114
115
		foreach( $propItems as $propItem ) {
116
			$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Property\Iface', $propItem );
117
		}
118
	}
119
120
121
	public function testGetPropertyItemsType()
122
	{
123
		$propItems = $this->object->getPropertyItems( 'proptest' );
124
125
		$this->assertEquals( 1, count( $propItems ) );
126
127
		foreach( $propItems as $propItem ) {
128
			$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Property\Iface', $propItem );
129
		}
130
	}
131
132
133
	public function testGetTypeId()
134
	{
135
		$this->assertEquals( 2, $this->object->getTypeId() );
136
	}
137
138
139
	public function testSetTypeId()
140
	{
141
		$this->assertFalse( $this->object->isModified() );
142
143
		$return = $this->object->setTypeId( 1 );
144
145
		$this->assertInstanceOf( '\Aimeos\MShop\Product\Item\Iface', $return );
146
		$this->assertEquals( 1, $this->object->getTypeId() );
147
		$this->assertTrue( $this->object->isModified() );
148
	}
149
150
151
	public function testGetType()
152
	{
153
		$this->assertEquals( 'test', $this->object->getType() );
154
	}
155
156
157
	public function testGetTypeName()
158
	{
159
		$this->assertEquals( 'Test', $this->object->getTypeName() );
160
	}
161
162
163
	public function testGetCode()
164
	{
165
		$this->assertEquals( 'TEST', $this->object->getCode() );
166
	}
167
168
169
	public function testSetCode()
170
	{
171
		$this->assertFalse( $this->object->isModified() );
172
173
		$return = $this->object->setCode( 'NEU' );
174
175
		$this->assertInstanceOf( '\Aimeos\MShop\Product\Item\Iface', $return );
176
		$this->assertEquals( 'NEU', $this->object->getCode() );
177
		$this->assertTrue( $this->object->isModified() );
178
	}
179
180
181
	public function testGetEditor()
182
	{
183
		$this->assertEquals( 'unitTestUser', $this->object->getEditor() );
184
	}
185
186
187
	public function testGetStatus()
188
	{
189
		$this->assertEquals( 0, $this->object->getStatus() );
190
	}
191
192
193
	public function testSetStatus()
194
	{
195
		$return = $this->object->setStatus( 8 );
196
197
		$this->assertInstanceOf( '\Aimeos\MShop\Product\Item\Iface', $return );
198
		$this->assertEquals( 8, $this->object->getStatus() );
199
		$this->assertTrue( $this->object->isModified() );
200
	}
201
202
203
	public function testGetLabel()
204
	{
205
		$this->assertEquals( 'testproduct', $this->object->getLabel() );
206
	}
207
208
209
	public function testSetLabel()
210
	{
211
		$return = $this->object->setLabel( 'editproduct' );
212
213
		$this->assertInstanceOf( '\Aimeos\MShop\Product\Item\Iface', $return );
214
		$this->assertEquals( 'editproduct', $this->object->getLabel() );
215
		$this->assertTrue( $this->object->isModified() );
216
	}
217
218
219
	public function testGetConfig()
220
	{
221
		$this->assertEquals( array( 'css-class' => 'test' ), $this->object->getConfig() );
222
	}
223
224
225
	public function testSetConfig()
226
	{
227
		$this->assertFalse( $this->object->isModified() );
228
229
		$return = $this->object->setConfig( array( 'key' => 'value' ) );
230
231
		$this->assertInstanceOf( '\Aimeos\MShop\Product\Item\Iface', $return );
232
		$this->assertEquals( array( 'key' => 'value' ), $this->object->getConfig() );
233
		$this->assertTrue( $this->object->isModified() );
234
	}
235
236
237
	public function testGetTarget()
238
	{
239
		$this->assertEquals( 'testtarget', $this->object->getTarget() );
240
	}
241
242
243
	public function testSetTarget()
244
	{
245
		$this->assertFalse( $this->object->isModified() );
246
247
		$return = $this->object->setTarget( 'ttarget' );
248
249
		$this->assertInstanceOf( '\Aimeos\MShop\Product\Item\Iface', $return );
250
		$this->assertEquals( 'ttarget', $this->object->getTarget() );
251
		$this->assertTrue( $this->object->isModified() );
252
	}
253
254
255
	public function testGetDateStart()
256
	{
257
		$this->assertEquals( null, $this->object->getDateStart() );
258
	}
259
260
261
	public function testSetDateStart()
262
	{
263
		$return = $this->object->setDateStart( '2010-04-22 06:22:22' );
264
265
		$this->assertInstanceOf( '\Aimeos\MShop\Product\Item\Iface', $return );
266
		$this->assertEquals( '2010-04-22 06:22:22', $this->object->getDateStart() );
267
		$this->assertTrue( $this->object->isModified() );
268
	}
269
270
271
	public function testGetDateEnd()
272
	{
273
		$this->assertEquals( null, $this->object->getDateEnd() );
274
	}
275
276
277
	public function testSetDateEnd()
278
	{
279
		$return = $this->object->setDateEnd( '2010-05-22 06:22:22' );
280
281
		$this->assertInstanceOf( '\Aimeos\MShop\Product\Item\Iface', $return );
282
		$this->assertEquals( '2010-05-22 06:22:22', $this->object->getDateEnd() );
283
		$this->assertTrue( $this->object->isModified() );
284
	}
285
286
287
	public function testGetTimeModified()
288
	{
289
		$this->assertEquals( '2011-01-19 18:04:32', $this->object->getTimeModified() );
290
	}
291
292
293
	public function testGetTimeCreated()
294
	{
295
		$this->assertEquals( '2011-01-19 17:04:32', $this->object->getTimeCreated() );
296
	}
297
298
299
	public function testIsAvailable()
300
	{
301
		$this->assertFalse( $this->object->isAvailable() );
302
	}
303
304
305
	public function testIsModified()
306
	{
307
		$this->assertFalse( $this->object->isModified() );
308
	}
309
310
311
	public function testIsModifiedTrue()
312
	{
313
		$this->object->setLabel( 'reeditProduct' );
314
		$this->assertTrue( $this->object->isModified() );
315
	}
316
317
318
	public function testGetResourceType()
319
	{
320
		$this->assertEquals( 'product', $this->object->getResourceType() );
321
	}
322
323
324
	public function testFromArray()
325
	{
326
		$item = new \Aimeos\MShop\Product\Item\Standard();
327
328
		$list = array(
329
			'product.id' => 1,
330
			'product.typeid' => 2,
331
			'product.type' => 'test',
332
			'product.typename' => 'Test',
333
			'product.label' => 'test item',
334
			'product.code' => 'test',
335
			'product.datestart' => '2000-01-01 00:00:00',
336
			'product.dateend' => '2001-01-01 00:00:00',
337
			'product.config' => array( 'key' => 'value' ),
338
			'product.status' => 0,
339
			'product.target' => 'ttarget',
340
		);
341
342
		$unknown = $item->fromArray( $list );
343
344
		$this->assertEquals( [], $unknown );
345
346
		$this->assertEquals( $list['product.id'], $item->getId() );
347
		$this->assertEquals( $list['product.code'], $item->getCode() );
348
		$this->assertEquals( $list['product.label'], $item->getLabel() );
349
		$this->assertEquals( $list['product.typeid'], $item->getTypeId() );
350
		$this->assertEquals( $list['product.datestart'], $item->getDateStart() );
351
		$this->assertEquals( $list['product.dateend'], $item->getDateEnd() );
352
		$this->assertEquals( $list['product.config'], $item->getConfig() );
353
		$this->assertEquals( $list['product.status'], $item->getStatus() );
354
		$this->assertEquals( $list['product.target'], $item->getTarget() );
355
		$this->assertNull( $item->getSiteId() );
356
		$this->assertNull( $item->getTypeName() );
357
		$this->assertNull( $item->getType() );
358
	}
359
360
361
	public function testToArray()
362
	{
363
		$arrayObject = $this->object->toArray( true );
364
		$this->assertEquals( count( $this->values ), count( $arrayObject ) );
365
366
		$this->assertEquals( $this->object->getId(), $arrayObject['product.id'] );
367
		$this->assertEquals( $this->object->getSiteId(), $arrayObject['product.siteid'] );
368
		$this->assertEquals( $this->object->getCode(), $arrayObject['product.code'] );
369
		$this->assertEquals( $this->object->getTypeName(), $arrayObject['product.typename'] );
370
		$this->assertEquals( $this->object->getTypeId(), $arrayObject['product.typeid'] );
371
		$this->assertEquals( $this->object->getType(), $arrayObject['product.type'] );
372
		$this->assertEquals( $this->object->getLabel(), $arrayObject['product.label'] );
373
		$this->assertEquals( $this->object->getStatus(), $arrayObject['product.status'] );
374
		$this->assertEquals( $this->object->getDateStart(), $arrayObject['product.datestart'] );
375
		$this->assertEquals( $this->object->getDateEnd(), $arrayObject['product.dateend'] );
376
		$this->assertEquals( $this->object->getConfig(), $arrayObject['product.config'] );
377
		$this->assertEquals( $this->object->getTimeCreated(), $arrayObject['product.ctime'] );
378
		$this->assertEquals( $this->object->getTimeModified(), $arrayObject['product.mtime'] );
379
		$this->assertEquals( $this->object->getEditor(), $arrayObject['product.editor'] );
380
		$this->assertEquals( $this->object->getTarget(), $arrayObject['product.target'] );
381
	}
382
383
}
384