Example #1
0
 /**
  * Sets up this test case
  * @return void
  */
 public function setUp()
 {
     $this->view = $this->getMock('TYPO3\\FLOW3\\Mvc\\View\\JsonView', array('loadConfigurationFromYamlFile'));
     $this->controllerContext = $this->getMock('TYPO3\\FLOW3\\Mvc\\Controller\\ControllerContext', array(), array(), '', FALSE);
     $this->response = $this->getMock('TYPO3\\FLOW3\\Http\\Response', array());
     $this->controllerContext->expects($this->any())->method('getResponse')->will($this->returnValue($this->response));
     $this->view->setControllerContext($this->controllerContext);
 }
Example #2
0
 /**
  * @test
  */
 public function renderReplacesErrorMessageMarkerWithEmptyStringIfNoErrorMessageIsSet()
 {
     $mockRequest = $this->getMock('\\TYPO3\\FLOW3\\Mvc\\RequestInterface');
     $this->controllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($mockRequest));
     $templateUrl = \vfsStream::url('testDirectory') . '/template.html';
     file_put_contents($templateUrl, 'error message: {ERROR_MESSAGE}');
     $this->view->expects($this->once())->method('getTemplatePathAndFilename')->will($this->returnValue($templateUrl));
     $this->assertSame('error message: ', $this->view->render());
 }
Example #3
0
 /**
  * Renders the not found view
  *
  * @return string The rendered view
  * @throws \TYPO3\FLOW3\Mvc\Exception if no request has been set
  * @api
  */
 public function render()
 {
     if (!is_object($this->controllerContext->getRequest())) {
         throw new \TYPO3\FLOW3\Mvc\Exception('Can\'t render view without request object.', 1192450280);
     }
     $template = file_get_contents($this->getTemplatePathAndFilename());
     $template = str_replace('{BASEURI}', $this->controllerContext->getRequest()->getHttpRequest()->getBaseUri(), $template);
     foreach ($this->variablesMarker as $variableName => $marker) {
         $variableValue = isset($this->variables[$variableName]) ? $this->variables[$variableName] : '';
         $template = str_replace('{' . $marker . '}', $variableValue, $template);
     }
     $this->controllerContext->getResponse()->setStatus(404);
     return $template;
 }
Example #4
0
 /**
  * Transforms the value view variable to a serializable
  * array represantion using a YAML view configuration and JSON encodes
  * the result.
  *
  * @return string The JSON encoded variables
  * @api
  */
 public function render()
 {
     $this->controllerContext->getResponse()->setHeader('Content-Type', 'application/json');
     $propertiesToRender = $this->renderArray();
     return json_encode($propertiesToRender);
 }