/** * @covers WSHelper::extractParamerts * @expectedException WebServiceException */ public function testExtractParamerts_WithEmptyModuleAndMethod() { $requestMock = $this->getMock('sfWebRequest', array('getMethod', 'getHttpHeader', 'getRequestParameters'), array(new sfEventDispatcher())); $requestMock->expects($this->once())->method('getMethod')->will($this->returnValue('GET')); $requestMock->expects($this->any())->method('getHttpHeader')->will($this->onConsecutiveCalls(array(array('app_id' => 1, 'app_token' => '1234', 'session_token' => '_absdjwsef43ismk43efdker')))); $requestMock->expects($this->once())->method('getRequestParameters')->will($this->returnValue(array('module' => 'api', 'action' => 'wsCall', '_sf_route' => null))); $this->helper->extractParamerts($requestMock); }
public function execute($request) { $wsHelper = new WSHelper(); $wsManager = new WSManager(); $result = ''; $status = 'INITIAL'; $contentType = 'text/plain'; try { $paramObj = $wsHelper->extractParamerts($request); $isMethodAvailable = $wsManager->isMethodAvailable($paramObj->getMethod()); if ($isMethodAvailable) { $isAuthenticated = $wsManager->isAuthenticated($paramObj); $isAuthorized = $wsManager->isAuthorized($paramObj); if ($isAuthenticated && $isAuthorized) { try { $result = $wsManager->callMethod($paramObj); $result = $wsHelper->formatResult($result, WSHelper::FORMAT_JSON); $status = 'SUCCESS'; $contentType = 'text/json'; } catch (Exception $e) { $logger = $this->getWebServiceLogger(); $logger->info('Uncaught Exception: ' . $e->getMessage()); $result = 'INTERNAL ERROR'; $status = 'ERROR'; } } else { $result = 'NOT ALLOWED'; $status = 'ERROR'; } } else { $result = 'INVALID REQUEST'; $status = 'ERROR'; } } catch (WebServiceException $e) { $result = $e->getCode() . ': ' . $e->getMessage(); $status = 'ERROR'; } $this->getResponse()->setContent($result); $this->getResponse()->setHttpHeader('Content-type', $contentType); $this->getResponse()->setHttpHeader('ohrm_ws_call_status', $status); return sfView::NONE; }