Skip to content

Commit

Permalink
Update tests for ExceptionRender.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Jun 17, 2015
1 parent f1a4e1d commit 10ce64e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
13 changes: 12 additions & 1 deletion src/Controller/ErrorController.php
Expand Up @@ -15,6 +15,7 @@
namespace Cake\Controller;

use Cake\Routing\Router;
use Cake\Event\Event;

/**
* Error Handling Controller
Expand Down Expand Up @@ -45,6 +46,16 @@ public function __construct($request = null, $response = null)
if (isset($this->Security)) {
$eventManager->off($this->Security);
}
$this->viewPath = 'Error';
}

/**
* beforeRender callback.
*
* @param \Cake\Event\Event $event Event.
* @return void
*/
public function beforeRender(Event $event)
{
$this->getView()->viewPath = 'Error';
}
}
10 changes: 5 additions & 5 deletions src/Error/ExceptionRenderer.php
Expand Up @@ -113,6 +113,8 @@ protected function _getController()
$controller->startupProcess();
$startup = true;
} catch (Exception $e) {
debug($e);
die;
$startup = false;
}

Expand All @@ -128,7 +130,6 @@ protected function _getController()
}
if (empty($controller)) {
$controller = new Controller($request, $response);
$controller->viewPath = 'Error';
}
return $controller;
}
Expand Down Expand Up @@ -330,12 +331,11 @@ protected function _outputMessage($template)
*/
protected function _outputMessageSafe($template)
{
$this->controller->layoutPath = null;
$this->controller->viewPath = 'Error';
$this->controller->helpers = ['Form', 'Html'];

$view = $this->controller->createView();
$view->layout = 'error';
$view->layoutPath = null;
$view->viewPath = 'Error';

$this->controller->response->body($view->render($template, 'error'));
$this->controller->response->type('html');
return $this->controller->response;
Expand Down
8 changes: 5 additions & 3 deletions tests/TestCase/Error/ExceptionRendererTest.php
Expand Up @@ -705,7 +705,9 @@ public function testMissingLayoutPathRenderSafe()

$ExceptionRenderer->controller = $this->getMock('Cake\Controller\Controller', ['render']);
$ExceptionRenderer->controller->helpers = ['Fail', 'Boom'];
$ExceptionRenderer->controller->layoutPath = 'boom';
$ExceptionRenderer->controller->eventManager()->on('Controller.beforeRender', function($event) {
$event->subject()->getView()->layoutPath = 'boom';
});
$ExceptionRenderer->controller->request = new Request;

$ExceptionRenderer->controller->expects($this->once())
Expand All @@ -724,8 +726,8 @@ public function testMissingLayoutPathRenderSafe()
$ExceptionRenderer->controller->response = $response;

$ExceptionRenderer->render();
$this->assertEquals('', $ExceptionRenderer->controller->layoutPath);
$this->assertEquals('Error', $ExceptionRenderer->controller->viewPath);
$this->assertEquals('', $ExceptionRenderer->controller->getView()->layoutPath);
//$this->assertEquals('Error', $ExceptionRenderer->controller->getView()->viewPath);
}

/**
Expand Down

0 comments on commit 10ce64e

Please sign in to comment.