mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Stacking messages in SessionComponent::setFlash
This commit is contained in:
parent
81d824077a
commit
f9f06e68b1
2 changed files with 10 additions and 7 deletions
|
@ -136,7 +136,13 @@ class SessionComponent extends Component {
|
|||
* @deprecated 3.0.0 Since 2.7, use the FlashComponent instead.
|
||||
*/
|
||||
public function setFlash($message, $element = 'default', $params = array(), $key = 'flash') {
|
||||
CakeSession::write('Message.' . $key, compact('message', 'element', 'params'));
|
||||
$messages = (array)CakeSession::read('Message.' . $key);
|
||||
$messages[] = [
|
||||
'message' => $message,
|
||||
'element' => $element,
|
||||
'params' => $params,
|
||||
];
|
||||
CakeSession::write('Message.' . $key, $messages);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -247,16 +247,13 @@ class SessionComponentTest extends CakeTestCase {
|
|||
$this->assertNull($Session->read('Message.flash'));
|
||||
|
||||
$Session->setFlash('This is a test message');
|
||||
$this->assertEquals(array('message' => 'This is a test message', 'element' => 'default', 'params' => array()), $Session->read('Message.flash'));
|
||||
$this->assertEquals(array('message' => 'This is a test message', 'element' => 'default', 'params' => array()), $Session->read('Message.flash.0'));
|
||||
|
||||
$Session->setFlash('This is a test message', 'test', array('name' => 'Joel Moss'));
|
||||
$this->assertEquals(array('message' => 'This is a test message', 'element' => 'test', 'params' => array('name' => 'Joel Moss')), $Session->read('Message.flash'));
|
||||
$this->assertEquals(array('message' => 'This is a test message', 'element' => 'test', 'params' => array('name' => 'Joel Moss')), $Session->read('Message.flash.1'));
|
||||
|
||||
$Session->setFlash('This is a test message', 'default', array(), 'myFlash');
|
||||
$this->assertEquals(array('message' => 'This is a test message', 'element' => 'default', 'params' => array()), $Session->read('Message.myFlash'));
|
||||
|
||||
$Session->setFlash('This is a test message', 'non_existing_layout');
|
||||
$this->assertEquals(array('message' => 'This is a test message', 'element' => 'default', 'params' => array()), $Session->read('Message.myFlash'));
|
||||
$this->assertEquals(array('message' => 'This is a test message', 'element' => 'default', 'params' => array()), $Session->read('Message.myFlash.0'));
|
||||
|
||||
$Session->delete('Message');
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue