|
10 | 10 | use Magento\Framework\Api\SearchCriteriaInterface;
|
11 | 11 | use Magento\TestFramework\Helper\Bootstrap;
|
12 | 12 |
|
| 13 | +/** |
| 14 | + * Checks Customer insert, update, search with repository |
| 15 | + */ |
13 | 16 | class CustomerRepositoryTest extends \PHPUnit_Framework_TestCase
|
14 | 17 | {
|
15 | 18 | /** @var AccountManagementInterface */
|
@@ -112,31 +115,39 @@ public function testCreateNewCustomer()
|
112 | 115 | }
|
113 | 116 |
|
114 | 117 | /**
|
| 118 | + * @dataProvider updateCustomerDataProvider |
115 | 119 | * @magentoAppArea frontend
|
116 | 120 | * @magentoDataFixture Magento/Customer/_files/customer.php
|
| 121 | + * @param int|null $defaultBilling |
| 122 | + * @param int|null $defaultShipping |
117 | 123 | */
|
118 |
| - public function testUpdateCustomer() |
| 124 | + public function testUpdateCustomer($defaultBilling, $defaultShipping) |
119 | 125 | {
|
120 |
| - $existingCustId = 1; |
| 126 | + $existingCustomerId = 1; |
121 | 127 | $email = 'savecustomer@example.com';
|
122 | 128 | $firstName = 'Firstsave';
|
123 |
| - $lastname = 'Lastsave'; |
124 |
| - $customerBefore = $this->customerRepository->getById($existingCustId); |
| 129 | + $lastName = 'Lastsave'; |
| 130 | + $customerBefore = $this->customerRepository->getById($existingCustomerId); |
125 | 131 | $customerData = array_merge($customerBefore->__toArray(), [
|
126 | 132 | 'id' => 1,
|
127 | 133 | 'email' => $email,
|
128 | 134 | 'firstname' => $firstName,
|
129 |
| - 'lastname' => $lastname, |
| 135 | + 'lastname' => $lastName, |
130 | 136 | 'created_in' => 'Admin',
|
131 |
| - 'password' => 'notsaved' |
| 137 | + 'password' => 'notsaved', |
| 138 | + 'default_billing' => $defaultBilling, |
| 139 | + 'default_shipping' => $defaultShipping |
132 | 140 | ]);
|
133 | 141 | $this->customerBuilder->populateWithArray($customerData);
|
134 |
| - $customerDetails = $this->customerBuilder->setId($existingCustId)->create(); |
| 142 | + $customerDetails = $this->customerBuilder->create(); |
135 | 143 | $this->customerRepository->save($customerDetails);
|
136 |
| - $customerAfter = $this->customerRepository->getById($existingCustId); |
| 144 | + $customerAfter = $this->customerRepository->getById($existingCustomerId); |
137 | 145 | $this->assertEquals($email, $customerAfter->getEmail());
|
138 | 146 | $this->assertEquals($firstName, $customerAfter->getFirstname());
|
139 |
| - $this->assertEquals($lastname, $customerAfter->getLastname()); |
| 147 | + $this->assertEquals($lastName, $customerAfter->getLastname()); |
| 148 | + $this->assertEquals($defaultBilling, $customerAfter->getDefaultBilling()); |
| 149 | + $this->assertEquals($defaultShipping, $customerAfter->getDefaultShipping()); |
| 150 | + $this->expectedDefaultShippingsInCustomerModelAttributes($existingCustomerId, $defaultBilling, $defaultShipping); |
140 | 151 | $this->assertEquals('Admin', $customerAfter->getCreatedIn());
|
141 | 152 | $passwordFromFixture = 'password';
|
142 | 153 | $this->accountManagement->authenticate($customerAfter->getEmail(), $passwordFromFixture);
|
@@ -269,45 +280,6 @@ public function testSearchCustomers($filters, $filterGroup, $expectedResult)
|
269 | 280 | }
|
270 | 281 | }
|
271 | 282 |
|
272 |
| - public function searchCustomersDataProvider() |
273 |
| - { |
274 |
| - $builder = Bootstrap::getObjectManager()->create('\Magento\Framework\Api\FilterBuilder'); |
275 |
| - return [ |
276 |
| - 'Customer with specific email' => [ |
277 |
| - [$builder->setField('email')->setValue('customer@search.example.com')->create()], |
278 |
| - null, |
279 |
| - [1 => ['email' => 'customer@search.example.com', 'firstname' => 'Firstname']], |
280 |
| - ], |
281 |
| - 'Customer with specific first name' => [ |
282 |
| - [$builder->setField('firstname')->setValue('Firstname2')->create()], |
283 |
| - null, |
284 |
| - [2 => ['email' => 'customer2@search.example.com', 'firstname' => 'Firstname2']], |
285 |
| - ], |
286 |
| - 'Customers with either email' => [ |
287 |
| - [], |
288 |
| - [ |
289 |
| - $builder->setField('firstname')->setValue('Firstname')->create(), |
290 |
| - $builder->setField('firstname')->setValue('Firstname2')->create() |
291 |
| - ], |
292 |
| - [ |
293 |
| - 1 => ['email' => 'customer@search.example.com', 'firstname' => 'Firstname'], |
294 |
| - 2 => ['email' => 'customer2@search.example.com', 'firstname' => 'Firstname2'] |
295 |
| - ], |
296 |
| - ], |
297 |
| - 'Customers created since' => [ |
298 |
| - [ |
299 |
| - $builder->setField('created_at')->setValue('2011-02-28 15:52:26') |
300 |
| - ->setConditionType('gt')->create(), |
301 |
| - ], |
302 |
| - [], |
303 |
| - [ |
304 |
| - 1 => ['email' => 'customer@search.example.com', 'firstname' => 'Firstname'], |
305 |
| - 3 => ['email' => 'customer3@search.example.com', 'firstname' => 'Firstname3'] |
306 |
| - ], |
307 |
| - ] |
308 |
| - ]; |
309 |
| - } |
310 |
| - |
311 | 283 | /**
|
312 | 284 | * Test ordering
|
313 | 285 | *
|
@@ -387,4 +359,92 @@ public function testDeleteById()
|
387 | 359 | );
|
388 | 360 | $this->customerRepository->get($fixtureCustomerEmail);
|
389 | 361 | }
|
| 362 | + |
| 363 | + /** |
| 364 | + * DataProvider update customer |
| 365 | + * |
| 366 | + * @return array |
| 367 | + */ |
| 368 | + public function updateCustomerDataProvider() |
| 369 | + { |
| 370 | + return [ |
| 371 | + 'Customer remove default shipping and billing' => [ |
| 372 | + null, |
| 373 | + null |
| 374 | + ], |
| 375 | + 'Customer update default shipping and billing' => [ |
| 376 | + 1, |
| 377 | + 1 |
| 378 | + ], |
| 379 | + ]; |
| 380 | + } |
| 381 | + |
| 382 | + public function searchCustomersDataProvider() |
| 383 | + { |
| 384 | + $builder = Bootstrap::getObjectManager()->create('\Magento\Framework\Api\FilterBuilder'); |
| 385 | + return [ |
| 386 | + 'Customer with specific email' => [ |
| 387 | + [$builder->setField('email')->setValue('customer@search.example.com')->create()], |
| 388 | + null, |
| 389 | + [1 => ['email' => 'customer@search.example.com', 'firstname' => 'Firstname']], |
| 390 | + ], |
| 391 | + 'Customer with specific first name' => [ |
| 392 | + [$builder->setField('firstname')->setValue('Firstname2')->create()], |
| 393 | + null, |
| 394 | + [2 => ['email' => 'customer2@search.example.com', 'firstname' => 'Firstname2']], |
| 395 | + ], |
| 396 | + 'Customers with either email' => [ |
| 397 | + [], |
| 398 | + [ |
| 399 | + $builder->setField('firstname')->setValue('Firstname')->create(), |
| 400 | + $builder->setField('firstname')->setValue('Firstname2')->create() |
| 401 | + ], |
| 402 | + [ |
| 403 | + 1 => ['email' => 'customer@search.example.com', 'firstname' => 'Firstname'], |
| 404 | + 2 => ['email' => 'customer2@search.example.com', 'firstname' => 'Firstname2'] |
| 405 | + ], |
| 406 | + ], |
| 407 | + 'Customers created since' => [ |
| 408 | + [ |
| 409 | + $builder->setField('created_at')->setValue('2011-02-28 15:52:26') |
| 410 | + ->setConditionType('gt')->create(), |
| 411 | + ], |
| 412 | + [], |
| 413 | + [ |
| 414 | + 1 => ['email' => 'customer@search.example.com', 'firstname' => 'Firstname'], |
| 415 | + 3 => ['email' => 'customer3@search.example.com', 'firstname' => 'Firstname3'] |
| 416 | + ], |
| 417 | + ] |
| 418 | + ]; |
| 419 | + } |
| 420 | + |
| 421 | + /** |
| 422 | + * Check defaults billing and shipping in customer model |
| 423 | + * |
| 424 | + * @param $customerId |
| 425 | + * @param $defaultBilling |
| 426 | + * @param $defaultShipping |
| 427 | + */ |
| 428 | + protected function expectedDefaultShippingsInCustomerModelAttributes( |
| 429 | + $customerId, |
| 430 | + $defaultBilling, |
| 431 | + $defaultShipping |
| 432 | + ) { |
| 433 | + /** |
| 434 | + * @var \Magento\Customer\Model\Customer $customer |
| 435 | + */ |
| 436 | + $customer = $this->objectManager->create('Magento\Customer\Model\Customer'); |
| 437 | + /** @var \Magento\Customer\Model\Customer $customer */ |
| 438 | + $customer->load($customerId); |
| 439 | + $this->assertEquals( |
| 440 | + $defaultBilling, |
| 441 | + $customer->getDefaultBilling(), |
| 442 | + 'default_billing customer attribute did not updated' |
| 443 | + ); |
| 444 | + $this->assertEquals( |
| 445 | + $defaultShipping, |
| 446 | + $customer->getDefaultShipping(), |
| 447 | + 'default_shipping customer attribute did not updated' |
| 448 | + ); |
| 449 | + } |
390 | 450 | }
|
0 commit comments