Skip to content

Commit 8b4ee8d

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-54824' into develop-pr3
2 parents 2cf83c8 + 587739e commit 8b4ee8d

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed

app/code/Magento/Customer/Model/Customer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ public function updateData($customer)
335335
$customAttributes = $customer->getCustomAttributes();
336336
if ($customAttributes !== null) {
337337
foreach ($customAttributes as $attribute) {
338-
$this->setDataUsingMethod($attribute->getAttributeCode(), $attribute->getValue());
338+
$this->setData($attribute->getAttributeCode(), $attribute->getValue());
339339
}
340340
}
341341

app/code/Magento/Customer/Test/Unit/Model/CustomerTest.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ class CustomerTest extends \PHPUnit_Framework_TestCase
5858
/** @var \Magento\Customer\Model\ResourceModel\Customer|\PHPUnit_Framework_MockObject_MockObject */
5959
protected $resourceMock;
6060

61+
/**
62+
* @var \Magento\Framework\Reflection\DataObjectProcessor|\PHPUnit_Framework_MockObject_MockObject
63+
*/
64+
private $dataObjectProcessor;
65+
6166
protected function setUp()
6267
{
6368
$this->_website = $this->getMock(\Magento\Store\Model\Website::class, [], [], '', false);
@@ -102,6 +107,15 @@ protected function setUp()
102107
false,
103108
false
104109
);
110+
111+
$this->dataObjectProcessor = $this->getMock(
112+
\Magento\Framework\Reflection\DataObjectProcessor::class,
113+
['buildOutputDataArray'],
114+
[],
115+
'',
116+
false
117+
);
118+
105119
$this->resourceMock->expects($this->any())
106120
->method('getIdFieldName')
107121
->will($this->returnValue('id'));
@@ -119,6 +133,7 @@ protected function setUp()
119133
'attributeFactory' => $this->attributeFactoryMock,
120134
'registry' => $this->registryMock,
121135
'resource' => $this->resourceMock,
136+
'dataObjectProcessor' => $this->dataObjectProcessor
122137
]
123138
);
124139
}
@@ -271,4 +286,65 @@ public function dataProviderIsConfirmationRequired()
271286
[1, null, 'test2@example.com', true],
272287
];
273288
}
289+
290+
public function testUpdateData()
291+
{
292+
$customerDataAttributes = [
293+
'attribute' => 'attribute',
294+
'test1' => 'test1',
295+
'test33' => 'test33',
296+
];
297+
298+
$customer = $this->getMock(
299+
\Magento\Customer\Model\Data\Customer::class,
300+
[
301+
'getCustomAttributes',
302+
'getId',
303+
],
304+
[],
305+
'',
306+
false
307+
);
308+
309+
$attribute = $this->getMock(
310+
\Magento\Framework\Api\AttributeValue::class,
311+
[
312+
'getAttributeCode',
313+
'getValue',
314+
],
315+
[],
316+
'',
317+
false
318+
);
319+
320+
$this->dataObjectProcessor->expects($this->once())
321+
->method('buildOutputDataArray')
322+
->withConsecutive(
323+
[$customer, \Magento\Customer\Api\Data\CustomerInterface::class]
324+
)->willReturn($customerDataAttributes);
325+
326+
$attribute->expects($this->exactly(3))
327+
->method('getAttributeCode')
328+
->willReturn('test33');
329+
330+
$attribute->expects($this->exactly(2))
331+
->method('getValue')
332+
->willReturn('test33');
333+
334+
$customer->expects($this->once())
335+
->method('getCustomAttributes')
336+
->willReturn([$attribute->getAttributeCode() => $attribute]);
337+
338+
$this->_model->updateData($customer);
339+
340+
foreach ($customerDataAttributes as $key => $value) {
341+
$expectedResult[strtolower(trim(preg_replace('/([A-Z]|[0-9]+)/', "_$1", $key), '_'))] = $value;
342+
}
343+
344+
$expectedResult[$attribute->getAttributeCode()] = $attribute->getValue();
345+
$expectedResult['attribute_set_id'] =
346+
\Magento\Customer\Api\CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER;
347+
348+
$this->assertEquals($this->_model->getData(), $expectedResult);
349+
}
274350
}

0 commit comments

Comments
 (0)