Skip to content

Commit 661874a

Browse files
author
al.kravchuk
committed
#23386: Copy Service does not works properly for Entities which extends Data Object and implements ExtensibleDataInterface.
Add unit tests coverage.
1 parent d70edfc commit 661874a

File tree

1 file changed

+84
-0
lines changed
  • lib/internal/Magento/Framework/DataObject/Test/Unit

1 file changed

+84
-0
lines changed

lib/internal/Magento/Framework/DataObject/Test/Unit/CopyTest.php

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace Magento\Framework\DataObject\Test\Unit;
88

9+
use Magento\Quote\Model\Quote\Address;
10+
911
class CopyTest extends \PHPUnit\Framework\TestCase
1012
{
1113
/**
@@ -300,4 +302,86 @@ public function testGetDataFromFieldsetWhenFieldDoesNotExists()
300302
$this->copy->getDataFromFieldset('fieldset', 'aspect', $this->sourceMock)
301303
);
302304
}
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+
}
303387
}

0 commit comments

Comments
 (0)