Permalink
Browse files

fixes #6476, crash on missing layout in session flash

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8238 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information...
1 parent c1bb970 commit 4cfdd311a90a8749ba4d45c43dc19d89355cedd5 gwoo committed Jul 21, 2009
@@ -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);
View
@@ -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) {
@@ -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;
@@ -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'));
/**
@@ -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);
@@ -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

0 comments on commit 4cfdd31

Please sign in to comment.