Passed
Push — master ( 8448db...4f9b83 )
by Aimeos
05:16
created

StandardTest::testSetPrice()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2011
6
 * @copyright Aimeos (aimeos.org), 2015-2022
7
 */
8
9
10
namespace Aimeos\MShop\Order\Item\Base\Product\Attribute;
11
12
13
class StandardTest extends \PHPUnit\Framework\TestCase
14
{
15
	private $object;
16
	private $values;
17
18
19
	protected function setUp() : void
20
	{
21
		$this->values = array(
22
			'order.base.product.attribute.id' => 4,
23
			'order.base.product.attribute.siteid' => 99,
24
			'order.base.product.attribute.attributeid' => 22,
25
			'order.base.product.attribute.parentid' => 11,
26
			'order.base.product.attribute.type' => 'UnitType',
27
			'order.base.product.attribute.code' => 'size',
28
			'order.base.product.attribute.value' => '30',
29
			'order.base.product.attribute.name' => 'small',
30
			'order.base.product.attribute.price' => '1.00',
31
			'order.base.product.attribute.quantity' => 2,
32
			'order.base.product.attribute.mtime' => '2011-01-06 13:20:34',
33
			'order.base.product.attribute.ctime' => '2011-01-01 00:00:01',
34
			'order.base.product.attribute.editor' => 'unitTestUser'
35
		);
36
37
		$this->object = new \Aimeos\MShop\Order\Item\Base\Product\Attribute\Standard( $this->values );
38
	}
39
40
41
	protected function tearDown() : void
42
	{
43
		unset( $this->object );
44
	}
45
46
47
	public function testGetId()
48
	{
49
		$this->assertEquals( 4, $this->object->getId() );
50
	}
51
52
53
	public function testSetId()
54
	{
55
		$return = $this->object->setId( null );
56
57
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Product\Attribute\Iface::class, $return );
58
		$this->assertEquals( null, $this->object->getId() );
59
		$this->assertTrue( $this->object->isModified() );
60
61
		$return = $this->object->setId( 8 );
62
63
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Product\Attribute\Iface::class, $return );
64
		$this->assertEquals( 8, $this->object->getId() );
65
		$this->assertFalse( $this->object->isModified() );
66
	}
67
68
69
	public function testGetSiteId()
70
	{
71
		$this->assertEquals( 99, $this->object->getSiteId() );
72
	}
73
74
75
	public function testSetSiteId()
76
	{
77
		$this->object->setSiteId( 100 );
78
		$this->assertEquals( 100, $this->object->getSiteId() );
79
		$this->assertTrue( $this->object->isModified() );
80
	}
81
82
83
	public function testGetAttributeId()
84
	{
85
		$this->assertEquals( 22, $this->object->getAttributeId() );
86
	}
87
88
89
	public function testSetAttributeId()
90
	{
91
		$return = $this->object->setAttributeId( 44 );
92
93
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Product\Attribute\Iface::class, $return );
94
		$this->assertEquals( 44, $this->object->getAttributeId() );
95
		$this->assertTrue( $this->object->isModified() );
96
97
		$this->assertEquals( '', $this->object->setAttributeId( null )->getAttributeId() );
98
	}
99
100
101
	public function testGetParentId()
102
	{
103
		$this->assertEquals( 11, $this->object->getParentId() );
104
	}
105
106
107
	public function testSetParentId()
108
	{
109
		$return = $this->object->setParentId( 33 );
110
111
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Product\Attribute\Iface::class, $return );
112
		$this->assertEquals( 33, $this->object->getParentId() );
113
		$this->assertTrue( $this->object->isModified() );
114
	}
115
116
117
	public function testGetType()
118
	{
119
		$this->assertEquals( 'UnitType', $this->object->getType() );
120
	}
121
122
123
	public function testSetType()
124
	{
125
		$return = $this->object->setType( 'testType' );
126
127
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Product\Attribute\Iface::class, $return );
128
		$this->assertEquals( 'testType', $this->object->getType() );
129
		$this->assertTrue( $this->object->isModified() );
130
	}
131
132
133
	public function testGetCode()
134
	{
135
		$this->assertEquals( 'size', $this->object->getCode() );
136
	}
137
138
139
	public function testSetCode()
140
	{
141
		$return = $this->object->setCode( 'weight' );
142
143
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Product\Attribute\Iface::class, $return );
144
		$this->assertEquals( 'weight', $this->object->getCode() );
145
		$this->assertTrue( $this->object->isModified() );
146
	}
147
148
149
	public function testGetValue()
150
	{
151
		$this->assertEquals( '30', $this->object->getValue() );
152
	}
153
154
155
	public function testSetValue()
156
	{
157
		$return = $this->object->setValue( 36 );
158
159
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Product\Attribute\Iface::class, $return );
160
		$this->assertEquals( 36, $this->object->getValue() );
161
		$this->assertTrue( $this->object->isModified() );
162
	}
163
164
165
	public function testGetName()
166
	{
167
		$this->assertEquals( 'small', $this->object->getName() );
168
	}
169
170
171
	public function testSetName()
172
	{
173
		$return = $this->object->setName( 'medium' );
174
175
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Product\Attribute\Iface::class, $return );
176
		$this->assertEquals( 'medium', $this->object->getName() );
177
		$this->assertTrue( $this->object->isModified() );
178
179
		$this->assertEquals( '', $this->object->setName( null )->getName() );
180
	}
181
182
183
	public function testGetQuantity()
184
	{
185
		$this->assertEquals( 2, $this->object->getQuantity() );
186
	}
187
188
189
	public function testSetQuantity()
190
	{
191
		$return = $this->object->setQuantity( 3 );
192
193
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Product\Attribute\Iface::class, $return );
194
		$this->assertEquals( 3, $this->object->getQuantity() );
195
		$this->assertTrue( $this->object->isModified() );
196
	}
197
198
199
	public function testGetPrice()
200
	{
201
		$this->assertEquals( '1.00', $this->object->getPrice() );
202
	}
203
204
205
	public function testSetPrice()
206
	{
207
		$return = $this->object->setPrice( '3.75' );
208
209
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Product\Attribute\Iface::class, $return );
210
		$this->assertEquals( '3.75', $this->object->getPrice() );
211
		$this->assertTrue( $this->object->isModified() );
212
	}
213
214
215
	public function testSetPriceNull()
216
	{
217
		$return = $this->object->setPrice( null );
218
219
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Product\Attribute\Iface::class, $return );
220
		$this->assertEquals( null, $this->object->getPrice() );
221
		$this->assertTrue( $this->object->isModified() );
222
	}
223
224
225
	public function testGetTimeModified()
226
	{
227
		$regexp = '/^[0-9]{4}-[0-1][0-9]-[0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9]$/';
228
		$this->assertRegExp( $regexp, $this->object->getTimeModified() );
229
	}
230
231
232
	public function testGetTimeCreated()
233
	{
234
		$this->assertEquals( '2011-01-01 00:00:01', $this->object->getTimeCreated() );
235
	}
236
237
238
	public function testGetEditor()
239
	{
240
		$this->assertEquals( 'unitTestUser', $this->object->editor() );
241
	}
242
243
244
	public function testGetResourceType()
245
	{
246
		$this->assertEquals( 'order/base/product/attribute', $this->object->getResourceType() );
247
	}
248
249
250
	public function testCopyFrom()
251
	{
252
		$attrManager = \Aimeos\MShop\Attribute\Manager\Factory::create( \TestHelper::context() );
253
		$item = $attrManager->search( $attrManager->filter() )->first();
254
255
		$return = $this->object->copyFrom( $item );
256
257
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Product\Attribute\Iface::class, $return );
258
		$this->assertEquals( $item->getId(), $this->object->getAttributeId() );
259
		$this->assertEquals( $item->getName(), $this->object->getName() );
260
		$this->assertEquals( $item->getType(), $this->object->getCode() );
261
		$this->assertEquals( $item->getCode(), $this->object->getValue() );
262
	}
263
264
265
	public function testFromArray()
266
	{
267
		$item = new \Aimeos\MShop\Order\Item\Base\Product\Attribute\Standard();
268
269
		$list = $entries = array(
270
			'order.base.product.attribute.id' => 1,
271
			'order.base.product.attribute.siteid' => 123,
272
			'order.base.product.attribute.attributeid' => 2,
273
			'order.base.product.attribute.parentid' => 3,
274
			'order.base.product.attribute.type' => 'variant',
275
			'order.base.product.attribute.code' => 'test',
276
			'order.base.product.attribute.value' => 'value',
277
			'order.base.product.attribute.name' => 'test item',
278
			'order.base.product.attribute.price' => '2.00',
279
			'order.base.product.attribute.quantity' => 4,
280
		);
281
282
		$item = $item->fromArray( $entries, true );
283
284
		$this->assertEquals( [], $entries );
285
		$this->assertEquals( $list['order.base.product.attribute.id'], $item->getId() );
286
		$this->assertEquals( $list['order.base.product.attribute.siteid'], $item->getSiteId() );
287
		$this->assertEquals( $list['order.base.product.attribute.attributeid'], $item->getAttributeId() );
288
		$this->assertEquals( $list['order.base.product.attribute.parentid'], $item->getParentId() );
289
		$this->assertEquals( $list['order.base.product.attribute.type'], $item->getType() );
290
		$this->assertEquals( $list['order.base.product.attribute.code'], $item->getCode() );
291
		$this->assertEquals( $list['order.base.product.attribute.name'], $item->getName() );
292
		$this->assertEquals( $list['order.base.product.attribute.value'], $item->getValue() );
293
		$this->assertEquals( $list['order.base.product.attribute.price'], $item->getPrice() );
294
		$this->assertEquals( $list['order.base.product.attribute.quantity'], $item->getQuantity() );
295
	}
296
297
298
	public function testToArray()
299
	{
300
		$list = $this->object->toArray( true );
301
302
		$this->assertEquals( count( $this->values ), count( $list ) );
303
304
		$this->assertEquals( $this->object->getId(), $list['order.base.product.attribute.id'] );
305
		$this->assertEquals( $this->object->getSiteId(), $list['order.base.product.attribute.siteid'] );
306
		$this->assertEquals( $this->object->getAttributeId(), $list['order.base.product.attribute.attributeid'] );
307
		$this->assertEquals( $this->object->getParentId(), $list['order.base.product.attribute.parentid'] );
308
		$this->assertEquals( $this->object->getType(), $list['order.base.product.attribute.type'] );
309
		$this->assertEquals( $this->object->getCode(), $list['order.base.product.attribute.code'] );
310
		$this->assertEquals( $this->object->getName(), $list['order.base.product.attribute.name'] );
311
		$this->assertEquals( $this->object->getValue(), $list['order.base.product.attribute.value'] );
312
		$this->assertEquals( $this->object->getPrice(), $list['order.base.product.attribute.price'] );
313
		$this->assertEquals( $this->object->getQuantity(), $list['order.base.product.attribute.quantity'] );
314
		$this->assertEquals( $this->object->getTimeModified(), $list['order.base.product.attribute.mtime'] );
315
		$this->assertEquals( $this->object->getTimeCreated(), $list['order.base.product.attribute.ctime'] );
316
		$this->assertEquals( $this->object->editor(), $list['order.base.product.attribute.editor'] );
317
	}
318
319
320
	public function testIsModified()
321
	{
322
		$this->assertFalse( $this->object->isModified() );
323
	}
324
}
325