Ejemplo n.º 1
0
 public function testCall()
 {
     $requestedServices = array('requestedServices');
     $this->_requestMock->expects($this->once())->method('getRequestedServices')->will($this->returnValue($requestedServices));
     $this->_dataObjectConverter->expects($this->once())->method('convertStdObjectToArray')->will($this->returnValue(['field' => 1]));
     $operationName = 'soapOperation';
     $className = 'Magento\\Framework\\Object';
     $methodName = 'testMethod';
     $isSecure = false;
     $aclResources = array('Magento_TestModule::resourceA');
     $this->_apiConfigMock->expects($this->once())->method('getServiceMethodInfo')->with($operationName, $requestedServices)->will($this->returnValue(array(SoapConfig::KEY_CLASS => $className, SoapConfig::KEY_METHOD => $methodName, SoapConfig::KEY_IS_SECURE => $isSecure, SoapConfig::KEY_ACL_RESOURCES => $aclResources)));
     $this->_authzServiceMock->expects($this->once())->method('isAllowed')->will($this->returnValue(true));
     $serviceMock = $this->getMockBuilder($className)->disableOriginalConstructor()->setMethods(array($methodName))->getMock();
     $serviceResponse = array('foo' => 'bar');
     $serviceMock->expects($this->once())->method($methodName)->will($this->returnValue($serviceResponse));
     $this->_objectManagerMock->expects($this->once())->method('get')->with($className)->will($this->returnValue($serviceMock));
     $this->_serializerMock->expects($this->once())->method('getInputData')->will($this->returnArgument(2));
     /** Execute SUT. */
     $this->assertEquals(array('result' => $serviceResponse), $this->_handler->__call($operationName, array((object) array('field' => 1))));
 }
Ejemplo n.º 2
0
 /**
  * Convert service response into format acceptable by SoapServer.
  *
  * @param object|array|string|int|float|null $data
  * @return array
  * @throws \InvalidArgumentException
  */
 protected function _prepareResponseData($data)
 {
     if ($data instanceof AbstractObject) {
         $result = $this->_dataObjectConverter->convertKeysToCamelCase($data->__toArray());
     } elseif (is_array($data)) {
         foreach ($data as $key => $value) {
             $result[$key] = $value instanceof AbstractObject ? $this->_dataObjectConverter->convertKeysToCamelCase($value->__toArray()) : $value;
         }
     } elseif (is_scalar($data) || is_null($data)) {
         $result = $data;
     } else {
         throw new \InvalidArgumentException("Service returned result in invalid format.");
     }
     return array(self::RESULT_NODE_NAME => $result);
 }
Ejemplo n.º 3
0
 /**
  * Load customer group collection data from service
  *
  * @param bool $printQuery
  * @param bool $logQuery
  * @return $this
  */
 public function loadData($printQuery = false, $logQuery = false)
 {
     if (!$this->isLoaded()) {
         $searchCriteria = $this->getSearchCriteria();
         $searchResults = $this->groupService->searchGroups($searchCriteria);
         $this->_totalRecords = $searchResults->getTotalCount();
         /** @var CustomerGroup[] $groups */
         $groups = $searchResults->getItems();
         foreach ($groups as $group) {
             $groupItem = new \Magento\Framework\Object();
             $groupItem->addData(\Magento\Framework\Service\DataObjectConverter::toFlatArray($group));
             $this->_addItem($groupItem);
         }
         $this->_setIsLoaded();
     }
     return $this;
 }
 public function testConvertSoapStdObjectToArray()
 {
     $stdObject = json_decode(json_encode($this->getCustomerDetails()->__toArray()), false);
     $addresses = $stdObject->addresses;
     unset($stdObject->addresses);
     $stdObject->addresses = new \stdClass();
     $stdObject->addresses->item = $addresses;
     $response = $this->dataObjectConverter->convertStdObjectToArray($stdObject);
     //Check array conversion
     $this->assertTrue(is_array($response['customer']));
     $this->assertTrue(is_array($response['addresses']));
     $this->assertEquals(2, count($response['addresses']['item']));
     //Check if data is correct
     $this->assertEquals(self::FIRSTNAME, $response['customer']['firstname']);
     $this->assertEquals(self::GROUP_ID, $response['customer']['group_id']);
     foreach ($response['addresses']['item'] as $key => $address) {
         $region = $address['region'];
         $this->assertEquals(self::REGION, $region['region']);
         $this->assertEquals(self::REGION_CODE, $region['region_code']);
         $this->assertEquals(self::REGION_ID, $region['region_id']);
         $this->assertEquals($this->expectedStreet[$key], $address['street']);
     }
 }
 /**
  * @magentoDbIsolation enabled
  */
 public function testCreateCustomerInServiceVsInModel()
 {
     $email = '*****@*****.**';
     $email2 = '*****@*****.**';
     $firstname = 'Tester';
     $lastname = 'McTest';
     $groupId = 1;
     $password = '******';
     /** @var \Magento\Customer\Model\Customer $customerModel */
     $customerModel = $this->_objectManager->create('Magento\\Customer\\Model\\CustomerFactory')->create();
     $customerModel->setEmail($email)->setFirstname($firstname)->setLastname($lastname)->setGroupId($groupId)->setPassword($password);
     $customerModel->save();
     /** @var \Magento\Customer\Model\Customer $customerModel */
     $savedModel = $this->_objectManager->create('Magento\\Customer\\Model\\CustomerFactory')->create()->load($customerModel->getId());
     $dataInModel = $savedModel->getData();
     $this->_customerBuilder->setEmail($email2)->setFirstname($firstname)->setLastname($lastname)->setGroupId($groupId);
     $newCustomerEntity = $this->_customerBuilder->create();
     $customerDetails = $this->_customerDetailsBuilder->setCustomer($newCustomerEntity)->create();
     $customerData = $this->_customerAccountService->createCustomer($customerDetails, $password);
     $this->assertNotNull($customerData->getId());
     $savedCustomer = $this->_customerAccountService->getCustomer($customerData->getId());
     $dataInService = \Magento\Framework\Service\DataObjectConverter::toFlatArray($savedCustomer);
     $expectedDifferences = ['created_at', 'updated_at', 'email', 'is_active', 'entity_id', 'entity_type_id', 'password_hash', 'attribute_set_id', 'disable_auto_group_change', 'confirmation', 'reward_update_notification', 'reward_warning_notification'];
     foreach ($dataInModel as $key => $value) {
         if (!in_array($key, $expectedDifferences)) {
             if (is_null($value)) {
                 $this->assertArrayNotHasKey($key, $dataInService);
             } else {
                 $this->assertEquals($value, $dataInService[$key], 'Failed asserting value for ' . $key);
             }
         }
     }
     $this->assertEquals($email2, $dataInService['email']);
     $this->assertArrayNotHasKey('is_active', $dataInService);
     $this->assertArrayNotHasKey('updated_at', $dataInService);
     $this->assertArrayNotHasKey('password_hash', $dataInService);
 }
Ejemplo n.º 6
0
 /**
  * Initialize customer form
  *
  * @return \Magento\Customer\Model\Metadata\Form $customerForm
  */
 protected function _getCustomerForm()
 {
     if (is_null($this->_customerForm)) {
         $this->_customerForm = $this->_customerFormFactory->create('customer', 'adminhtml_customer', DataObjectConverter::toFlatArray($this->_getCustomerDataObject()));
     }
     return $this->_customerForm;
 }
 /**
  * Initializes Data Object with the data from array
  *
  * @param array $data
  * @return $this
  */
 protected function _setDataValues(array $data)
 {
     $dataObjectMethods = get_class_methods($this->_getDataObjectType());
     foreach ($data as $key => $value) {
         /* First, verify is there any getter for the key on the Service Data Object */
         $possibleMethods = array('get' . \Magento\Framework\Service\DataObjectConverter::snakeCaseToCamelCase($key), 'is' . \Magento\Framework\Service\DataObjectConverter::snakeCaseToCamelCase($key));
         if (array_intersect($possibleMethods, $dataObjectMethods)) {
             $this->_data[$key] = $value;
         }
     }
     return $this;
 }
Ejemplo n.º 8
0
 /**
  * Add rendering EAV attributes to Form element
  *
  * @param \Magento\Customer\Service\V1\Data\Eav\AttributeMetadata[] $attributes
  * @param \Magento\Framework\Data\Form\AbstractForm $form
  * @return $this
  */
 protected function _addAttributesToForm($attributes, \Magento\Framework\Data\Form\AbstractForm $form)
 {
     // add additional form types
     $types = $this->_getAdditionalFormElementTypes();
     foreach ($types as $type => $className) {
         $form->addType($type, $className);
     }
     $renderers = $this->_getAdditionalFormElementRenderers();
     foreach ($attributes as $attribute) {
         $inputType = $attribute->getFrontendInput();
         if ($inputType) {
             $element = $form->addField($attribute->getAttributeCode(), $inputType, array('name' => $attribute->getAttributeCode(), 'label' => __($attribute->getStoreLabel()), 'class' => $attribute->getFrontendClass(), 'required' => $attribute->isRequired()));
             if ($inputType == 'multiline') {
                 $element->setLineCount($attribute->getMultilineCount());
             }
             $element->setEntityAttribute($attribute);
             $this->_addAdditionalFormElementData($element);
             if (!empty($renderers[$attribute->getAttributeCode()])) {
                 $element->setRenderer($renderers[$attribute->getAttributeCode()]);
             }
             if ($inputType == 'select' || $inputType == 'multiselect') {
                 $options = array();
                 foreach ($attribute->getOptions() as $optionData) {
                     $options[] = \Magento\Framework\Service\DataObjectConverter::toFlatArray($optionData);
                 }
                 $element->setValues($options);
             } elseif ($inputType == 'date') {
                 $format = $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT);
                 $element->setImage($this->getViewFileUrl('images/grid-cal.gif'));
                 $element->setDateFormat($format);
             }
         }
     }
     return $this;
 }
Ejemplo n.º 9
0
 /**
  * @param string $field
  * @param StockItem $dataObject
  * @return mixed
  * @throws \BadMethodCallException
  */
 public function getDoFieldData($field, StockItem $dataObject)
 {
     $possibleMethods = array('get' . \Magento\Framework\Service\DataObjectConverter::snakeCaseToCamelCase($field), 'is' . \Magento\Framework\Service\DataObjectConverter::snakeCaseToCamelCase($field));
     foreach ($possibleMethods as $method) {
         if (method_exists($dataObject, $method)) {
             return $dataObject->{$method}();
         }
     }
     throw new \BadMethodCallException(__('Field "%1" was not found in DO "%2".', $field, get_class($dataObject)));
 }
Ejemplo n.º 10
0
 /**
  * @magentoDataFixture Magento/Customer/_files/customer_group.php
  */
 public function testSaveActionExistingGroup()
 {
     $groupId = $this->findGroupIdWithCode(self::CUSTOMER_GROUP_CODE);
     $this->getRequest()->setParam('tax_class', self::TAX_CLASS_ID);
     $this->getRequest()->setParam('id', $groupId);
     $this->getRequest()->setParam('code', self::CUSTOMER_GROUP_CODE);
     $this->dispatch('backend/customer/group/save');
     $this->assertSessionMessages($this->isEmpty(), MessageInterface::TYPE_ERROR);
     $this->assertSessionMessages($this->logicalNot($this->isEmpty()), MessageInterface::TYPE_SUCCESS);
     $this->assertSessionMessages($this->equalTo(['The customer group has been saved.']), MessageInterface::TYPE_SUCCESS);
     /** @var \Magento\Customer\Service\V1\CustomerGroupServiceInterface $groupService */
     $groupService = Bootstrap::getObjectManager()->get('Magento\\Customer\\Service\\V1\\CustomerGroupServiceInterface');
     $customerGroupData = \Magento\Framework\Service\DataObjectConverter::toFlatArray($groupService->getGroup($groupId));
     ksort($customerGroupData);
     $this->assertEquals(['code' => self::CUSTOMER_GROUP_CODE, 'id' => $groupId, 'tax_class_id' => self::TAX_CLASS_ID], $customerGroupData);
 }
Ejemplo n.º 11
0
 /**
  * Initializes Data Object with the data from array
  *
  * @param array $data
  * @return $this
  */
 protected function _setDataValues(array $data)
 {
     $dataObjectMethods = get_class_methods($this->_getDataObjectType());
     foreach ($data as $key => $value) {
         /* First, verify is there any getter for the key on the Service Data Object */
         $camelCaseKey = \Magento\Framework\Service\DataObjectConverter::snakeCaseToCamelCase($key);
         $possibleMethods = array('get' . $camelCaseKey, 'is' . $camelCaseKey);
         if ($key == AbstractObject::CUSTOM_ATTRIBUTES_KEY && !empty($data[$key])) {
             foreach ($data[$key] as $customAttribute) {
                 $this->setCustomAttribute($customAttribute[AttributeValue::ATTRIBUTE_CODE], $customAttribute[AttributeValue::VALUE]);
             }
         } elseif (array_intersect($possibleMethods, $dataObjectMethods)) {
             $this->_data[$key] = $value;
         } else {
             $this->setCustomAttribute($key, $value);
         }
     }
     return $this;
 }
 /**
  * @inheritdoc
  */
 public function getCustomAddressAttributeMetadata()
 {
     $customAttributes = [];
     if (!$this->addressDataObjectMethods) {
         $this->addressDataObjectMethods = array_flip(get_class_methods('Magento\\Customer\\Service\\V1\\Data\\Address'));
     }
     foreach ($this->getAllAddressAttributeMetadata() as $attributeMetadata) {
         $attributeCode = $attributeMetadata->getAttributeCode();
         $camelCaseKey = \Magento\Framework\Service\DataObjectConverter::snakeCaseToCamelCase($attributeCode);
         $isDataObjectMethod = isset($this->addressDataObjectMethods['get' . $camelCaseKey]) || isset($this->addressDataObjectMethods['is' . $camelCaseKey]);
         if (!$isDataObjectMethod && !$attributeMetadata->isSystem()) {
             $customAttributes[] = $attributeMetadata;
         }
     }
     return $customAttributes;
 }