public function testSetDataTable()
 {
     $request = new Request();
     $data = new DataTable();
     $data->addColumn(new ColumnDescription('textfield', ValueType::STRING));
     $data->addColumn(new ColumnDescription('intfield', ValueType::NUMBER));
     $response = new Response($request);
     $response->setDataTable($data);
     $getRequest = $response->getRequest();
     $getDataTable = $response->getDataTable();
     $this->assertEquals($request, $getRequest, "Request must match");
     $this->assertEquals($data, $getDataTable, "DataTable must match");
 }
 /**
  * @param Response $response
  * @param ResponseStatus $responseStatus
  * @return string JSON or JSONP output
  */
 public function render(Response $response, ResponseStatus $responseStatus = null)
 {
     $output = '';
     $request = $response->getRequest();
     $outputTypeCode = $request->getOutputType()->getCode();
     $isJsonP = $outputTypeCode === OutputType::JSONP;
     if ($isJsonP) {
         $responseHandler = $request->getParameters()->getParameter(RequestParameters::RESPONSE_HANDLER_PARAMETER);
         $output .= $responseHandler . '(';
     }
     $dataTable = $response->getDataTable();
     $output .= "{\"version\":\"0.6\"";
     $reqId = $request->getRequestId();
     if ($reqId !== false) {
         $output .= ",\"reqId\":" . json_encode($reqId);
     }
     if ($responseStatus === null) {
         $sig = $request->getSignature();
         if ($sig !== false && $sig === $this->getSignature($dataTable)) {
             $responseStatus = new ResponseStatus(new StatusType(StatusType::ERROR), new ReasonType(ReasonType::NOT_MODIFIED));
         } else {
             $responseStatus = new ResponseStatus(new StatusType(StatusType::OK));
         }
     }
     $statusTypeCode = $responseStatus->getStatusType()->getCode();
     $output .= ",\"status\":" . json_encode($statusTypeCode);
     if ($statusTypeCode != StatusType::OK) {
         if ($statusTypeCode == StatusType::WARNING) {
             $warnings = $dataTable->getWarnings();
             $warningStrings = array();
             foreach ($warnings as $warning) {
                 $warningStrings[] = $this->getFaultString($warning->getReasonType(), $warning->getMessage());
             }
             $output .= ",\"warnings\":[" . implode(",", $warningStrings) . "]";
         } else {
             $errorsOutput = $this->getFaultString($responseStatus->getReasonType(), $responseStatus->getDescription());
             $output .= ",\"errors\":[" . $errorsOutput . "]";
         }
     }
     if ($statusTypeCode != StatusType::ERROR && $dataTable !== null) {
         $output .= ",\"sig\":" . json_encode($this->getSignature($dataTable));
         $output .= ",\"table\":" . $this->renderDataTable($dataTable, true, true, $isJsonP);
     }
     $output .= "}";
     if ($isJsonP) {
         $output .= ");";
     }
     return $output;
 }
 public function testGetSignature()
 {
     $renderer = new JsonRenderer();
     $sig = $renderer->getSignature($this->response->getDataTable());
     $this->assertTrue(is_string($sig), "signature must be a string");
 }