|
11 | 11 | use Magento\Framework\Api\SearchCriteriaInterface;
|
12 | 12 | use Magento\TestFramework\Helper\Bootstrap;
|
13 | 13 |
|
| 14 | +/** |
| 15 | + * Checks Customer insert, update, search with repository |
| 16 | + */ |
14 | 17 | class CustomerRepositoryTest extends \PHPUnit_Framework_TestCase
|
15 | 18 | {
|
16 | 19 | /** @var AccountManagementInterface */
|
@@ -113,31 +116,43 @@ public function testCreateNewCustomer()
|
113 | 116 | }
|
114 | 117 |
|
115 | 118 | /**
|
| 119 | + * @dataProvider updateCustomerDataProvider |
116 | 120 | * @magentoAppArea frontend
|
117 | 121 | * @magentoDataFixture Magento/Customer/_files/customer.php
|
| 122 | + * @param int|null $defaultBilling |
| 123 | + * @param int|null $defaultShipping |
118 | 124 | */
|
119 |
| - public function testUpdateCustomer() |
| 125 | + public function testUpdateCustomer($defaultBilling, $defaultShipping) |
120 | 126 | {
|
121 |
| - $existingCustId = 1; |
| 127 | + $existingCustomerId = 1; |
122 | 128 | $email = 'savecustomer@example.com';
|
123 | 129 | $firstName = 'Firstsave';
|
124 |
| - $lastname = 'Lastsave'; |
125 |
| - $customerBefore = $this->customerRepository->getById($existingCustId); |
| 130 | + $lastName = 'Lastsave'; |
| 131 | + $customerBefore = $this->customerRepository->getById($existingCustomerId); |
126 | 132 | $customerData = array_merge($customerBefore->__toArray(), [
|
127 | 133 | 'id' => 1,
|
128 | 134 | 'email' => $email,
|
129 | 135 | 'firstname' => $firstName,
|
130 |
| - 'lastname' => $lastname, |
| 136 | + 'lastname' => $lastName, |
131 | 137 | 'created_in' => 'Admin',
|
132 |
| - 'password' => 'notsaved' |
| 138 | + 'password' => 'notsaved', |
| 139 | + 'default_billing' => $defaultBilling, |
| 140 | + 'default_shipping' => $defaultShipping |
133 | 141 | ]);
|
134 | 142 | $this->customerBuilder->populateWithArray($customerData);
|
135 |
| - $customerDetails = $this->customerBuilder->setId($existingCustId)->create(); |
| 143 | + $customerDetails = $this->customerBuilder->create(); |
136 | 144 | $this->customerRepository->save($customerDetails);
|
137 |
| - $customerAfter = $this->customerRepository->getById($existingCustId); |
| 145 | + $customerAfter = $this->customerRepository->getById($existingCustomerId); |
138 | 146 | $this->assertEquals($email, $customerAfter->getEmail());
|
139 | 147 | $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 | + ); |
141 | 156 | $this->assertEquals('Admin', $customerAfter->getCreatedIn());
|
142 | 157 | $passwordFromFixture = 'password';
|
143 | 158 | $this->accountManagement->authenticate($customerAfter->getEmail(), $passwordFromFixture);
|
@@ -278,45 +293,6 @@ public function testSearchCustomers($filters, $filterGroup, $expectedResult)
|
278 | 293 | }
|
279 | 294 | }
|
280 | 295 |
|
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 |
| - |
320 | 296 | /**
|
321 | 297 | * Test ordering
|
322 | 298 | *
|
@@ -396,4 +372,92 @@ public function testDeleteById()
|
396 | 372 | );
|
397 | 373 | $this->customerRepository->get($fixtureCustomerEmail);
|
398 | 374 | }
|
| 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 | + } |
399 | 463 | }
|
0 commit comments