Skip to content

Commit b981286

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-42728' into BUGS
2 parents c0b1e42 + beed1e1 commit b981286

File tree

2 files changed

+89
-5
lines changed

2 files changed

+89
-5
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,15 @@ public function getData()
122122
/** @var Customer $customer */
123123
foreach ($items as $customer) {
124124
$result['customer'] = $customer->getData();
125+
unset($result['address']);
125126

126-
$addresses = [];
127127
/** @var Address $address */
128128
foreach ($customer->getAddresses() as $address) {
129129
$addressId = $address->getId();
130130
$address->load($addressId);
131-
$addresses[$addressId] = $address->getData();
132-
$this->prepareAddressData($addressId, $addresses, $result['customer']);
131+
$result['address'][$addressId] = $address->getData();
132+
$this->prepareAddressData($addressId, $result['address'], $result['customer']);
133133
}
134-
$result['address'] = $addresses;
135-
136134
$this->loadedData[$customer->getId()] = $result;
137135
}
138136

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

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,4 +246,90 @@ function ($origName) {
246246

247247
return [$attributeMock];
248248
}
249+
250+
public function testGetData()
251+
{
252+
$customer = $this->getMockBuilder('Magento\Customer\Model\Customer')
253+
->disableOriginalConstructor()
254+
->getMock();
255+
$address = $this->getMockBuilder('Magento\Customer\Model\Address')
256+
->disableOriginalConstructor()
257+
->getMock();
258+
$collectionMock = $this->getMockBuilder('Magento\Customer\Model\Resource\Customer\Collection')
259+
->disableOriginalConstructor()
260+
->getMock();
261+
262+
$collectionMock->expects($this->once())
263+
->method('addAttributeToSelect')
264+
->with('*');
265+
266+
$this->customerCollectionFactoryMock->expects($this->once())
267+
->method('create')
268+
->willReturn($collectionMock);
269+
270+
$collectionMock->expects($this->once())
271+
->method('getItems')
272+
->willReturn([$customer]);
273+
$customer->expects($this->once())
274+
->method('getData')
275+
->willReturn([
276+
'email' => 'test@test.ua',
277+
'default_billing' => 2,
278+
'default_shipping' => 2,
279+
]);
280+
$customer->expects($this->once())
281+
->method('getAddresses')
282+
->willReturn([$address]);
283+
$address->expects($this->atLeastOnce())
284+
->method('getId')
285+
->willReturn(2);
286+
$address->expects($this->once())
287+
->method('load')
288+
->with(2)
289+
->willReturnSelf();
290+
$address->expects($this->once())
291+
->method('getData')
292+
->willReturn([
293+
'firstname' => 'firstname',
294+
'lastname' => 'lastname',
295+
'street' => "street\nstreet",
296+
]);
297+
298+
$helper = new ObjectManager($this);
299+
$dataProvider = $helper->getObject(
300+
'\Magento\Customer\Model\Customer\DataProvider',
301+
[
302+
'name' => 'test-name',
303+
'primaryFieldName' => 'primary-field-name',
304+
'requestFieldName' => 'request-field-name',
305+
'eavValidationRules' => $this->eavValidationRulesMock,
306+
'customerCollectionFactory' => $this->customerCollectionFactoryMock,
307+
'eavConfig' => $this->getEavConfigMock()
308+
]
309+
);
310+
$this->assertEquals(
311+
[
312+
'' => [
313+
'customer' => [
314+
'email' => 'test@test.ua',
315+
'default_billing' => 2,
316+
'default_shipping' => 2,
317+
],
318+
'address' => [
319+
2 => [
320+
'firstname' => 'firstname',
321+
'lastname' => 'lastname',
322+
'street' => [
323+
'street',
324+
'street',
325+
],
326+
'default_billing' => 2,
327+
'default_shipping' => 2,
328+
]
329+
]
330+
]
331+
],
332+
$dataProvider->getData()
333+
);
334+
}
249335
}

0 commit comments

Comments
 (0)