/** * Test get item with any type * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ public function testItemAnyType() { $this->_markTestAsRestOnly('Test will fail for SOAP because attribute values get converted to strings.'); $customerAttributes = [Item::CUSTOM_ATTRIBUTE_1 => [AttributeValue::ATTRIBUTE_CODE => Item::CUSTOM_ATTRIBUTE_1, AttributeValue::VALUE => '12345'], Item::CUSTOM_ATTRIBUTE_2 => [AttributeValue::ATTRIBUTE_CODE => Item::CUSTOM_ATTRIBUTE_2, AttributeValue::VALUE => 12345], Item::CUSTOM_ATTRIBUTE_3 => [AttributeValue::ATTRIBUTE_CODE => Item::CUSTOM_ATTRIBUTE_3, AttributeValue::VALUE => true]]; $attributeValue1 = $this->valueFactory->create()->setAttributeCode(Item::CUSTOM_ATTRIBUTE_1)->setValue('12345'); $attributeValue2 = $this->valueFactory->create()->setAttributeCode(Item::CUSTOM_ATTRIBUTE_2)->setValue(12345); $attributeValue3 = $this->valueFactory->create()->setAttributeCode(Item::CUSTOM_ATTRIBUTE_3)->setValue(true); $item = $this->itemFactory->create()->setItemId(1)->setName('testProductAnyType')->setCustomAttributes([$attributeValue1, $attributeValue2, $attributeValue3]); $serviceInfo = ['rest' => ['resourcePath' => $this->_restResourcePath . 'itemAnyType', 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST], 'soap' => ['service' => $this->_soapService, 'operation' => $this->_soapService . 'ItemAnyType']]; $requestData = $item->__toArray(); $item = $this->_webApiCall($serviceInfo, ['entityItem' => $requestData]); $this->assertSame($attributeValue1->getValue(), $item['custom_attributes'][0]['value'], 'Serialized attribute value type does\'t match pre-defined type.'); // string '12345' is expected $this->assertSame($attributeValue2->getValue(), $item['custom_attributes'][1]['value'], 'Serialized attribute value type does\'t match pre-defined type.'); // integer 12345 is expected $this->assertSame($attributeValue3->getValue(), $item['custom_attributes'][2]['value'], 'Serialized attribute value type does\'t match pre-defined type.'); // boolean true is expected }
/** * {@inheritdoc} */ public function getPreconfiguredItem() { $customAttributeDataObject = $this->customAttributeDataObjectFactory->create()->setName('nameValue')->setCustomAttribute('custom_attribute_int', 1); $item = $this->itemFactory->create()->setItemId(1)->setName('testProductAnyType')->setCustomAttribute('custom_attribute_data_object', $customAttributeDataObject)->setCustomAttribute('custom_attribute_string', 'someStringValue'); return $item; }