9 class CopyTest extends \PHPUnit\Framework\TestCase
44 $this->eventManagerMock = $this->createMock(\
Magento\Framework\
Event\ManagerInterface::class);
45 $this->sourceMock = $this->createMock(\
Magento\Framework\DataObject::class);
46 $this->targetMock = $this->createMock(\
Magento\Framework\DataObject::class);
47 $this->extensionAttributesFactoryMock =
48 $this->createMock(\
Magento\Framework\Api\ExtensionAttributesFactory::class);
49 $this->copy = new \Magento\Framework\DataObject\Copy(
50 $this->eventManagerMock,
51 $this->fieldsetConfigMock,
52 $this->extensionAttributesFactoryMock
58 $this->fieldsetConfigMock->expects($this->never())->method(
'getFieldset');
61 $this->copy->copyFieldsetToTarget(
'fieldset',
'aspect', [],
'target')
67 $this->fieldsetConfigMock
68 ->expects($this->once())
69 ->method(
'getFieldset')
70 ->with(
'fieldset',
'global')
71 ->will($this->returnValue(
null));
72 $this->eventManagerMock->expects($this->never())->method(
'dispatch');
75 $this->copy->copyFieldsetToTarget(
'fieldset',
'aspect', $this->sourceMock, [$this->targetMock])
81 $fields[
'code'][
'node'][
'aspect'] = [];
82 $this->fieldsetConfigMock
83 ->expects($this->once())
84 ->method(
'getFieldset')
85 ->with(
'fieldset',
'global')
86 ->will($this->returnValue(
$fields));
88 $eventName = sprintf(
'core_copy_fieldset_%s_%s',
'fieldset',
'aspect');
90 'target' => new \Magento\Framework\DataObject([$this->targetMock]),
94 $this->eventManagerMock->expects($this->once())->method(
'dispatch')->with($eventName,
$data);
97 $this->copy->copyFieldsetToTarget(
'fieldset',
'aspect', $this->sourceMock, [$this->targetMock])
103 $fields[
'code'][
'aspect'] =
'value';
104 $this->fieldsetConfigMock
105 ->expects($this->once())
106 ->method(
'getFieldset')
107 ->with(
'fieldset',
'global')
108 ->will($this->returnValue(
$fields));
111 ->expects($this->once())
112 ->method(
'getDataUsingMethod')
114 ->will($this->returnValue(
'value'));
117 ->expects($this->once())
118 ->method(
'setDataUsingMethod')
120 ->will($this->returnSelf());
121 $eventName = sprintf(
'core_copy_fieldset_%s_%s',
'fieldset',
'aspect');
127 $this->eventManagerMock->expects($this->once())->method(
'dispatch')->with($eventName,
$data);
130 $this->copy->copyFieldsetToTarget(
'fieldset',
'aspect', $this->sourceMock, $this->targetMock)
136 $fields[
'code'][
'aspect'] =
'value';
138 $this->fieldsetConfigMock
139 ->expects($this->once())
140 ->method(
'getFieldset')
141 ->with(
'fieldset',
'global')
142 ->will($this->returnValue(
$fields));
145 ->expects($this->once())
146 ->method(
'getDataUsingMethod')
148 ->will($this->returnValue(
'value'));
151 ->expects($this->never())
152 ->method(
'setDataUsingMethod');
153 $eventName = sprintf(
'core_copy_fieldset_%s_%s',
'fieldset',
'aspect');
159 'target' => new \Magento\Framework\DataObject($newTarget),
163 $this->eventManagerMock->expects($this->once())->method(
'dispatch')->with($eventName,
$data);
166 $this->copy->copyFieldsetToTarget(
'fieldset',
'aspect', $this->sourceMock,
$target)
172 $fields[
'code'][
'aspect'] =
'*';
173 $this->fieldsetConfigMock
174 ->expects($this->once())
175 ->method(
'getFieldset')
176 ->with(
'fieldset',
'global')
177 ->will($this->returnValue(
$fields));
179 $sourceMock = $this->createPartialMock(\
Magento\Framework\Api\ExtensibleDataInterface::class, [
180 'getExtensionAttributes',
'getCode' 182 $targetMock = $this->createPartialMock(\
Magento\Framework\Api\ExtensibleDataInterface::class, [
183 'getExtensionAttributes',
185 'setExtensionAttributes' 189 ->expects($this->any())
190 ->method(
'getExtensionAttributes')
193 ->expects($this->once())
195 ->willReturn(
'code');
198 ->expects($this->any())
199 ->method(
'getExtensionAttributes')
202 ->expects($this->any())
203 ->method(
'setExtensionAttributes')
206 ->expects($this->once())
210 $this->eventManagerMock->expects($this->once())->method(
'dispatch');
217 $fields[
'code'][
'aspect'] =
'*';
219 $this->fieldsetConfigMock
220 ->expects($this->once())
221 ->method(
'getFieldset')
222 ->with(
'fieldset',
'global')
223 ->will($this->returnValue(
$fields));
225 $sourceMock = $this->createPartialMock(\
Magento\Framework\Api\AbstractSimpleObject::class, [
228 $targetMock = $this->createPartialMock(\
Magento\Framework\Api\AbstractSimpleObject::class, [
233 ->expects($this->once())
234 ->method(
'__toArray')
238 ->expects($this->once())
240 ->with(
'code',
'code');
242 $this->eventManagerMock->expects($this->once())->method(
'dispatch');
249 $this->fieldsetConfigMock->expects($this->never())->method(
'getFieldset');
250 $this->assertNull($this->copy->getDataFromFieldset(
'fieldset',
'aspect',
'source'));
255 $this->fieldsetConfigMock
256 ->expects($this->once())
257 ->method(
'getFieldset')
258 ->with(
'fieldset',
'global')
259 ->will($this->returnValue(
null));
261 ->expects($this->never())
262 ->method(
'getDataUsingMethod');
263 $this->assertNull($this->copy->getDataFromFieldset(
'fieldset',
'aspect', $this->sourceMock));
268 $fields[
'code'][
'aspect'] =
'value';
269 $this->fieldsetConfigMock
270 ->expects($this->once())
271 ->method(
'getFieldset')
272 ->with(
'fieldset',
'global')
273 ->will($this->returnValue(
$fields));
275 ->expects($this->once())
276 ->method(
'getDataUsingMethod')
278 ->will($this->returnValue(
'value'));
281 [
'value' =>
'value'],
282 $this->copy->getDataFromFieldset(
'fieldset',
'aspect', $this->sourceMock)
288 $fields[
'code'][
'aspect'] = [];
289 $this->fieldsetConfigMock
290 ->expects($this->once())
291 ->method(
'getFieldset')
292 ->with(
'fieldset',
'global')
293 ->will($this->returnValue(
$fields));
295 ->expects($this->never())
296 ->method(
'getDataUsingMethod');
300 $this->copy->getDataFromFieldset(
'fieldset',
'aspect', $this->sourceMock)
testCopyFieldsetToTargetWhenTargetNotArray()
$extensionAttributesFactoryMock
testGetDataFromFieldsetWhenFieldsetDoesNotExist()
testCopyFieldsetToTargetWhenFieldExists()
testGetCopyFieldsetToTargetWhenTargetIsArray()
testGetCopyFieldsetToTargetWhenTargetIsAbstractSimpleObject()
testGetDataFromFieldsetWhenFieldExists()
testCopyFieldsetToTargetWhenFieldsetInputInvalid()
testGetDataFromFieldsetWhenFieldDoesNotExists()
testCopyFieldsetToTargetWhenFieldIsNotExists()
testGetCopyFieldsetToTargetWhenTargetIsExtensibleDataInterface()
testGetDataFromFieldsetWhenSourceIsInvalid()