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\Service\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.service.attribute.id' => 3, |
23
|
|
|
'order.base.service.attribute.siteid' => 99, |
24
|
|
|
'order.base.service.attribute.attributeid' => 22, |
25
|
|
|
'order.base.service.attribute.parentid' => 42, |
26
|
|
|
'order.base.service.attribute.type' => 'UnitType', |
27
|
|
|
'order.base.service.attribute.name' => 'UnitName', |
28
|
|
|
'order.base.service.attribute.code' => 'UnitCode', |
29
|
|
|
'order.base.service.attribute.value' => 'UnitValue', |
30
|
|
|
'order.base.service.attribute.price' => '1.00', |
31
|
|
|
'order.base.service.attribute.quantity' => 1, |
32
|
|
|
'order.base.service.attribute.mtime' => '2020-12-31 23:59:59', |
33
|
|
|
'order.base.service.attribute.ctime' => '2011-01-01 00:00:01', |
34
|
|
|
'order.base.service.attribute.editor' => 'unitTestUser' |
35
|
|
|
); |
36
|
|
|
|
37
|
|
|
$this->object = new \Aimeos\MShop\Order\Item\Base\Service\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( 3, $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\Service\Attribute\Iface::class, $return ); |
58
|
|
|
$this->assertEquals( null, $this->object->getId() ); |
59
|
|
|
$this->assertTrue( $this->object->isModified() ); |
60
|
|
|
|
61
|
|
|
$return = $this->object->setId( 99 ); |
62
|
|
|
|
63
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Attribute\Iface::class, $return ); |
64
|
|
|
$this->assertEquals( 99, $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\Service\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( 42, $this->object->getParentId() ); |
104
|
|
|
$this->assertFalse( $this->object->isModified() ); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
|
108
|
|
|
public function testSetParentId() |
109
|
|
|
{ |
110
|
|
|
$return = $this->object->setParentId( 98 ); |
111
|
|
|
|
112
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Attribute\Iface::class, $return ); |
113
|
|
|
$this->assertEquals( 98, $this->object->getParentId() ); |
114
|
|
|
$this->assertTrue( $this->object->isModified() ); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
|
118
|
|
|
public function testGetType() |
119
|
|
|
{ |
120
|
|
|
$this->assertEquals( 'UnitType', $this->object->getType() ); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
|
124
|
|
|
public function testSetType() |
125
|
|
|
{ |
126
|
|
|
$return = $this->object->setType( 'testType' ); |
127
|
|
|
|
128
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Attribute\Iface::class, $return ); |
129
|
|
|
$this->assertEquals( 'testType', $this->object->getType() ); |
130
|
|
|
$this->assertTrue( $this->object->isModified() ); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
|
134
|
|
|
public function testGetCode() |
135
|
|
|
{ |
136
|
|
|
$this->assertEquals( 'UnitCode', $this->object->getCode() ); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
|
140
|
|
|
public function testSetCode() |
141
|
|
|
{ |
142
|
|
|
$return = $this->object->setCode( 'testCode' ); |
143
|
|
|
|
144
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Attribute\Iface::class, $return ); |
145
|
|
|
$this->assertEquals( 'testCode', $this->object->getCode() ); |
146
|
|
|
$this->assertTrue( $this->object->isModified() ); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
|
150
|
|
|
public function testGetValue() |
151
|
|
|
{ |
152
|
|
|
$this->assertEquals( 'UnitValue', $this->object->getValue() ); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
|
156
|
|
|
public function testSetValue() |
157
|
|
|
{ |
158
|
|
|
$return = $this->object->setValue( 'custom' ); |
159
|
|
|
|
160
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Attribute\Iface::class, $return ); |
161
|
|
|
$this->assertEquals( 'custom', $this->object->getValue() ); |
162
|
|
|
$this->assertTrue( $this->object->isModified() ); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
|
166
|
|
|
public function testGetName() |
167
|
|
|
{ |
168
|
|
|
$this->assertEquals( 'UnitName', $this->object->getName() ); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
|
172
|
|
|
public function testSetName() |
173
|
|
|
{ |
174
|
|
|
$return = $this->object->setName( 'testName' ); |
175
|
|
|
|
176
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Attribute\Iface::class, $return ); |
177
|
|
|
$this->assertEquals( 'testName', $this->object->getName() ); |
178
|
|
|
$this->assertTrue( $this->object->isModified() ); |
179
|
|
|
|
180
|
|
|
$this->assertEquals( '', $this->object->setName( null )->getName() ); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
|
184
|
|
|
public function testGetQuantity() |
185
|
|
|
{ |
186
|
|
|
$this->assertEquals( 1, $this->object->getQuantity() ); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
|
190
|
|
|
public function testSetQuantity() |
191
|
|
|
{ |
192
|
|
|
$return = $this->object->setQuantity( 3 ); |
193
|
|
|
|
194
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Attribute\Iface::class, $return ); |
195
|
|
|
$this->assertEquals( 3, $this->object->getQuantity() ); |
196
|
|
|
$this->assertTrue( $this->object->isModified() ); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
|
200
|
|
|
public function testGetPrice() |
201
|
|
|
{ |
202
|
|
|
$this->assertEquals( '1.00', $this->object->getPrice() ); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
|
206
|
|
|
public function testSetPrice() |
207
|
|
|
{ |
208
|
|
|
$return = $this->object->setPrice( '3.75' ); |
209
|
|
|
|
210
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Attribute\Iface::class, $return ); |
211
|
|
|
$this->assertEquals( '3.75', $this->object->getPrice() ); |
212
|
|
|
$this->assertTrue( $this->object->isModified() ); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
|
216
|
|
|
public function testSetPriceNull() |
217
|
|
|
{ |
218
|
|
|
$return = $this->object->setPrice( null ); |
219
|
|
|
|
220
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Attribute\Iface::class, $return ); |
221
|
|
|
$this->assertEquals( null, $this->object->getPrice() ); |
222
|
|
|
$this->assertTrue( $this->object->isModified() ); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
|
226
|
|
|
public function testGetTimeModified() |
227
|
|
|
{ |
228
|
|
|
$this->assertEquals( '2020-12-31 23:59:59', $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/service/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\Service\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\Service\Attribute\Standard(); |
268
|
|
|
|
269
|
|
|
$list = $entries = array( |
270
|
|
|
'order.base.service.attribute.id' => 1, |
271
|
|
|
'order.base.service.attribute.attributeid' => 2, |
272
|
|
|
'order.base.service.attribute.parentid' => 3, |
273
|
|
|
'order.base.service.attribute.type' => 'delivery', |
274
|
|
|
'order.base.service.attribute.code' => 'test', |
275
|
|
|
'order.base.service.attribute.value' => 'value', |
276
|
|
|
'order.base.service.attribute.name' => 'test item', |
277
|
|
|
'order.base.service.attribute.price' => '2.00', |
278
|
|
|
'order.base.service.attribute.quantity' => 4, |
279
|
|
|
); |
280
|
|
|
|
281
|
|
|
$item = $item->fromArray( $entries, true ); |
282
|
|
|
|
283
|
|
|
$this->assertEquals( [], $entries ); |
284
|
|
|
$this->assertEquals( '', $item->getSiteId() ); |
285
|
|
|
$this->assertEquals( $list['order.base.service.attribute.id'], $item->getId() ); |
286
|
|
|
$this->assertEquals( $list['order.base.service.attribute.attributeid'], $item->getAttributeId() ); |
287
|
|
|
$this->assertEquals( $list['order.base.service.attribute.parentid'], $item->getParentId() ); |
288
|
|
|
$this->assertEquals( $list['order.base.service.attribute.type'], $item->getType() ); |
289
|
|
|
$this->assertEquals( $list['order.base.service.attribute.code'], $item->getCode() ); |
290
|
|
|
$this->assertEquals( $list['order.base.service.attribute.name'], $item->getName() ); |
291
|
|
|
$this->assertEquals( $list['order.base.service.attribute.value'], $item->getValue() ); |
292
|
|
|
$this->assertEquals( $list['order.base.service.attribute.price'], $item->getPrice() ); |
293
|
|
|
$this->assertEquals( $list['order.base.service.attribute.quantity'], $item->getQuantity() ); |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
|
297
|
|
|
public function testToArray() |
298
|
|
|
{ |
299
|
|
|
$list = $this->object->toArray( true ); |
300
|
|
|
|
301
|
|
|
$this->assertEquals( count( $this->values ), count( $list ) ); |
302
|
|
|
|
303
|
|
|
$this->assertEquals( $this->object->getId(), $list['order.base.service.attribute.id'] ); |
304
|
|
|
$this->assertEquals( $this->object->getSiteId(), $list['order.base.service.attribute.siteid'] ); |
305
|
|
|
$this->assertEquals( $this->object->getAttributeId(), $list['order.base.service.attribute.attributeid'] ); |
306
|
|
|
$this->assertEquals( $this->object->getParentId(), $list['order.base.service.attribute.parentid'] ); |
307
|
|
|
$this->assertEquals( $this->object->getType(), $list['order.base.service.attribute.type'] ); |
308
|
|
|
$this->assertEquals( $this->object->getCode(), $list['order.base.service.attribute.code'] ); |
309
|
|
|
$this->assertEquals( $this->object->getName(), $list['order.base.service.attribute.name'] ); |
310
|
|
|
$this->assertEquals( $this->object->getValue(), $list['order.base.service.attribute.value'] ); |
311
|
|
|
$this->assertEquals( $this->object->getPrice(), $list['order.base.service.attribute.price'] ); |
312
|
|
|
$this->assertEquals( $this->object->getQuantity(), $list['order.base.service.attribute.quantity'] ); |
313
|
|
|
$this->assertEquals( $this->object->getTimeModified(), $list['order.base.service.attribute.mtime'] ); |
314
|
|
|
$this->assertEquals( $this->object->getTimeCreated(), $list['order.base.service.attribute.ctime'] ); |
315
|
|
|
$this->assertEquals( $this->object->getTimeModified(), $list['order.base.service.attribute.mtime'] ); |
316
|
|
|
$this->assertEquals( $this->object->editor(), $list['order.base.service.attribute.editor'] ); |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
public function testIsModified() |
320
|
|
|
{ |
321
|
|
|
$this->assertFalse( $this->object->isModified() ); |
322
|
|
|
} |
323
|
|
|
} |
324
|
|
|
|