mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-18 23:49:55 +00:00
Fix session flash with plugins.
Fix using plugin elements for SessionHelper::flash() Fixes #2246
This commit is contained in:
parent
5934a7a324
commit
3ad50a2591
2 changed files with 26 additions and 2 deletions
|
@ -80,6 +80,7 @@ class SessionHelperTest extends CakeTestCase {
|
||||||
public function tearDown() {
|
public function tearDown() {
|
||||||
$_SESSION = array();
|
$_SESSION = array();
|
||||||
unset($this->View, $this->Session);
|
unset($this->View, $this->Session);
|
||||||
|
CakePlugin::unload();
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,7 +161,7 @@ class SessionHelperTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function testFlashElementInAttrs() {
|
public function testFlashElementInAttrs() {
|
||||||
App::build(array(
|
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(
|
$result = $this->Session->flash('flash', array(
|
||||||
'element' => 'session_helper',
|
'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>";
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,9 +128,13 @@ class SessionHelper extends AppHelper {
|
||||||
} elseif ($flash['element'] == '' || $flash['element'] == null) {
|
} elseif ($flash['element'] == '' || $flash['element'] == null) {
|
||||||
$out = $message;
|
$out = $message;
|
||||||
} else {
|
} else {
|
||||||
|
$options = array();
|
||||||
|
if (isset($flash['plugin'])) {
|
||||||
|
$options['plugin'] = $flash['plugin'];
|
||||||
|
}
|
||||||
$tmpVars = $flash['params'];
|
$tmpVars = $flash['params'];
|
||||||
$tmpVars['message'] = $message;
|
$tmpVars['message'] = $message;
|
||||||
$out = $this->_View->element($flash['element'], $tmpVars);
|
$out = $this->_View->element($flash['element'], $tmpVars, $options);
|
||||||
}
|
}
|
||||||
CakeSession::delete('Message.' . $key);
|
CakeSession::delete('Message.' . $key);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue