| Total Complexity | 46 |
| Total Lines | 617 |
| Duplicated Lines | 0 % |
| Changes | 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.service.attribute.id' => 3, |
||
| 28 | 'order.service.attribute.siteid' => 99, |
||
| 29 | 'order.service.attribute.parentid' => 42, |
||
| 30 | 'order.service.attribute.name' => 'UnitName', |
||
| 31 | 'order.service.attribute.type' => 'default', |
||
| 32 | 'order.service.attribute.code' => 'UnitCode', |
||
| 33 | 'order.service.attribute.value' => 'UnitValue', |
||
| 34 | 'order.service.attribute.mtime' => '2020-12-31 23:59:59', |
||
| 35 | 'order.service.attribute.ctime' => '2011-01-01 00:00:01', |
||
| 36 | 'order.service.attribute.editor' => 'unitTestUser' |
||
| 37 | ); |
||
| 38 | |||
| 39 | $this->attributes = [new \Aimeos\MShop\Order\Item\Service\Attribute\Standard( $attrValues )]; |
||
| 40 | |||
| 41 | |||
| 42 | $txValues = array( |
||
| 43 | 'order.service.transaction.id' => 3, |
||
| 44 | 'order.service.transaction.siteid' => 99, |
||
| 45 | 'order.service.transaction.parentid' => 42, |
||
| 46 | 'order.service.transaction.type' => 'payment', |
||
| 47 | 'order.service.attribute.config' => [], |
||
| 48 | 'order.service.attribute.status' => 6, |
||
| 49 | 'order.service.attribute.mtime' => '2020-12-31 23:59:59', |
||
| 50 | 'order.service.attribute.ctime' => '2011-01-01 00:00:01', |
||
| 51 | 'order.service.attribute.editor' => 'unitTestUser' |
||
| 52 | ); |
||
| 53 | |||
| 54 | $this->transactions = [new \Aimeos\MShop\Order\Item\Service\Transaction\Standard( $this->price, $txValues )]; |
||
| 55 | |||
| 56 | |||
| 57 | $this->values = array( |
||
| 58 | 'order.service.id' => 1, |
||
| 59 | 'order.service.siteid' => 99, |
||
| 60 | 'order.service.serviceid' => 'ServiceID', |
||
| 61 | 'order.service.parentid' => 42, |
||
| 62 | 'order.service.code' => 'UnitCode', |
||
| 63 | 'order.service.name' => 'UnitName', |
||
| 64 | 'order.service.mediaurl' => 'Url for test', |
||
| 65 | 'order.service.position' => 1, |
||
| 66 | 'order.service.type' => 'payment', |
||
| 67 | 'order.service.mtime' => '2012-01-01 00:00:01', |
||
| 68 | 'order.service.ctime' => '2011-01-01 00:00:01', |
||
| 69 | 'order.service.editor' => 'unitTestUser' |
||
| 70 | ); |
||
| 71 | |||
| 72 | $servItem = \Aimeos\MShop::create( \TestHelper::context(), 'service' )->create(); |
||
| 73 | $this->object = new \Aimeos\MShop\Order\Item\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\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\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\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 testGetParentId() |
||
| 129 | { |
||
| 130 | $this->assertEquals( 42, $this->object->getParentId() ); |
||
| 131 | } |
||
| 132 | |||
| 133 | |||
| 134 | public function testSetParentId() |
||
| 135 | { |
||
| 136 | $return = $this->object->setParentId( 111 ); |
||
| 137 | |||
| 138 | $this->assertInstanceOf( \Aimeos\MShop\Order\Item\Service\Iface::class, $return ); |
||
| 139 | $this->assertEquals( 111, $this->object->getParentId() ); |
||
| 140 | $this->assertTrue( $this->object->isModified() ); |
||
| 141 | } |
||
| 142 | |||
| 143 | |||
| 144 | public function testSetParentIdReset() |
||
| 145 | { |
||
| 146 | $return = $this->object->setParentId( null ); |
||
| 147 | |||
| 148 | $this->assertInstanceOf( \Aimeos\MShop\Order\Item\Service\Iface::class, $return ); |
||
| 149 | $this->assertEquals( null, $this->object->getParentId() ); |
||
| 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\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\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\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\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\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\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\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\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/service' )->createAttributeItem(); |
||
| 287 | |||
| 288 | $return = $this->object->addAttributeItems( [$item] ); |
||
| 289 | |||
| 290 | $this->assertInstanceOf( \Aimeos\MShop\Order\Item\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() |
||
| 297 | { |
||
| 298 | $attManager = \Aimeos\MShop::create( \TestHelper::context(), 'order/service/attribute' ); |
||
| 299 | |||
| 300 | $attrItem001 = $attManager->create(); |
||
| 301 | $attrItem001->setAttributeId( '1' ); |
||
| 302 | $attrItem001->setCode( 'code_001' ); |
||
| 303 | $attrItem001->setValue( 'value_001' ); |
||
| 304 | |||
| 305 | $attrItem002 = $attManager->create(); |
||
| 306 | $attrItem002->setAttributeId( '2' ); |
||
| 307 | $attrItem002->setCode( 'code_002' ); |
||
| 308 | $attrItem002->setType( 'test_002' ); |
||
| 309 | $attrItem002->setValue( 'value_002' ); |
||
| 310 | |||
| 311 | $this->object->setAttributeItems( array( $attrItem001, $attrItem002 ) ); |
||
| 312 | |||
| 313 | $result = $this->object->getAttribute( 'code_001' ); |
||
| 314 | $this->assertEquals( 'value_001', $result ); |
||
| 315 | |||
| 316 | $result = $this->object->getAttribute( 'code_002', ['test_002'] ); |
||
| 317 | $this->assertEquals( 'value_002', $result ); |
||
| 318 | |||
| 319 | $result = $this->object->getAttribute( 'code_002', 'test_002' ); |
||
| 320 | $this->assertEquals( 'value_002', $result ); |
||
| 321 | |||
| 322 | $result = $this->object->getAttribute( 'code_002' ); |
||
| 323 | $this->assertEquals( null, $result ); |
||
| 324 | |||
| 325 | $result = $this->object->getAttribute( 'code_003' ); |
||
| 326 | $this->assertEquals( null, $result ); |
||
| 327 | |||
| 328 | $this->object->setAttributeItems( [] ); |
||
| 329 | |||
| 330 | $result = $this->object->getAttribute( 'code_001' ); |
||
| 331 | $this->assertEquals( null, $result ); |
||
| 332 | } |
||
| 333 | |||
| 334 | |||
| 335 | public function testGetAttributeList() |
||
| 336 | { |
||
| 337 | $attManager = \Aimeos\MShop::create( \TestHelper::context(), 'order/service/attribute' ); |
||
| 338 | |||
| 339 | $attrItem001 = $attManager->create(); |
||
| 340 | $attrItem001->setAttributeId( '1' ); |
||
| 341 | $attrItem001->setCode( 'code_001' ); |
||
| 342 | $attrItem001->setType( 'test_001' ); |
||
| 343 | $attrItem001->setValue( 'value_001' ); |
||
| 344 | |||
| 345 | $attrItem002 = $attManager->create(); |
||
| 346 | $attrItem002->setAttributeId( '2' ); |
||
| 347 | $attrItem002->setCode( 'code_001' ); |
||
| 348 | $attrItem002->setType( 'test_001' ); |
||
| 349 | $attrItem002->setValue( 'value_002' ); |
||
| 350 | |||
| 351 | $this->object->setAttributeItems( array( $attrItem001, $attrItem002 ) ); |
||
| 352 | |||
| 353 | $result = $this->object->getAttribute( 'code_001', 'test_001' ); |
||
| 354 | $this->assertEquals( ['value_001', 'value_002'], $result ); |
||
| 355 | } |
||
| 356 | |||
| 357 | |||
| 358 | public function testGetAttributeItem() |
||
| 359 | { |
||
| 360 | $attManager = \Aimeos\MShop::create( \TestHelper::context(), 'order/service/attribute' ); |
||
| 361 | |||
| 362 | $attrItem001 = $attManager->create(); |
||
| 363 | $attrItem001->setAttributeId( '1' ); |
||
| 364 | $attrItem001->setCode( 'code_001' ); |
||
| 365 | $attrItem001->setValue( 'value_001' ); |
||
| 366 | |||
| 367 | $attrItem002 = $attManager->create(); |
||
| 368 | $attrItem002->setAttributeId( '2' ); |
||
| 369 | $attrItem002->setCode( 'code_002' ); |
||
| 370 | $attrItem002->setType( 'test_002' ); |
||
| 371 | $attrItem002->setValue( 'value_002' ); |
||
| 372 | |||
| 373 | $this->object->setAttributeItems( array( $attrItem001, $attrItem002 ) ); |
||
| 374 | |||
| 375 | $result = $this->object->getAttributeItem( 'code_001' ); |
||
| 376 | $this->assertEquals( 'value_001', $result->getValue() ); |
||
| 377 | |||
| 378 | $result = $this->object->getAttributeItem( 'code_002', 'test_002' ); |
||
| 379 | $this->assertEquals( 'value_002', $result->getValue() ); |
||
| 380 | |||
| 381 | $result = $this->object->getAttributeItem( 'code_002' ); |
||
| 382 | $this->assertEquals( null, $result ); |
||
| 383 | |||
| 384 | $result = $this->object->getAttributeItem( 'code_003' ); |
||
| 385 | $this->assertEquals( null, $result ); |
||
| 386 | |||
| 387 | $this->object->setAttributeItems( [] ); |
||
| 388 | |||
| 389 | $result = $this->object->getAttributeItem( 'code_001' ); |
||
| 390 | $this->assertEquals( null, $result ); |
||
| 391 | } |
||
| 392 | |||
| 393 | |||
| 394 | public function testGetAttributeItemList() |
||
| 395 | { |
||
| 396 | $attManager = \Aimeos\MShop::create( \TestHelper::context(), 'order/service/attribute' ); |
||
| 397 | |||
| 398 | $attrItem001 = $attManager->create(); |
||
| 399 | $attrItem001->setAttributeId( '1' ); |
||
| 400 | $attrItem001->setCode( 'code_001' ); |
||
| 401 | $attrItem001->setType( 'test_001' ); |
||
| 402 | $attrItem001->setValue( 'value_001' ); |
||
| 403 | |||
| 404 | $attrItem002 = $attManager->create(); |
||
| 405 | $attrItem002->setAttributeId( '2' ); |
||
| 406 | $attrItem002->setCode( 'code_001' ); |
||
| 407 | $attrItem002->setType( 'test_001' ); |
||
| 408 | $attrItem002->setValue( 'value_002' ); |
||
| 409 | |||
| 410 | $this->object->setAttributeItems( array( $attrItem001, $attrItem002 ) ); |
||
| 411 | |||
| 412 | $result = $this->object->getAttributeItem( 'code_001', 'test_001' ); |
||
| 413 | $this->assertEquals( 2, count( $result ) ); |
||
| 414 | } |
||
| 415 | |||
| 416 | |||
| 417 | public function testGetAttributeItems() |
||
| 418 | { |
||
| 419 | $this->assertEquals( $this->attributes, $this->object->getAttributeItems()->toArray() ); |
||
| 420 | } |
||
| 421 | |||
| 422 | |||
| 423 | public function testGetAttributeItemsByType() |
||
| 424 | { |
||
| 425 | $this->assertEquals( $this->attributes, $this->object->getAttributeItems( 'default' )->toArray() ); |
||
| 426 | } |
||
| 427 | |||
| 428 | |||
| 429 | public function testGetAttributeItemsInvalidType() |
||
| 430 | { |
||
| 431 | $this->assertEquals( [], $this->object->getAttributeItems( 'invalid' )->toArray() ); |
||
| 432 | } |
||
| 433 | |||
| 434 | |||
| 435 | public function testSetAttributeItem() |
||
| 462 | } |
||
| 463 | |||
| 464 | |||
| 465 | public function testSetAttributeItems() |
||
| 466 | { |
||
| 467 | $attManager = \Aimeos\MShop::create( \TestHelper::context(), 'order/service/attribute' ); |
||
| 468 | |||
| 469 | $list = array( |
||
| 470 | $attManager->create(), |
||
| 471 | $attManager->create(), |
||
| 472 | ); |
||
| 473 | |||
| 474 | $return = $this->object->setAttributeItems( $list ); |
||
| 475 | |||
| 476 | $this->assertInstanceOf( \Aimeos\MShop\Order\Item\Service\Iface::class, $return ); |
||
| 477 | $this->assertEquals( $list, $this->object->getAttributeItems()->toArray() ); |
||
| 478 | $this->assertTrue( $this->object->isModified() ); |
||
| 479 | } |
||
| 480 | |||
| 481 | |||
| 482 | public function testGetTransactions() |
||
| 483 | { |
||
| 484 | $this->assertEquals( $this->transactions, $this->object->getTransactions()->toArray() ); |
||
| 485 | } |
||
| 486 | |||
| 487 | |||
| 488 | public function testSetTransactions() |
||
| 489 | { |
||
| 490 | $txValues = array( |
||
| 491 | 'order.service.transaction.id' => 5, |
||
| 492 | 'order.service.transaction.siteid' => 100, |
||
| 493 | 'order.service.transaction.parentid' => 50, |
||
| 494 | 'order.service.transaction.type' => 'refund', |
||
| 495 | 'order.service.attribute.config' => ['tx' => '001'], |
||
| 496 | 'order.service.attribute.status' => 3, |
||
| 497 | 'order.service.attribute.mtime' => '2020-12-31 23:59:59', |
||
| 498 | 'order.service.attribute.ctime' => '2011-01-01 00:00:01', |
||
| 499 | 'order.service.attribute.editor' => 'unitTestUser' |
||
| 500 | ); |
||
| 501 | |||
| 502 | $list = [new \Aimeos\MShop\Order\Item\Service\Transaction\Standard( $this->price, $txValues )]; |
||
| 503 | $result = $this->object->setTransactions( $list ); |
||
| 504 | |||
| 505 | $this->assertInstanceOf( \Aimeos\MShop\Order\Item\Service\Iface::class, $result ); |
||
| 506 | $this->assertEquals( $list, $this->object->getTransactions()->toArray() ); |
||
| 507 | $this->assertTrue( $this->object->isModified() ); |
||
| 508 | } |
||
| 509 | |||
| 510 | |||
| 511 | public function testGetTimeModified() |
||
| 512 | { |
||
| 513 | $this->assertEquals( '2012-01-01 00:00:01', $this->object->getTimeModified() ); |
||
| 514 | } |
||
| 515 | |||
| 516 | |||
| 517 | public function testGetTimeCreated() |
||
| 518 | { |
||
| 519 | $this->assertEquals( '2011-01-01 00:00:01', $this->object->getTimeCreated() ); |
||
| 520 | } |
||
| 521 | |||
| 522 | |||
| 523 | public function testGetEditor() |
||
| 524 | { |
||
| 525 | $this->assertEquals( 'unitTestUser', $this->object->editor() ); |
||
| 526 | } |
||
| 527 | |||
| 528 | |||
| 529 | public function testFromArray() |
||
| 530 | { |
||
| 531 | $item = new \Aimeos\MShop\Order\Item\Service\Standard( new \Aimeos\MShop\Price\Item\Standard() ); |
||
| 532 | |||
| 533 | $list = $entries = array( |
||
| 534 | 'order.service.id' => 1, |
||
| 535 | 'order.service.parentid' => 2, |
||
| 536 | 'order.service.serviceid' => 3, |
||
| 537 | 'order.service.position' => 4, |
||
| 538 | 'order.service.currencyid' => 'EUR', |
||
| 539 | 'order.service.price' => '1.00', |
||
| 540 | 'order.service.costs' => '0.50', |
||
| 541 | 'order.service.rebate' => '0.50', |
||
| 542 | 'order.service.taxrates' => ['tax' => '20.00'], |
||
| 543 | 'order.service.taxvalue' => '0.2500', |
||
| 544 | 'order.service.taxflag' => 1, |
||
| 545 | 'order.service.code' => 'test', |
||
| 546 | 'order.service.name' => 'test item', |
||
| 547 | 'order.service.type' => 'delivery', |
||
| 548 | ); |
||
| 549 | |||
| 550 | $item = $item->fromArray( $entries, true ); |
||
| 551 | |||
| 552 | $this->assertEquals( [], $entries ); |
||
| 553 | $this->assertEquals( '', $item->getSiteId() ); |
||
| 554 | $this->assertEquals( $list['order.service.id'], $item->getId() ); |
||
| 555 | $this->assertEquals( $list['order.service.parentid'], $item->getParentId() ); |
||
| 556 | $this->assertEquals( $list['order.service.serviceid'], $item->getServiceId() ); |
||
| 557 | $this->assertEquals( $list['order.service.position'], $item->getPosition() ); |
||
| 558 | $this->assertEquals( $list['order.service.currencyid'], $item->getPrice()->getCurrencyId() ); |
||
| 559 | $this->assertEquals( $list['order.service.price'], $item->getPrice()->getValue() ); |
||
| 560 | $this->assertEquals( $list['order.service.costs'], $item->getPrice()->getCosts() ); |
||
| 561 | $this->assertEquals( $list['order.service.rebate'], $item->getPrice()->getRebate() ); |
||
| 562 | $this->assertEquals( $list['order.service.taxrates'], $item->getPrice()->getTaxRates() ); |
||
| 563 | $this->assertEquals( $list['order.service.taxvalue'], $item->getPrice()->getTaxValue() ); |
||
| 564 | $this->assertEquals( $list['order.service.taxflag'], $item->getPrice()->getTaxFlag() ); |
||
| 565 | $this->assertEquals( $list['order.service.code'], $item->getCode() ); |
||
| 566 | $this->assertEquals( $list['order.service.name'], $item->getName() ); |
||
| 567 | $this->assertEquals( $list['order.service.type'], $item->getType() ); |
||
| 568 | } |
||
| 569 | |||
| 570 | |||
| 571 | public function testToArray() |
||
| 597 | } |
||
| 598 | |||
| 599 | public function testIsModified() |
||
| 600 | { |
||
| 601 | $this->assertFalse( $this->object->isModified() ); |
||
| 602 | } |
||
| 603 | |||
| 604 | |||
| 605 | public function testGetResourceType() |
||
| 606 | { |
||
| 607 | $this->assertEquals( 'order/service', $this->object->getResourceType() ); |
||
| 608 | } |
||
| 609 | |||
| 610 | |||
| 611 | public function testCopyFrom() |
||
| 612 | { |
||
| 613 | $serviceCopy = new \Aimeos\MShop\Order\Item\Service\Standard( $this->price ); |
||
| 614 | |||
| 615 | $manager = \Aimeos\MShop::create( \TestHelper::context(), 'service' ); |
||
| 616 | |||
| 617 | $filter = $manager->filter()->add( ['service.provider' => 'Standard'] ); |
||
| 618 | $item = $manager->search( $filter )->first( new \RuntimeException( 'No service found' ) ); |
||
| 619 | |||
| 620 | $return = $serviceCopy->copyFrom( $item->set( 'customprop', 123 ) ); |
||
| 621 | |||
| 622 | $this->assertInstanceOf( \Aimeos\MShop\Order\Item\Service\Iface::class, $return ); |
||
| 623 | $this->assertEquals( 'unitdeliverycode', $serviceCopy->getCode() ); |
||
| 624 | $this->assertEquals( 'unitlabel', $serviceCopy->getName() ); |
||
| 625 | $this->assertEquals( 'delivery', $serviceCopy->getType() ); |
||
| 626 | $this->assertEquals( '', $serviceCopy->getMediaUrl() ); |
||
| 627 | $this->assertEquals( '123', $serviceCopy->get( 'customprop' ) ); |
||
| 628 | |||
| 629 | $this->assertTrue( $serviceCopy->isModified() ); |
||
| 630 | } |
||
| 631 | } |
||
| 632 |