Skip to content

Commit

Permalink
Fix session flash with plugins.
Browse files Browse the repository at this point in the history
Fix using plugin elements for SessionHelper::flash()
Fixes #2246
  • Loading branch information
markstory committed Nov 12, 2011
1 parent 5934a7a commit 3ad50a2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
22 changes: 21 additions & 1 deletion lib/Cake/Test/Case/View/Helper/SessionHelperTest.php
Expand Up @@ -80,6 +80,7 @@ public function setUp() {
public function tearDown() {
$_SESSION = array();
unset($this->View, $this->Session);
CakePlugin::unload();
parent::tearDown();
}

Expand Down Expand Up @@ -160,12 +161,31 @@ public function testFlashAttributes() {
*/
public function testFlashElementInAttrs() {
App::build(array(
'views' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS)
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS)
));
$result = $this->Session->flash('flash', array(
'element' => 'session_helper',
'params' => array('title' => 'Notice!', 'name' => 'Alert!')
));
$expected = "<div id=\"notificationLayout\">\n\t<h1>Alert!</h1>\n\t<h3>Notice!</h3>\n\t<p>This is a calling</p>\n</div>";
}

/**
* test using eleents in plugins.
*
* @return void
*/
public function testFlashWithPluginElement() {
App::build(array(
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin'. DS)
));
CakePlugin::load('TestPlugin');

$result = $this->Session->flash('flash', array(
'element' => 'plugin_element',
'plugin' => 'TestPlugin'
));
$expected = 'this is the plugin element using params[plugin]';
$this->assertEquals($expected, $result);
}
}
6 changes: 5 additions & 1 deletion lib/Cake/View/Helper/SessionHelper.php
Expand Up @@ -128,9 +128,13 @@ public function flash($key = 'flash', $attrs = array()) {
} elseif ($flash['element'] == '' || $flash['element'] == null) {
$out = $message;
} else {
$options = array();
if (isset($flash['plugin'])) {
$options['plugin'] = $flash['plugin'];
}
$tmpVars = $flash['params'];
$tmpVars['message'] = $message;
$out = $this->_View->element($flash['element'], $tmpVars);
$out = $this->_View->element($flash['element'], $tmpVars, $options);
}
CakeSession::delete('Message.' . $key);
}
Expand Down

0 comments on commit 3ad50a2

Please sign in to comment.