CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER, 'attribute_set_id' => CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER, 'attribute_group_id' => 1, 'attribute_code' => 'random_attribute', 'sort_order' => 2 ], 'random_attribute', ), DataFixture( CustomerAttribute::class, [ 'entity_type_id' => CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER, 'attribute_set_id' => CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER, 'attribute_group_id' => 1, 'source_model' => Table::class, 'backend_model' => ArrayBackend::class, 'attribute_code' => 'multiselect_attribute', 'frontend_input' => 'multiselect', 'sort_order' => 1 ], 'multiselect_attribute', ), DataFixture( AttributeOptionFixture::class, [ 'entity_type' => CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER, 'attribute_code' => '$multiselect_attribute.attribute_code$', 'label' => 'line 1', 'sort_order' => 20 ], 'multiselect_attribute_option1' ), DataFixture( AttributeOptionFixture::class, [ 'entity_type' => CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER, 'attribute_code' => '$multiselect_attribute.attribute_code$', 'label' => 'option 2', 'sort_order' => 30 ], 'multiselect_attribute_option2' ), DataFixture( AttributeOptionFixture::class, [ 'entity_type' => CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER, 'attribute_code' => '$multiselect_attribute.attribute_code$', 'label' => 'option 3', 'sort_order' => 10 ], 'multiselect_attribute_option3' ) ] class CreateCustomerV2WithCustomAttributesTest extends GraphQlAbstract { /** * @var string */ private $query = <<registry = Bootstrap::getObjectManager()->get(Registry::class); $this->customerRepository = Bootstrap::getObjectManager()->get(CustomerRepositoryInterface::class); $this->random_attribute = DataFixtureStorageManager::getStorage()->get('random_attribute'); $this->multiselect_attribute = DataFixtureStorageManager::getStorage()->get('multiselect_attribute'); $this->option2 = DataFixtureStorageManager::getStorage()->get('multiselect_attribute_option2'); $this->option3 = DataFixtureStorageManager::getStorage()->get('multiselect_attribute_option3'); } /** * @return void * @throws Exception */ public function testCreateCustomerAccountWithCustomAttributes() { $response = $this->graphQlMutation( sprintf( $this->query, $this->random_attribute->getAttributeCode(), 'new_value_for_attribute', $this->multiselect_attribute->getAttributeCode(), $this->option2->getValue() . "," . $this->option3->getValue() ) ); $this->assertEquals( [ 'createCustomerV2' => [ 'customer' => [ 'firstname' => 'Adam', 'lastname' => 'Smith', 'email' => 'adam@smith.com', 'custom_attributes' => [ 0 => [ 'code' => $this->multiselect_attribute->getAttributeCode(), 'selected_options' => [ [ 'label' => $this->option3->getLabel(), 'value' => $this->option3->getValue() ], [ 'label' => $this->option2->getLabel(), 'value' => $this->option2->getValue() ] ] ], 1 => [ 'code' => $this->random_attribute->getAttributeCode(), 'value' => 'new_value_for_attribute', ] ], ], ], ], $response ); } public function testCreateCustomerAccountWithNonExistingCustomAttribute() { $query = <<graphQlMutation($query); $this->assertEquals( [ 'createCustomerV2' => [ 'customer' => [ 'firstname' => 'John', 'lastname' => 'Doe', 'email' => 'john@doe.com', 'custom_attributes' => [] ], ], ], $response ); } protected function tearDown(): void { $email1 = 'adam@smith.com'; $email2 = 'john@doe.com'; try { $customer1 = $this->customerRepository->get($email1); $customer2 = $this->customerRepository->get($email2); } catch (Exception $exception) { return; } $this->registry->unregister('isSecureArea'); $this->registry->register('isSecureArea', true); $this->customerRepository->delete($customer1); $this->customerRepository->delete($customer2); $this->registry->unregister('isSecureArea'); $this->registry->register('isSecureArea', false); parent::tearDown(); } }