Fix session flash with plugins.

Fix using plugin elements for SessionHelper::flash()
Fixes #2246
This commit is contained in:
mark_story 2011-11-12 11:03:17 -05:00
parent 5934a7a324
commit 3ad50a2591
2 changed files with 26 additions and 2 deletions

View file

@ -80,6 +80,7 @@ class SessionHelperTest extends CakeTestCase {
public function tearDown() {
$_SESSION = array();
unset($this->View, $this->Session);
CakePlugin::unload();
parent::tearDown();
}
@ -160,7 +161,7 @@ class SessionHelperTest extends CakeTestCase {
*/
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',
@ -168,4 +169,23 @@ class SessionHelperTest extends CakeTestCase {
));
$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);
}
}

View file

@ -128,9 +128,13 @@ class SessionHelper extends AppHelper {
} 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);
}