/** * Initialize SOAP Server. * * @return Mage_Webapi_Model_Soap_Server */ protected function _initSoapServer() { $this->_soapServer->initWsdlCache(); $this->_soapServer->setWSDL($this->_soapServer->generateUri(true))->setEncoding($this->_soapServer->getApiCharset())->setSoapVersion(SOAP_1_2)->setClassmap($this->_apiConfig->getTypeToClassMap()); use_soap_error_handler(false); // TODO: Headers are not available at this point. // $this->_soapHandler->setRequestHeaders($this->_getRequestHeaders()); $this->_soapServer->setReturnResponse(true)->setObject($this->_soapHandler); return $this->_soapServer; }
/** * Test handle method with exception. */ public function testHandleWithException() { /** Mock cache canUse method to return false. */ $this->_cacheMock->expects($this->once())->method('canUse')->will($this->returnValue(false)); $requestedResources = array('res1' => 'v1'); $exception = new LogicException('getResourceDataMerged Exception'); $this->_resourceConfigMock->expects($this->once())->method('getResourceDataMerged')->will($this->throwException($exception)); $this->setExpectedException('Mage_Webapi_Exception', 'getResourceDataMerged Exception', Mage_Webapi_Exception::HTTP_BAD_REQUEST); $this->_autoDiscover->handle($requestedResources, 'http://magento.host'); }
/** * Identify version of requested operation. * * This method is required when there are two or more resource versions specified in request: * http://magento.host/api/soap?wsdl&resources[resource_a]=v1&resources[resource_b]=v2 <br/> * In this case it is not obvious what version of requested operation should be used. * * @param string $operationName * @return int * @throws Mage_Webapi_Exception */ protected function _getOperationVersion($operationName) { $requestedResources = $this->_request->getRequestedResources(); $resourceName = $this->_apiConfig->getResourceNameByOperation($operationName); if (!isset($requestedResources[$resourceName])) { throw new Mage_Webapi_Exception($this->_helper->__('The version of "%s" operation cannot be identified.', $operationName), Mage_Webapi_Exception::HTTP_NOT_FOUND); } $version = (int) str_replace('V', '', ucfirst($requestedResources[$resourceName])); $this->_apiConfig->validateVersionNumber($version, $resourceName); return $version; }
/** * Process array of types. * * @param string $type * @param array $callInfo */ protected function _processArrayParameter($type, $callInfo = array()) { $arrayItemType = $this->_helper->getArrayItemType($type); $arrayTypeName = $this->_helper->translateArrayTypeName($type); if (!$this->_helper->isTypeSimple($arrayItemType)) { $this->addComplexType($arrayItemType, $callInfo); } $arrayTypeParameters = array(self::ARRAY_ITEM_KEY_NAME => array('type' => $arrayItemType, 'required' => false, 'isArray' => true, 'documentation' => sprintf('An item of %s.', $arrayTypeName))); $arrayTypeData = array('documentation' => sprintf('An array of %s items.', $arrayItemType), 'parameters' => $arrayTypeParameters); $this->_config->setTypeData($arrayTypeName, $arrayTypeData); $this->addComplexType($arrayTypeName, $callInfo); }
/** * Process call info data from interface. * * @param array $interface * @param string $resourceName * @param string $methodName */ protected function _processInterfaceCallInfo($interface, $resourceName, $methodName) { foreach ($interface as $direction => $interfaceData) { $direction = $direction == 'in' ? 'requiredInput' : 'returned'; foreach ($interfaceData['parameters'] as $parameterData) { $parameterType = $parameterData['type']; if (!$this->_helper->isTypeSimple($parameterType)) { $operation = $this->getOperationName($resourceName, $methodName); if ($parameterData['required']) { $condition = $direction == 'requiredInput' ? 'yes' : 'always'; } else { $condition = $direction == 'requiredInput' ? 'no' : 'conditionally'; } $callInfo = array(); $callInfo[$direction][$condition]['calls'][] = $operation; $this->_apiConfig->setTypeData($parameterType, array('callInfo' => $callInfo)); } } } }
/** * Test that complexType for Data structures has been generated correctly in WSDL. * See /_files/controllers/AutoDiscover/ModuleB/SubresourceData.php */ public function testGenerateDataStructureComplexTypes() { $wsdlNs = Wsdl::WSDL_NS; $xsdNs = Wsdl::XSD_NS; // Generated from Vendor_ModuleB_Model_Webapi_ModuleBData class. $dataStructureName = 'VendorModuleBData'; $typeData = $this->_config->getTypeData($dataStructureName); $complexTypeXpath = "//{$wsdlNs}:types/{$xsdNs}:schema/{$xsdNs}:complexType[@name='%s']"; /** @var DOMElement $dataStructure */ $dataStructure = $this->_xpath->query(sprintf($complexTypeXpath, $dataStructureName))->item(0); $this->assertNotNull($dataStructure, sprintf('Complex type for data structure "%s" was not found in WSDL.', $dataStructureName)); $this->_assertDocumentation($typeData['documentation'], $dataStructure); // Expected appinfo tags. $expectedAppinfo = (include __DIR__ . '/../../_files/Controller/annotation_fixture.php'); foreach ($typeData['parameters'] as $parameterName => $parameterData) { // remove all appinfo placeholders from expected doc. $expectedDoc = trim(preg_replace('/(\\{.*\\}|\\r)/U', '', $parameterData['documentation'])); $this->_assertParameter($parameterName, $parameterData['type'], $parameterData['required'], $expectedDoc, $expectedAppinfo[$parameterName], $dataStructure); } }
/** * Test getDataType functionality. * Expected result of method is placed in file fixture. */ public function testGetDataType() { $expectedType = (include __DIR__ . '/../../../_files/config/data_structure_fixture.php'); $this->assertEquals($expectedType, $this->_config->getTypeData('NamespaceAModuleAData')); }