|
8 | 8 |
|
9 | 9 | use Magento\Customer\Api\AccountManagementInterface;
|
10 | 10 | use Magento\Customer\Api\CustomerRepositoryInterface;
|
11 |
| -use Magento\Customer\Api\Data\CustomerInterfaceFactory; |
| 11 | +use Magento\Customer\Api\Data\AddressInterface; |
12 | 12 | use Magento\Customer\Api\Data\AddressInterfaceFactory;
|
13 |
| -use Magento\Framework\Api\ExtensibleDataObjectConverter; |
14 |
| -use Magento\Framework\Api\DataObjectHelper; |
15 |
| -use Magento\Framework\Encryption\EncryptorInterface; |
16 | 13 | use Magento\Customer\Api\Data\CustomerInterface;
|
| 14 | +use Magento\Customer\Api\Data\CustomerInterfaceFactory; |
| 15 | +use Magento\Customer\Model\Customer; |
17 | 16 | use Magento\Customer\Model\CustomerRegistry;
|
| 17 | +use Magento\Framework\Api\DataObjectHelper; |
| 18 | +use Magento\Framework\Api\ExtensibleDataObjectConverter; |
| 19 | +use Magento\Framework\Api\FilterBuilder; |
| 20 | +use Magento\Framework\Api\SearchCriteriaBuilder; |
18 | 21 | use Magento\Framework\Api\SortOrder;
|
| 22 | +use Magento\Framework\Api\SortOrderBuilder; |
19 | 23 | use Magento\Framework\Config\CacheInterface;
|
| 24 | +use Magento\Framework\Encryption\EncryptorInterface; |
| 25 | +use Magento\Framework\Exception\NoSuchEntityException; |
20 | 26 | use Magento\Framework\ObjectManagerInterface;
|
21 | 27 | use Magento\Framework\Validator\Exception as ValidatorException;
|
22 | 28 | use Magento\Sales\Api\Data\OrderInterface;
|
23 | 29 | use Magento\Sales\Api\OrderRepositoryInterface;
|
24 | 30 | use Magento\TestFramework\Helper\Bootstrap;
|
25 |
| -use Magento\Customer\Api\Data\AddressInterface; |
26 |
| -use Magento\Framework\Api\SearchCriteriaBuilder; |
27 |
| -use Magento\Framework\Api\FilterBuilder; |
28 |
| -use Magento\Framework\Api\SortOrderBuilder; |
29 |
| -use Magento\Framework\Exception\NoSuchEntityException; |
30 |
| -use Magento\Customer\Model\Customer; |
31 | 31 |
|
32 | 32 | /**
|
33 | 33 | * Checks Customer insert, update, search with repository
|
@@ -244,6 +244,53 @@ public function testUpdateCustomer($defaultBilling, $defaultShipping)
|
244 | 244 | $this->assertNotContains('password_hash', array_keys($inAfterOnly));
|
245 | 245 | }
|
246 | 246 |
|
| 247 | + /** |
| 248 | + * Test update customer custom attributes |
| 249 | + * |
| 250 | + * @magentoDbIsolation enabled |
| 251 | + * @magentoDataFixture Magento/Customer/_files/attribute_user_defined_custom_attribute.php |
| 252 | + * @return void |
| 253 | + */ |
| 254 | + public function testUpdateCustomerAttributesAutoIncrement() |
| 255 | + { |
| 256 | + $email = 'email@example.com'; |
| 257 | + $storeId = 1; |
| 258 | + $firstname = 'Tester'; |
| 259 | + $lastname = 'McTest'; |
| 260 | + $groupId = 1; |
| 261 | + $newAttributeValue = 'test1'; |
| 262 | + $updateAttributeValue = 'test2'; |
| 263 | + |
| 264 | + $newCustomerEntity = $this->customerFactory->create() |
| 265 | + ->setStoreId($storeId) |
| 266 | + ->setEmail($email) |
| 267 | + ->setFirstname($firstname) |
| 268 | + ->setLastname($lastname) |
| 269 | + ->setGroupId($groupId); |
| 270 | + $newCustomerEntity->setCustomAttribute('custom_attribute1', $newAttributeValue); |
| 271 | + $savedCustomer = $this->customerRepository->save($newCustomerEntity); |
| 272 | + |
| 273 | + $updatedCustomer = $this->customerFactory->create(); |
| 274 | + $this->dataObjectHelper->mergeDataObjects( |
| 275 | + CustomerInterface::class, |
| 276 | + $updatedCustomer, |
| 277 | + $savedCustomer |
| 278 | + ); |
| 279 | + $updatedCustomer->setCustomAttribute('custom_attribute1', $updateAttributeValue); |
| 280 | + $this->customerRepository->save($updatedCustomer); |
| 281 | + |
| 282 | + $customerAfter = $this->customerRepository->getById($savedCustomer->getId()); |
| 283 | + $this->assertSame( |
| 284 | + $customerAfter->getCustomAttribute('custom_attribute1')->getValue(), |
| 285 | + $updateAttributeValue |
| 286 | + ); |
| 287 | + |
| 288 | + $resource = $this->objectManager->get(\Magento\Framework\App\ResourceConnection::class); |
| 289 | + $connection = $resource->getConnection(); |
| 290 | + $tableStatus = $connection->showTableStatus('customer_entity_varchar'); |
| 291 | + $this->assertSame($tableStatus['Auto_increment'], '2'); |
| 292 | + } |
| 293 | + |
247 | 294 | /**
|
248 | 295 | * Test update customer address
|
249 | 296 | *
|
|
0 commit comments