Exemplo n.º 1
0
 /**
  * Test that a response code is correctly set within a Frapi_Response
  */
 public function testResponseData()
 {
     $response = new Frapi_Response(array('data' => array('test' => 'success')));
     $data = $response->getData();
     $this->assertEquals('success', $data['test']);
 }
Exemplo n.º 2
0
 /**
  * Process Output
  *
  * This method will process the output by getting
  *
  * @return string  The output
  */
 public function processOutput()
 {
     // We check if we have errors, if we don't then we can process normally
     /**
      * Handle the headers and depending on whether they are a PUT, POST, DELETE, GET
      * we should invoke:
      *   $this->actionContext->executePost();
      *   $this->actionContext->executePut();
      *   $this->actionContext->executeDelete();
      *   $this->actionContext->executeGet();
      *   $this->actionContext->executeHead();
      */
     $method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : false;
     $action = 'executeAction';
     if ($method !== false) {
         $action = 'execute' . ucfirst(strtolower($method));
     }
     $response = $this->actionContext->setAction($action)->{$action}();
     // Make sure we use a Frapi_Response.
     if (!$response instanceof Frapi_Response) {
         $response = new Frapi_Response(array('data' => $response));
     }
     /**
      * Here we look for the temporary params so we can
      * automatically replace the jsonp_callback and handle
      * it in the OutputHandlers transparently.
      */
     $tmpParams = $this->actionContext->getParams();
     if (isset($tmpParams['jsonp_callback'])) {
         $response->setData($response->getData() + array('jsonp_callback' => $tmpParams['jsonp_callback']));
     }
     unset($tmpParams);
     /**
      * If the action result is NOT an instance of
      * Error, we can assume that it's valid
      * output so keep going and output the result
      */
     return $this->getOutputInstance($this->getFormat())->setOutputAction($this->getAction())->populateOutput($response->getData(), $this->actionContext->getTemplateFileName())->sendHeaders($response)->executeOutput();
 }
Exemplo n.º 3
0
 /**
  * Test that a reason phrase is correctly set with a Frapi_Response by a
  * standard http code
  */
 public function testReasonPhraseByHttpCode()
 {
     $response = new Frapi_Response(array('code' => 405));
     $this->assertEquals('Method Not Allowed', $response->getReasonPhrase());
 }