Total Complexity | 46 |
Total Lines | 623 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Complex classes like StandardTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use StandardTest, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
13 | class StandardTest extends \PHPUnit\Framework\TestCase |
||
14 | { |
||
15 | private $object; |
||
16 | private $values; |
||
17 | private $price; |
||
18 | private $attributes; |
||
19 | private $transactions; |
||
20 | |||
21 | |||
22 | protected function setUp() : void |
||
23 | { |
||
24 | $this->price = \Aimeos\MShop::create( \TestHelper::context(), 'price' )->create(); |
||
25 | |||
26 | $attrValues = array( |
||
27 | 'order.base.service.attribute.id' => 3, |
||
28 | 'order.base.service.attribute.siteid' => 99, |
||
29 | 'order.base.service.attribute.parentid' => 42, |
||
30 | 'order.base.service.attribute.name' => 'UnitName', |
||
31 | 'order.base.service.attribute.type' => 'default', |
||
32 | 'order.base.service.attribute.code' => 'UnitCode', |
||
33 | 'order.base.service.attribute.value' => 'UnitValue', |
||
34 | 'order.base.service.attribute.mtime' => '2020-12-31 23:59:59', |
||
35 | 'order.base.service.attribute.ctime' => '2011-01-01 00:00:01', |
||
36 | 'order.base.service.attribute.editor' => 'unitTestUser' |
||
37 | ); |
||
38 | |||
39 | $this->attributes = [new \Aimeos\MShop\Order\Item\Base\Service\Attribute\Standard( $attrValues )]; |
||
40 | |||
41 | |||
42 | $txValues = array( |
||
43 | 'order.base.service.transaction.id' => 3, |
||
44 | 'order.base.service.transaction.siteid' => 99, |
||
45 | 'order.base.service.transaction.parentid' => 42, |
||
46 | 'order.base.service.transaction.type' => 'payment', |
||
47 | 'order.base.service.attribute.config' => [], |
||
48 | 'order.base.service.attribute.status' => 6, |
||
49 | 'order.base.service.attribute.mtime' => '2020-12-31 23:59:59', |
||
50 | 'order.base.service.attribute.ctime' => '2011-01-01 00:00:01', |
||
51 | 'order.base.service.attribute.editor' => 'unitTestUser' |
||
52 | ); |
||
53 | |||
54 | $this->transactions = [new \Aimeos\MShop\Order\Item\Base\Service\Transaction\Standard( $this->price, $txValues )]; |
||
55 | |||
56 | |||
57 | $this->values = array( |
||
58 | 'order.base.service.id' => 1, |
||
59 | 'order.base.service.siteid' => 99, |
||
60 | 'order.base.service.serviceid' => 'ServiceID', |
||
61 | 'order.base.service.baseid' => 42, |
||
62 | 'order.base.service.code' => 'UnitCode', |
||
63 | 'order.base.service.name' => 'UnitName', |
||
64 | 'order.base.service.mediaurl' => 'Url for test', |
||
65 | 'order.base.service.position' => 1, |
||
66 | 'order.base.service.type' => 'payment', |
||
67 | 'order.base.service.mtime' => '2012-01-01 00:00:01', |
||
68 | 'order.base.service.ctime' => '2011-01-01 00:00:01', |
||
69 | 'order.base.service.editor' => 'unitTestUser' |
||
70 | ); |
||
71 | |||
72 | $servItem = \Aimeos\MShop::create( \TestHelper::context(), 'service' )->create(); |
||
73 | $this->object = new \Aimeos\MShop\Order\Item\Base\Service\Standard( |
||
74 | $this->price, $this->values, $this->attributes, $this->transactions, $servItem |
||
75 | ); |
||
76 | } |
||
77 | |||
78 | |||
79 | protected function tearDown() : void |
||
80 | { |
||
81 | unset( $this->object ); |
||
82 | } |
||
83 | |||
84 | |||
85 | public function testGetServiceItem() |
||
86 | { |
||
87 | $this->assertInstanceOf( \Aimeos\MShop\Service\Item\Iface::class, $this->object->getServiceItem() ); |
||
88 | $this->assertNull( ( new \Aimeos\MShop\Order\Item\Base\Service\Standard( $this->price ) )->getServiceItem() ); |
||
89 | } |
||
90 | |||
91 | |||
92 | public function testGetId() |
||
93 | { |
||
94 | $this->assertEquals( 1, $this->object->getId() ); |
||
95 | } |
||
96 | |||
97 | |||
98 | public function testSetId() |
||
99 | { |
||
100 | $return = $this->object->setId( null ); |
||
101 | |||
102 | $this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Iface::class, $return ); |
||
103 | $this->assertEquals( null, $this->object->getId() ); |
||
104 | $this->assertTrue( $this->object->isModified() ); |
||
105 | |||
106 | $return = $this->object->setId( 5 ); |
||
107 | |||
108 | $this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Iface::class, $return ); |
||
109 | $this->assertEquals( 5, $this->object->getId() ); |
||
110 | $this->assertFalse( $this->object->isModified() ); |
||
111 | } |
||
112 | |||
113 | |||
114 | public function testGetSiteId() |
||
115 | { |
||
116 | $this->assertEquals( 99, $this->object->getSiteId() ); |
||
117 | } |
||
118 | |||
119 | |||
120 | public function testSetSiteId() |
||
121 | { |
||
122 | $this->object->setSiteId( 100 ); |
||
123 | $this->assertEquals( 100, $this->object->getSiteId() ); |
||
124 | $this->assertTrue( $this->object->isModified() ); |
||
125 | } |
||
126 | |||
127 | |||
128 | public function testGetBaseId() |
||
129 | { |
||
130 | $this->assertEquals( 42, $this->object->getBaseId() ); |
||
131 | } |
||
132 | |||
133 | |||
134 | public function testSetBaseId() |
||
135 | { |
||
136 | $return = $this->object->setBaseId( 111 ); |
||
137 | |||
138 | $this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Iface::class, $return ); |
||
139 | $this->assertEquals( 111, $this->object->getBaseId() ); |
||
140 | $this->assertTrue( $this->object->isModified() ); |
||
141 | } |
||
142 | |||
143 | |||
144 | public function testSetBaseIdReset() |
||
145 | { |
||
146 | $return = $this->object->setBaseId( null ); |
||
147 | |||
148 | $this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Iface::class, $return ); |
||
149 | $this->assertEquals( null, $this->object->getBaseId() ); |
||
150 | $this->assertTrue( $this->object->isModified() ); |
||
151 | } |
||
152 | |||
153 | |||
154 | public function testGetServiceId() |
||
155 | { |
||
156 | $this->assertEquals( 'ServiceID', $this->object->getServiceId() ); |
||
157 | } |
||
158 | |||
159 | |||
160 | public function testSetServiceId() |
||
161 | { |
||
162 | $return = $this->object->setServiceId( 'testServiceID' ); |
||
163 | |||
164 | $this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Iface::class, $return ); |
||
165 | $this->assertEquals( 'testServiceID', $this->object->getServiceId() ); |
||
166 | $this->assertTrue( $this->object->isModified() ); |
||
167 | } |
||
168 | |||
169 | |||
170 | public function testGetCode() |
||
171 | { |
||
172 | $this->assertEquals( 'UnitCode', $this->object->getCode() ); |
||
173 | } |
||
174 | |||
175 | |||
176 | public function testSetCode() |
||
177 | { |
||
178 | $return = $this->object->setCode( 'testCode' ); |
||
179 | |||
180 | $this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Iface::class, $return ); |
||
181 | $this->assertEquals( 'testCode', $this->object->getCode() ); |
||
182 | $this->assertTrue( $this->object->isModified() ); |
||
183 | } |
||
184 | |||
185 | |||
186 | public function testGetName() |
||
187 | { |
||
188 | $this->assertEquals( 'UnitName', $this->object->getName() ); |
||
189 | } |
||
190 | |||
191 | |||
192 | public function testSetName() |
||
193 | { |
||
194 | $return = $this->object->setName( 'testName' ); |
||
195 | |||
196 | $this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Iface::class, $return ); |
||
197 | $this->assertEquals( 'testName', $this->object->getName() ); |
||
198 | $this->assertTrue( $this->object->isModified() ); |
||
199 | } |
||
200 | |||
201 | |||
202 | public function testGetMediaUrl() |
||
203 | { |
||
204 | $this->assertEquals( 'Url for test', $this->object->getMediaUrl() ); |
||
205 | } |
||
206 | |||
207 | |||
208 | public function testSetMediaUrl() |
||
209 | { |
||
210 | $return = $this->object->setMediaUrl( 'testUrl' ); |
||
211 | |||
212 | $this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Iface::class, $return ); |
||
213 | $this->assertEquals( 'testUrl', $this->object->getMediaUrl() ); |
||
214 | $this->assertTrue( $this->object->isModified() ); |
||
215 | } |
||
216 | |||
217 | |||
218 | public function testGetType() |
||
219 | { |
||
220 | $this->assertEquals( 'payment', $this->object->getType() ); |
||
221 | } |
||
222 | |||
223 | |||
224 | public function testSetType() |
||
225 | { |
||
226 | $return = $this->object->setType( 'delivery' ); |
||
227 | |||
228 | $this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Iface::class, $return ); |
||
229 | $this->assertEquals( 'delivery', $this->object->getType() ); |
||
230 | $this->assertTrue( $this->object->isModified() ); |
||
231 | } |
||
232 | |||
233 | |||
234 | public function testGetPrice() |
||
235 | { |
||
236 | $this->assertSame( $this->price, $this->object->getPrice() ); |
||
237 | } |
||
238 | |||
239 | |||
240 | public function testSetPrice() |
||
241 | { |
||
242 | $this->price->setCosts( '5.00' ); |
||
243 | $return = $this->object->setPrice( $this->price ); |
||
244 | |||
245 | $this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Iface::class, $return ); |
||
246 | $this->assertFalse( $this->object->isModified() ); |
||
247 | $this->assertSame( $this->price, $this->object->getPrice() ); |
||
248 | } |
||
249 | |||
250 | |||
251 | public function testGetPosition() |
||
252 | { |
||
253 | $this->assertEquals( 1, $this->object->getPosition() ); |
||
254 | } |
||
255 | |||
256 | |||
257 | public function testSetPosition() |
||
258 | { |
||
259 | $return = $this->object->setPosition( 2 ); |
||
260 | |||
261 | $this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Iface::class, $return ); |
||
262 | $this->assertEquals( 2, $this->object->getPosition() ); |
||
263 | $this->assertTrue( $this->object->isModified() ); |
||
264 | } |
||
265 | |||
266 | |||
267 | public function testSetPositionReset() |
||
268 | { |
||
269 | $return = $this->object->setPosition( null ); |
||
270 | |||
271 | $this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Iface::class, $return ); |
||
272 | $this->assertEquals( null, $this->object->getPosition() ); |
||
273 | $this->assertTrue( $this->object->isModified() ); |
||
274 | } |
||
275 | |||
276 | |||
277 | public function testSetPositionInvalid() |
||
278 | { |
||
279 | $this->expectException( \Aimeos\MShop\Order\Exception::class ); |
||
280 | $this->object->setPosition( -1 ); |
||
281 | } |
||
282 | |||
283 | |||
284 | public function testAddAttributeItems() |
||
285 | { |
||
286 | $item = \Aimeos\MShop::create( \TestHelper::context(), 'order/base/service' )->createAttributeItem(); |
||
287 | |||
288 | $return = $this->object->addAttributeItems( [$item] ); |
||
289 | |||
290 | $this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Iface::class, $return ); |
||
291 | $this->assertEquals( 2, count( $this->object->getAttributeItems() ) ); |
||
292 | $this->assertTrue( $this->object->isModified() ); |
||
293 | } |
||
294 | |||
295 | |||
296 | public function testGetAttribute() |
||
333 | } |
||
334 | |||
335 | |||
336 | public function testGetAttributeList() |
||
337 | { |
||
338 | $manager = \Aimeos\MShop::create( \TestHelper::context(), 'order' ); |
||
339 | $attManager = $manager->getSubManager( 'base' )->getSubManager( 'service' )->getSubManager( 'attribute' ); |
||
340 | |||
341 | $attrItem001 = $attManager->create(); |
||
342 | $attrItem001->setAttributeId( '1' ); |
||
343 | $attrItem001->setCode( 'code_001' ); |
||
344 | $attrItem001->setType( 'test_001' ); |
||
345 | $attrItem001->setValue( 'value_001' ); |
||
346 | |||
347 | $attrItem002 = $attManager->create(); |
||
348 | $attrItem002->setAttributeId( '2' ); |
||
349 | $attrItem002->setCode( 'code_001' ); |
||
350 | $attrItem002->setType( 'test_001' ); |
||
351 | $attrItem002->setValue( 'value_002' ); |
||
352 | |||
353 | $this->object->setAttributeItems( array( $attrItem001, $attrItem002 ) ); |
||
354 | |||
355 | $result = $this->object->getAttribute( 'code_001', 'test_001' ); |
||
356 | $this->assertEquals( ['value_001', 'value_002'], $result ); |
||
357 | } |
||
358 | |||
359 | |||
360 | public function testGetAttributeItem() |
||
361 | { |
||
362 | $manager = \Aimeos\MShop::create( \TestHelper::context(), 'order' ); |
||
363 | $attManager = $manager->getSubManager( 'base' )->getSubManager( 'service' )->getSubManager( 'attribute' ); |
||
364 | |||
365 | $attrItem001 = $attManager->create(); |
||
366 | $attrItem001->setAttributeId( '1' ); |
||
367 | $attrItem001->setCode( 'code_001' ); |
||
368 | $attrItem001->setValue( 'value_001' ); |
||
369 | |||
370 | $attrItem002 = $attManager->create(); |
||
371 | $attrItem002->setAttributeId( '2' ); |
||
372 | $attrItem002->setCode( 'code_002' ); |
||
373 | $attrItem002->setType( 'test_002' ); |
||
374 | $attrItem002->setValue( 'value_002' ); |
||
375 | |||
376 | $this->object->setAttributeItems( array( $attrItem001, $attrItem002 ) ); |
||
377 | |||
378 | $result = $this->object->getAttributeItem( 'code_001' ); |
||
379 | $this->assertEquals( 'value_001', $result->getValue() ); |
||
380 | |||
381 | $result = $this->object->getAttributeItem( 'code_002', 'test_002' ); |
||
382 | $this->assertEquals( 'value_002', $result->getValue() ); |
||
383 | |||
384 | $result = $this->object->getAttributeItem( 'code_002' ); |
||
385 | $this->assertEquals( null, $result ); |
||
386 | |||
387 | $result = $this->object->getAttributeItem( 'code_003' ); |
||
388 | $this->assertEquals( null, $result ); |
||
389 | |||
390 | $this->object->setAttributeItems( [] ); |
||
391 | |||
392 | $result = $this->object->getAttributeItem( 'code_001' ); |
||
393 | $this->assertEquals( null, $result ); |
||
394 | } |
||
395 | |||
396 | |||
397 | public function testGetAttributeItemList() |
||
398 | { |
||
399 | $manager = \Aimeos\MShop::create( \TestHelper::context(), 'order' ); |
||
400 | $attManager = $manager->getSubManager( 'base' )->getSubManager( 'service' )->getSubManager( 'attribute' ); |
||
401 | |||
402 | $attrItem001 = $attManager->create(); |
||
403 | $attrItem001->setAttributeId( '1' ); |
||
404 | $attrItem001->setCode( 'code_001' ); |
||
405 | $attrItem001->setType( 'test_001' ); |
||
406 | $attrItem001->setValue( 'value_001' ); |
||
407 | |||
408 | $attrItem002 = $attManager->create(); |
||
409 | $attrItem002->setAttributeId( '2' ); |
||
410 | $attrItem002->setCode( 'code_001' ); |
||
411 | $attrItem002->setType( 'test_001' ); |
||
412 | $attrItem002->setValue( 'value_002' ); |
||
413 | |||
414 | $this->object->setAttributeItems( array( $attrItem001, $attrItem002 ) ); |
||
415 | |||
416 | $result = $this->object->getAttributeItem( 'code_001', 'test_001' ); |
||
417 | $this->assertEquals( 2, count( $result ) ); |
||
418 | } |
||
419 | |||
420 | |||
421 | public function testGetAttributeItems() |
||
422 | { |
||
423 | $this->assertEquals( $this->attributes, $this->object->getAttributeItems()->toArray() ); |
||
424 | } |
||
425 | |||
426 | |||
427 | public function testGetAttributeItemsByType() |
||
428 | { |
||
429 | $this->assertEquals( $this->attributes, $this->object->getAttributeItems( 'default' )->toArray() ); |
||
430 | } |
||
431 | |||
432 | |||
433 | public function testGetAttributeItemsInvalidType() |
||
434 | { |
||
435 | $this->assertEquals( [], $this->object->getAttributeItems( 'invalid' )->toArray() ); |
||
436 | } |
||
437 | |||
438 | |||
439 | public function testSetAttributeItem() |
||
440 | { |
||
441 | $manager = \Aimeos\MShop::create( \TestHelper::context(), 'order' ); |
||
442 | $attManager = $manager->getSubManager( 'base' )->getSubManager( 'service' )->getSubManager( 'attribute' ); |
||
443 | |||
444 | $item = $attManager->create(); |
||
445 | $item->setAttributeId( '1' ); |
||
446 | $item->setCode( 'test_code' ); |
||
447 | $item->setType( 'test_type' ); |
||
448 | $item->setValue( 'test_value' ); |
||
449 | |||
450 | $return = $this->object->setAttributeItem( $item ); |
||
451 | |||
452 | $this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Iface::class, $return ); |
||
453 | $this->assertEquals( 'test_value', $this->object->getAttributeItem( 'test_code', 'test_type' )->getValue() ); |
||
454 | $this->assertTrue( $this->object->isModified() ); |
||
455 | |||
456 | $item = $attManager->create(); |
||
457 | $item->setAttributeId( '1' ); |
||
458 | $item->setCode( 'test_code' ); |
||
459 | $item->setType( 'test_type' ); |
||
460 | $item->setValue( 'test_value2' ); |
||
461 | |||
462 | $return = $this->object->setAttributeItem( $item ); |
||
463 | |||
464 | $this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Iface::class, $return ); |
||
465 | $this->assertEquals( 'test_value2', $this->object->getAttributeItem( 'test_code', 'test_type' )->getValue() ); |
||
466 | $this->assertTrue( $this->object->isModified() ); |
||
467 | } |
||
468 | |||
469 | |||
470 | public function testSetAttributeItems() |
||
485 | } |
||
486 | |||
487 | |||
488 | public function testGetTransactions() |
||
489 | { |
||
490 | $this->assertEquals( $this->transactions, $this->object->getTransactions()->toArray() ); |
||
491 | } |
||
492 | |||
493 | |||
494 | public function testSetTransactions() |
||
495 | { |
||
496 | $txValues = array( |
||
497 | 'order.base.service.transaction.id' => 5, |
||
498 | 'order.base.service.transaction.siteid' => 100, |
||
499 | 'order.base.service.transaction.parentid' => 50, |
||
500 | 'order.base.service.transaction.type' => 'refund', |
||
501 | 'order.base.service.attribute.config' => ['tx' => '001'], |
||
502 | 'order.base.service.attribute.status' => 3, |
||
503 | 'order.base.service.attribute.mtime' => '2020-12-31 23:59:59', |
||
504 | 'order.base.service.attribute.ctime' => '2011-01-01 00:00:01', |
||
505 | 'order.base.service.attribute.editor' => 'unitTestUser' |
||
506 | ); |
||
507 | |||
508 | $list = [new \Aimeos\MShop\Order\Item\Base\Service\Transaction\Standard( $this->price, $txValues )]; |
||
509 | $result = $this->object->setTransactions( $list ); |
||
510 | |||
511 | $this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Iface::class, $result ); |
||
512 | $this->assertEquals( $list, $this->object->getTransactions()->toArray() ); |
||
513 | $this->assertTrue( $this->object->isModified() ); |
||
514 | } |
||
515 | |||
516 | |||
517 | public function testGetTimeModified() |
||
518 | { |
||
519 | $this->assertEquals( '2012-01-01 00:00:01', $this->object->getTimeModified() ); |
||
520 | } |
||
521 | |||
522 | |||
523 | public function testGetTimeCreated() |
||
524 | { |
||
525 | $this->assertEquals( '2011-01-01 00:00:01', $this->object->getTimeCreated() ); |
||
526 | } |
||
527 | |||
528 | |||
529 | public function testGetEditor() |
||
530 | { |
||
531 | $this->assertEquals( 'unitTestUser', $this->object->editor() ); |
||
532 | } |
||
533 | |||
534 | |||
535 | public function testFromArray() |
||
536 | { |
||
537 | $item = new \Aimeos\MShop\Order\Item\Base\Service\Standard( new \Aimeos\MShop\Price\Item\Standard() ); |
||
538 | |||
539 | $list = $entries = array( |
||
540 | 'order.base.service.id' => 1, |
||
541 | 'order.base.service.baseid' => 2, |
||
542 | 'order.base.service.serviceid' => 3, |
||
543 | 'order.base.service.position' => 4, |
||
544 | 'order.base.service.currencyid' => 'EUR', |
||
545 | 'order.base.service.price' => '1.00', |
||
546 | 'order.base.service.costs' => '0.50', |
||
547 | 'order.base.service.rebate' => '0.50', |
||
548 | 'order.base.service.taxrates' => ['tax' => '20.00'], |
||
549 | 'order.base.service.taxvalue' => '0.2500', |
||
550 | 'order.base.service.taxflag' => 1, |
||
551 | 'order.base.service.code' => 'test', |
||
552 | 'order.base.service.name' => 'test item', |
||
553 | 'order.base.service.type' => 'delivery', |
||
554 | ); |
||
555 | |||
556 | $item = $item->fromArray( $entries, true ); |
||
557 | |||
558 | $this->assertEquals( [], $entries ); |
||
559 | $this->assertEquals( '', $item->getSiteId() ); |
||
560 | $this->assertEquals( $list['order.base.service.id'], $item->getId() ); |
||
561 | $this->assertEquals( $list['order.base.service.baseid'], $item->getBaseId() ); |
||
562 | $this->assertEquals( $list['order.base.service.serviceid'], $item->getServiceId() ); |
||
563 | $this->assertEquals( $list['order.base.service.position'], $item->getPosition() ); |
||
564 | $this->assertEquals( $list['order.base.service.currencyid'], $item->getPrice()->getCurrencyId() ); |
||
565 | $this->assertEquals( $list['order.base.service.price'], $item->getPrice()->getValue() ); |
||
566 | $this->assertEquals( $list['order.base.service.costs'], $item->getPrice()->getCosts() ); |
||
567 | $this->assertEquals( $list['order.base.service.rebate'], $item->getPrice()->getRebate() ); |
||
568 | $this->assertEquals( $list['order.base.service.taxrates'], $item->getPrice()->getTaxRates() ); |
||
569 | $this->assertEquals( $list['order.base.service.taxvalue'], $item->getPrice()->getTaxValue() ); |
||
570 | $this->assertEquals( $list['order.base.service.taxflag'], $item->getPrice()->getTaxFlag() ); |
||
571 | $this->assertEquals( $list['order.base.service.code'], $item->getCode() ); |
||
572 | $this->assertEquals( $list['order.base.service.name'], $item->getName() ); |
||
573 | $this->assertEquals( $list['order.base.service.type'], $item->getType() ); |
||
574 | } |
||
575 | |||
576 | |||
577 | public function testToArray() |
||
578 | { |
||
579 | $arrayObject = $this->object->toArray( true ); |
||
580 | |||
581 | $this->assertEquals( count( $this->values ) + 8, count( $arrayObject ) ); |
||
582 | |||
583 | $this->assertEquals( $this->object->getId(), $arrayObject['order.base.service.id'] ); |
||
584 | $this->assertEquals( $this->object->getBaseId(), $arrayObject['order.base.service.baseid'] ); |
||
585 | $this->assertEquals( $this->object->getServiceId(), $arrayObject['order.base.service.serviceid'] ); |
||
586 | $this->assertEquals( $this->object->getPosition(), $arrayObject['order.base.service.position'] ); |
||
587 | $this->assertEquals( $this->object->getCode(), $arrayObject['order.base.service.code'] ); |
||
588 | $this->assertEquals( $this->object->getName(), $arrayObject['order.base.service.name'] ); |
||
589 | $this->assertEquals( $this->object->getType(), $arrayObject['order.base.service.type'] ); |
||
590 | $this->assertEquals( $this->object->getTimeCreated(), $arrayObject['order.base.service.ctime'] ); |
||
591 | $this->assertEquals( $this->object->getTimeModified(), $arrayObject['order.base.service.mtime'] ); |
||
592 | $this->assertEquals( $this->object->editor(), $arrayObject['order.base.service.editor'] ); |
||
593 | |||
594 | $price = $this->object->getPrice(); |
||
595 | $this->assertEquals( $price->getCurrencyId(), $arrayObject['order.base.service.currencyid'] ); |
||
596 | $this->assertEquals( $price->getValue(), $arrayObject['order.base.service.price'] ); |
||
597 | $this->assertEquals( $price->getCosts(), $arrayObject['order.base.service.costs'] ); |
||
598 | $this->assertEquals( $price->getRebate(), $arrayObject['order.base.service.rebate'] ); |
||
599 | $this->assertEquals( $price->getTaxRate(), $arrayObject['order.base.service.taxrate'] ); |
||
600 | $this->assertEquals( $price->getTaxRates(), $arrayObject['order.base.service.taxrates'] ); |
||
601 | $this->assertEquals( $price->getTaxValue(), $arrayObject['order.base.service.taxvalue'] ); |
||
602 | $this->assertEquals( $price->getTaxFlag(), $arrayObject['order.base.service.taxflag'] ); |
||
603 | } |
||
604 | |||
605 | public function testIsModified() |
||
606 | { |
||
607 | $this->assertFalse( $this->object->isModified() ); |
||
608 | } |
||
609 | |||
610 | |||
611 | public function testGetResourceType() |
||
614 | } |
||
615 | |||
616 | |||
617 | public function testCopyFrom() |
||
618 | { |
||
619 | $serviceCopy = new \Aimeos\MShop\Order\Item\Base\Service\Standard( $this->price ); |
||
620 | |||
621 | $manager = \Aimeos\MShop::create( \TestHelper::context(), 'service' ); |
||
622 | |||
623 | $filter = $manager->filter()->add( ['service.provider' => 'Standard'] ); |
||
624 | $item = $manager->search( $filter )->first( new \RuntimeException( 'No service found' ) ); |
||
625 | |||
626 | $return = $serviceCopy->copyFrom( $item->set( 'customprop', 123 ) ); |
||
627 | |||
628 | $this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Service\Iface::class, $return ); |
||
629 | $this->assertEquals( 'unitdeliverycode', $serviceCopy->getCode() ); |
||
630 | $this->assertEquals( 'unitlabel', $serviceCopy->getName() ); |
||
631 | $this->assertEquals( 'delivery', $serviceCopy->getType() ); |
||
632 | $this->assertEquals( '', $serviceCopy->getMediaUrl() ); |
||
633 | $this->assertEquals( '123', $serviceCopy->get( 'customprop' ) ); |
||
634 | |||
635 | $this->assertTrue( $serviceCopy->isModified() ); |
||
636 | } |
||
637 | } |
||
638 |