Skip to content

Commit 90746b2

Browse files
author
Olexandr Lysenko
committed
Merge remote-tracking branch 'origin/MAGETWO-31896' into MAGETWO-31896-fixed
Conflicts: dev/tests/integration/testsuite/Magento/Customer/Model/Resource/CustomerRepositoryTest.php
2 parents 1bba5fe + f02949a commit 90746b2

File tree

2 files changed

+114
-54
lines changed

2 files changed

+114
-54
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,8 @@ protected function _saveAddresses(\Magento\Customer\Model\Customer $customer)
220220
}
221221
}
222222
}
223-
if ($customer->dataHasChangedFor('default_billing')) {
224-
$this->saveAttribute($customer, 'default_billing');
225-
}
226-
if ($customer->dataHasChangedFor('default_shipping')) {
227-
$this->saveAttribute($customer, 'default_shipping');
228-
}
223+
$this->saveAttribute($customer, 'default_billing');
224+
$this->saveAttribute($customer, 'default_shipping');
229225

230226
return $this;
231227
}

dev/tests/integration/testsuite/Magento/Customer/Model/Resource/CustomerRepositoryTest.php

Lines changed: 112 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
use Magento\Framework\Api\SearchCriteriaInterface;
1212
use Magento\TestFramework\Helper\Bootstrap;
1313

14+
/**
15+
* Checks Customer insert, update, search with repository
16+
*/
1417
class CustomerRepositoryTest extends \PHPUnit_Framework_TestCase
1518
{
1619
/** @var AccountManagementInterface */
@@ -113,31 +116,43 @@ public function testCreateNewCustomer()
113116
}
114117

115118
/**
119+
* @dataProvider updateCustomerDataProvider
116120
* @magentoAppArea frontend
117121
* @magentoDataFixture Magento/Customer/_files/customer.php
122+
* @param int|null $defaultBilling
123+
* @param int|null $defaultShipping
118124
*/
119-
public function testUpdateCustomer()
125+
public function testUpdateCustomer($defaultBilling, $defaultShipping)
120126
{
121-
$existingCustId = 1;
127+
$existingCustomerId = 1;
122128
$email = 'savecustomer@example.com';
123129
$firstName = 'Firstsave';
124-
$lastname = 'Lastsave';
125-
$customerBefore = $this->customerRepository->getById($existingCustId);
130+
$lastName = 'Lastsave';
131+
$customerBefore = $this->customerRepository->getById($existingCustomerId);
126132
$customerData = array_merge($customerBefore->__toArray(), [
127133
'id' => 1,
128134
'email' => $email,
129135
'firstname' => $firstName,
130-
'lastname' => $lastname,
136+
'lastname' => $lastName,
131137
'created_in' => 'Admin',
132-
'password' => 'notsaved'
138+
'password' => 'notsaved',
139+
'default_billing' => $defaultBilling,
140+
'default_shipping' => $defaultShipping
133141
]);
134142
$this->customerBuilder->populateWithArray($customerData);
135-
$customerDetails = $this->customerBuilder->setId($existingCustId)->create();
143+
$customerDetails = $this->customerBuilder->create();
136144
$this->customerRepository->save($customerDetails);
137-
$customerAfter = $this->customerRepository->getById($existingCustId);
145+
$customerAfter = $this->customerRepository->getById($existingCustomerId);
138146
$this->assertEquals($email, $customerAfter->getEmail());
139147
$this->assertEquals($firstName, $customerAfter->getFirstname());
140-
$this->assertEquals($lastname, $customerAfter->getLastname());
148+
$this->assertEquals($lastName, $customerAfter->getLastname());
149+
$this->assertEquals($defaultBilling, $customerAfter->getDefaultBilling());
150+
$this->assertEquals($defaultShipping, $customerAfter->getDefaultShipping());
151+
$this->expectedDefaultShippingsInCustomerModelAttributes(
152+
$existingCustomerId,
153+
$defaultBilling,
154+
$defaultShipping
155+
);
141156
$this->assertEquals('Admin', $customerAfter->getCreatedIn());
142157
$passwordFromFixture = 'password';
143158
$this->accountManagement->authenticate($customerAfter->getEmail(), $passwordFromFixture);
@@ -278,45 +293,6 @@ public function testSearchCustomers($filters, $filterGroup, $expectedResult)
278293
}
279294
}
280295

281-
public function searchCustomersDataProvider()
282-
{
283-
$builder = Bootstrap::getObjectManager()->create('Magento\Framework\Api\FilterBuilder');
284-
return [
285-
'Customer with specific email' => [
286-
[$builder->setField('email')->setValue('customer@search.example.com')->create()],
287-
null,
288-
[1 => ['email' => 'customer@search.example.com', 'firstname' => 'Firstname']],
289-
],
290-
'Customer with specific first name' => [
291-
[$builder->setField('firstname')->setValue('Firstname2')->create()],
292-
null,
293-
[2 => ['email' => 'customer2@search.example.com', 'firstname' => 'Firstname2']],
294-
],
295-
'Customers with either email' => [
296-
[],
297-
[
298-
$builder->setField('firstname')->setValue('Firstname')->create(),
299-
$builder->setField('firstname')->setValue('Firstname2')->create()
300-
],
301-
[
302-
1 => ['email' => 'customer@search.example.com', 'firstname' => 'Firstname'],
303-
2 => ['email' => 'customer2@search.example.com', 'firstname' => 'Firstname2']
304-
],
305-
],
306-
'Customers created since' => [
307-
[
308-
$builder->setField('created_at')->setValue('2011-02-28 15:52:26')
309-
->setConditionType('gt')->create(),
310-
],
311-
[],
312-
[
313-
1 => ['email' => 'customer@search.example.com', 'firstname' => 'Firstname'],
314-
3 => ['email' => 'customer3@search.example.com', 'firstname' => 'Firstname3']
315-
],
316-
]
317-
];
318-
}
319-
320296
/**
321297
* Test ordering
322298
*
@@ -396,4 +372,92 @@ public function testDeleteById()
396372
);
397373
$this->customerRepository->get($fixtureCustomerEmail);
398374
}
375+
376+
/**
377+
* DataProvider update customer
378+
*
379+
* @return array
380+
*/
381+
public function updateCustomerDataProvider()
382+
{
383+
return [
384+
'Customer remove default shipping and billing' => [
385+
null,
386+
null
387+
],
388+
'Customer update default shipping and billing' => [
389+
1,
390+
1
391+
],
392+
];
393+
}
394+
395+
public function searchCustomersDataProvider()
396+
{
397+
$builder = Bootstrap::getObjectManager()->create('\Magento\Framework\Api\FilterBuilder');
398+
return [
399+
'Customer with specific email' => [
400+
[$builder->setField('email')->setValue('customer@search.example.com')->create()],
401+
null,
402+
[1 => ['email' => 'customer@search.example.com', 'firstname' => 'Firstname']],
403+
],
404+
'Customer with specific first name' => [
405+
[$builder->setField('firstname')->setValue('Firstname2')->create()],
406+
null,
407+
[2 => ['email' => 'customer2@search.example.com', 'firstname' => 'Firstname2']],
408+
],
409+
'Customers with either email' => [
410+
[],
411+
[
412+
$builder->setField('firstname')->setValue('Firstname')->create(),
413+
$builder->setField('firstname')->setValue('Firstname2')->create()
414+
],
415+
[
416+
1 => ['email' => 'customer@search.example.com', 'firstname' => 'Firstname'],
417+
2 => ['email' => 'customer2@search.example.com', 'firstname' => 'Firstname2']
418+
],
419+
],
420+
'Customers created since' => [
421+
[
422+
$builder->setField('created_at')->setValue('2011-02-28 15:52:26')
423+
->setConditionType('gt')->create(),
424+
],
425+
[],
426+
[
427+
1 => ['email' => 'customer@search.example.com', 'firstname' => 'Firstname'],
428+
3 => ['email' => 'customer3@search.example.com', 'firstname' => 'Firstname3']
429+
],
430+
]
431+
];
432+
}
433+
434+
/**
435+
* Check defaults billing and shipping in customer model
436+
*
437+
* @param $customerId
438+
* @param $defaultBilling
439+
* @param $defaultShipping
440+
*/
441+
protected function expectedDefaultShippingsInCustomerModelAttributes(
442+
$customerId,
443+
$defaultBilling,
444+
$defaultShipping
445+
) {
446+
/**
447+
* @var \Magento\Customer\Model\Customer $customer
448+
*/
449+
$customer = $this->objectManager->create('Magento\Customer\Model\Customer');
450+
/** @var \Magento\Customer\Model\Customer $customer */
451+
$customer->load($customerId);
452+
$this->assertEquals(
453+
$defaultBilling,
454+
$customer->getDefaultBilling(),
455+
'default_billing customer attribute did not updated'
456+
);
457+
$this->assertEquals(
458+
$defaultShipping,
459+
$customer->getDefaultShipping(),
460+
'default_shipping customer attribute did not updated'
461+
);
462+
}
399463
}

0 commit comments

Comments
 (0)