/**
  * @magentoApiDataFixture Magento/Customer/_files/attribute_user_defined_address.php
  * @magentoApiDataFixture Magento/Customer/_files/attribute_user_defined_customer.php
  */
 public function testCustomAttributes()
 {
     //Sample customer data comes with the disable_auto_group_change custom attribute
     $customerData = $this->customerHelper->createSampleCustomerDataObject();
     //address attribute code from fixture
     $fixtureAddressAttributeCode = 'address_user_attribute';
     //customer attribute code from fixture
     $fixtureCustomerAttributeCode = 'user_attribute';
     //Custom Attribute Values
     $address1CustomAttributeValue = 'value1';
     $address2CustomAttributeValue = 'value2';
     $customerCustomAttributeValue = 'value3';
     $addresses = $customerData->getAddresses();
     $addresses[0]->setCustomAttribute($fixtureAddressAttributeCode, $address1CustomAttributeValue);
     $addresses[1]->setCustomAttribute($fixtureAddressAttributeCode, $address2CustomAttributeValue);
     $customerData->setAddresses($addresses);
     $customerData->setCustomAttribute($fixtureCustomerAttributeCode, $customerCustomAttributeValue);
     $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH, 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST], 'soap' => ['service' => self::SERVICE_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_NAME . 'CreateAccount']];
     $customerDataArray = $this->dataObjectProcessor->buildOutputDataArray($customerData, '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     $requestData = ['customer' => $customerDataArray, 'password' => CustomerHelper::PASSWORD];
     $customerData = $this->_webApiCall($serviceInfo, $requestData);
     $customerId = $customerData['id'];
     //TODO: Fix assertions to verify custom attributes
     $this->assertNotNull($customerData);
     $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH . '/' . $customerId, 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_DELETE], 'soap' => ['service' => CustomerRepositoryTest::SERVICE_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => CustomerRepositoryTest::SERVICE_NAME . 'DeleteById']];
     $response = $this->_webApiCall($serviceInfo, ['customerId' => $customerId]);
     $this->assertTrue($response);
 }
 /**
  * Test creating a customer with absent required address fields
  */
 public function testCreateCustomerWithoutAddressRequiresException()
 {
     $customerDataArray = $this->dataObjectProcessor->buildOutputDataArray($this->customerHelper->createSampleCustomerDataObject(), '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     foreach ($customerDataArray[Customer::KEY_ADDRESSES] as &$address) {
         $address[Address::FIRSTNAME] = null;
     }
     $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH, 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST], 'soap' => ['service' => self::SERVICE_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_NAME . 'Save']];
     $requestData = ['customer' => $customerDataArray];
     try {
         $this->_webApiCall($serviceInfo, $requestData);
         $this->fail('Expected exception did not occur.');
     } catch (\Exception $e) {
         if (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) {
             $expectedException = new InputException();
             $expectedException->addError(__('%fieldName is a required field.', ['fieldName' => Address::FIRSTNAME]));
             $this->assertInstanceOf('SoapFault', $e);
             $this->checkSoapFault($e, $expectedException->getRawMessage(), 'env:Sender', $expectedException->getParameters());
         } else {
             $this->assertEquals(HTTPExceptionCodes::HTTP_BAD_REQUEST, $e->getCode());
             $exceptionData = $this->processRestExceptionResult($e);
             $expectedExceptionData = ['message' => '%fieldName is a required field.', 'parameters' => ['fieldName' => Address::FIRSTNAME]];
             $this->assertEquals($expectedExceptionData, $exceptionData);
         }
     }
     try {
         $this->customerRegistry->retrieveByEmail($customerDataArray[Customer::EMAIL], $customerDataArray[Customer::WEBSITE_ID]);
         $this->fail('An expected NoSuchEntityException was not thrown.');
     } catch (NoSuchEntityException $e) {
         $exception = NoSuchEntityException::doubleField('email', $customerDataArray[Customer::EMAIL], 'websiteId', $customerDataArray[Customer::WEBSITE_ID]);
         $this->assertEquals($exception->getMessage(), $e->getMessage(), 'Exception message does not match expected message.');
     }
 }
 /**
  * Create customer with image attribute
  *
  * @param array $imageData
  * @return array Customer data as array
  */
 protected function createCustomerWithImageAttribute($imageData)
 {
     $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH, 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST], 'soap' => ['service' => self::SERVICE_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_NAME . 'CreateAccount']];
     $customerData = $this->customerHelper->createSampleCustomerDataObject();
     $customerDataArray = $this->dataObjectProcessor->buildOutputDataArray($customerData, '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     $customerDataArray['custom_attributes'][] = ['attribute_code' => 'customer_image', 'value' => $imageData];
     $requestData = ['customer' => $customerDataArray, 'password' => \Magento\TestFramework\Helper\Customer::PASSWORD];
     $customerData = $this->_webApiCall($serviceInfo, $requestData);
     return $customerData;
 }
Esempio n. 4
0
 /**
  * @return array
  */
 private function generateCustomerData()
 {
     $customer = $this->customerHelper->createSampleCustomerDataObject();
     /** @var \Magento\TestModuleDefaultHydrator\Api\Data\ExtensionAttributeInterface $extensionAttribute */
     $extensionAttribute = $this->objectManager->create(\Magento\TestModuleDefaultHydrator\Api\Data\ExtensionAttributeInterface::class);
     $extensionAttribute->setValue('extension attribute value');
     /** @var \Magento\Customer\Api\Data\CustomerExtensionInterface $customerExtension */
     $customerExtension = $this->objectManager->create(\Magento\Customer\Api\Data\CustomerExtension::class);
     $customerExtension->setExtensionAttribute($extensionAttribute);
     $customer->setExtensionAttributes($customerExtension);
     $customer->setCustomAttribute('custom_attribute1', 'custom attribute value');
     $customerData = $this->dataObjectProcessor->buildOutputDataArray($customer, \Magento\Customer\Api\Data\CustomerInterface::class);
     return $customerData;
 }