public function testGetRequestedResources() { /** Prepare mocks for SUT constructor. */ $resources = array('resourceName_1' => 'version', 'resourceName_2' => 'version'); $requestParams = array(Mage_Webapi_Model_Soap_Server::REQUEST_PARAM_WSDL => true, Mage_Webapi_Model_Soap_Server::REQUEST_PARAM_RESOURCES => $resources, Mage_Webapi_Controller_Router_Route_Webapi::PARAM_API_TYPE => 'soap'); $this->_soapRequest->setParams($requestParams); /** Execute SUT. */ $this->assertEquals($resources, $this->_soapRequest->getRequestedResources(), 'Requested resources were retrieved incorrectly. '); }
/** * Test generateUri method. * * @dataProvider providerForGenerateUriTest */ public function testGenerateUri($isWsdl, $resources, $expectedUri, $assertMessage) { $this->_storeMock->expects($this->once())->method('getBaseUrl')->will($this->returnValue('http://magento.com/')); $this->_requestMock->expects($this->once())->method('getRequestedResources')->will($this->returnValue($resources)); $actualUri = $this->_soapServer->generateUri($isWsdl); $this->assertEquals($expectedUri, $actualUri, $assertMessage); }
/** * Dispatch request to SOAP endpoint. * * @return Mage_Webapi_Controller_Dispatcher_Soap */ public function dispatch() { try { if ($this->_request->getParam(Mage_Webapi_Model_Soap_Server::REQUEST_PARAM_WSDL) !== null) { $responseBody = $this->_autoDiscover->handle($this->_request->getRequestedResources(), $this->_soapServer->generateUri()); $this->_setResponseContentType('text/xml'); } else { $responseBody = $this->_initSoapServer()->handle(); $this->_setResponseContentType('application/soap+xml'); } $this->_setResponseBody($responseBody); } catch (Exception $e) { $maskedException = $this->_errorProcessor->maskException($e); $this->_processBadRequest($maskedException->getMessage()); } $this->_response->sendResponse(); return $this; }
/** * Get SOAP endpoint URL. * * @param bool $isWsdl * @return string */ public function generateUri($isWsdl = false) { $params = array(self::REQUEST_PARAM_RESOURCES => $this->_request->getRequestedResources()); if ($isWsdl) { $params[self::REQUEST_PARAM_WSDL] = true; } $query = http_build_query($params, '', '&'); return $this->getEndpointUri() . '?' . $query; }
/** * 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; }