|
6 | 6 |
|
7 | 7 | namespace Magento\Framework\DataObject\Test\Unit;
|
8 | 8 |
|
| 9 | +use Magento\Quote\Model\Quote\Address; |
| 10 | + |
9 | 11 | class CopyTest extends \PHPUnit\Framework\TestCase
|
10 | 12 | {
|
11 | 13 | /**
|
@@ -300,4 +302,86 @@ public function testGetDataFromFieldsetWhenFieldDoesNotExists()
|
300 | 302 | $this->copy->getDataFromFieldset('fieldset', 'aspect', $this->sourceMock)
|
301 | 303 | );
|
302 | 304 | }
|
| 305 | + |
| 306 | + public function testGetExtensionAttributeForDataObjectChild() |
| 307 | + { |
| 308 | + $fields['code']['aspect'] = '*'; |
| 309 | + $this->fieldsetConfigMock |
| 310 | + ->expects($this->once()) |
| 311 | + ->method('getFieldset') |
| 312 | + ->with('fieldset', 'global') |
| 313 | + ->will($this->returnValue($fields)); |
| 314 | + |
| 315 | + $sourceMock = $this->createPartialMock(Address::class, [ |
| 316 | + 'getExtensionAttributes', 'getCode' |
| 317 | + ]); |
| 318 | + $targetMock = $this->createPartialMock( |
| 319 | + Address::class, [ |
| 320 | + 'getExtensionAttributes', |
| 321 | + 'setCode', |
| 322 | + 'setExtensionAttributes' |
| 323 | + ]); |
| 324 | + |
| 325 | + $sourceMock |
| 326 | + ->expects($this->any()) |
| 327 | + ->method('getExtensionAttributes') |
| 328 | + ->willReturnSelf(); |
| 329 | + $sourceMock |
| 330 | + ->expects($this->once()) |
| 331 | + ->method('getCode') |
| 332 | + ->willReturn('code'); |
| 333 | + |
| 334 | + $targetMock |
| 335 | + ->expects($this->any()) |
| 336 | + ->method('getExtensionAttributes') |
| 337 | + ->willReturnSelf(); |
| 338 | + $targetMock |
| 339 | + ->expects($this->any()) |
| 340 | + ->method('setExtensionAttributes') |
| 341 | + ->willReturnSelf(); |
| 342 | + $targetMock |
| 343 | + ->expects($this->once()) |
| 344 | + ->method('setCode') |
| 345 | + ->with('code'); |
| 346 | + |
| 347 | + $this->eventManagerMock->expects($this->once())->method('dispatch'); |
| 348 | + $result = $this->copy->copyFieldsetToTarget('fieldset', 'aspect', $sourceMock, $targetMock); |
| 349 | + $this->assertEquals($result, $targetMock); |
| 350 | + } |
| 351 | + |
| 352 | + public function testGetDataObjectFieldFromExtensbielEntity() |
| 353 | + { |
| 354 | + $fields['code']['aspect'] = '*'; |
| 355 | + $this->fieldsetConfigMock |
| 356 | + ->expects($this->once()) |
| 357 | + ->method('getFieldset') |
| 358 | + ->with('fieldset', 'global') |
| 359 | + ->will($this->returnValue($fields)); |
| 360 | + |
| 361 | + $sourceMock = $this->createPartialMock(Address::class, [ |
| 362 | + 'getExtensionAttributes' |
| 363 | + ]); |
| 364 | + $targetMock = $this->createPartialMock( |
| 365 | + Address::class, [ |
| 366 | + 'getExtensionAttributes' |
| 367 | + ]); |
| 368 | + |
| 369 | + $sourceMock |
| 370 | + ->expects($this->any()) |
| 371 | + ->method('getExtensionAttributes') |
| 372 | + ->willReturn(null); |
| 373 | + $value = 'code'; |
| 374 | + $sourceMock->setData('code', $value); |
| 375 | + |
| 376 | + $targetMock |
| 377 | + ->expects($this->any()) |
| 378 | + ->method('getExtensionAttributes') |
| 379 | + ->willReturn(null); |
| 380 | + |
| 381 | + |
| 382 | + $this->eventManagerMock->expects($this->once())->method('dispatch'); |
| 383 | + $result = $this->copy->copyFieldsetToTarget('fieldset', 'aspect', $sourceMock, $targetMock); |
| 384 | + $this->assertEquals($result, $targetMock); |
| 385 | + $this->assertEquals($value, $result->getCode()); |
| 386 | + } |
303 | 387 | }
|
0 commit comments