Skip to content

Commit

Permalink
fixes #6476, crash on missing layout in session flash
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8238 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information
gwoo committed Jul 21, 2009
1 parent c1bb970 commit 4cfdd31
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 5 deletions.
8 changes: 4 additions & 4 deletions cake/libs/view/helpers/session.php
Expand Up @@ -142,10 +142,10 @@ function flash($key = 'flash') {
$out = $flash['message'];
} else {
$view =& ClassRegistry::getObject('view');
list($tmpLayout, $tmpVars, $tmpTitle) = array($view->layout, $view->viewVars, $view->pageTitle);
list($view->layout, $view->viewVars, $view->pageTitle) = array($flash['layout'], $flash['params'], '');
$out = $view->renderLayout($flash['message']);
list($view->layout, $view->viewVars, $view->pageTitle) = array($tmpLayout, $tmpVars, $tmpTitle);
list($tmpVars, $tmpTitle) = array($view->viewVars, $view->pageTitle);
list($view->viewVars, $view->pageTitle) = array($flash['params'], '');
$out = $view->renderLayout($flash['message'], $flash['layout']);
list($view->viewVars, $view->pageTitle) = array($tmpVars, $tmpTitle);
}
echo($out);
parent::del('Message.' . $key);
Expand Down
6 changes: 5 additions & 1 deletion cake/libs/view/view.php
Expand Up @@ -417,6 +417,10 @@ function render($action = null, $layout = null, $file = null) {
*/
function renderLayout($content_for_layout, $layout = null) {
$layoutFileName = $this->_getLayoutFileName($layout);
if (empty($layoutFileName)) {
return $this->output;
}

$debug = '';

if (isset($this->viewVars['cakeDebug']) && Configure::read() > 2) {
Expand Down Expand Up @@ -892,7 +896,7 @@ function _paths($plugin = null, $cached = true) {
$paths = array();
$viewPaths = Configure::read('viewPaths');

if ($plugin !== null) {
if (!empty($plugin)) {
$count = count($viewPaths);
for ($i = 0; $i < $count; $i++) {
$paths[] = $viewPaths[$i] . 'plugins' . DS . $plugin . DS;
Expand Down
52 changes: 52 additions & 0 deletions cake/tests/cases/libs/view/helpers/session.test.php
Expand Up @@ -27,6 +27,26 @@
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
}
if (!class_exists('AppError')) {
App::import('Error');
/**
* AppController class
*
* @package cake
* @subpackage cake.tests.cases.libs
*/
class AppError extends ErrorHandler {
/**
* _stop method
*
* @access public
* @return void
*/
function _stop() {
return;
}
}
}
App::import('Core', array('Helper', 'AppHelper', 'Controller', 'View'));
App::import('Helper', array('Session'));
/**
Expand Down Expand Up @@ -143,7 +163,9 @@ function testFlash() {
$result = ob_get_clean();
$this->assertEqual($result, $expected);

$_viewPaths = Configure::read('viewPaths');
Configure::write('viewPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS));

$controller = new Controller();
$this->Session->view = new View($controller);

Expand All @@ -165,6 +187,36 @@ function testFlash() {
$expected = 'Bare message';
$this->assertEqual($result, $expected);
$this->assertFalse($this->Session->check('Message.bare'));

Configure::write('viewPaths', $_viewPaths);
}
/**
* testFlash method
*
* @access public
* @return void
*/
function testFlashMissingLayout() {
$_SESSION = array(
'Message' => array(
'notification' => array(
'layout' => 'does_not_exist',
'params' => array('title' => 'Notice!', 'name' => 'Alert!'),
'message' => 'This is a test of the emergency broadcasting system',
)
)
);

$controller = new Controller();
$this->Session->view = new View($controller);

ob_start();
$this->Session->flash('notification');
$result = ob_get_contents();
ob_clean();

$this->assertPattern("/Missing Layout/", $result);
$this->assertPattern("/layouts\/does_not_exist.ctp/", $result);
}
/**
* testID method
Expand Down

0 comments on commit 4cfdd31

Please sign in to comment.