From f9f06e68b1c59f5a0119ae2969c0d7ce70d5c321 Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Wed, 30 Aug 2017 10:06:56 -0500 Subject: [PATCH] Stacking messages in SessionComponent::setFlash --- lib/Cake/Controller/Component/SessionComponent.php | 8 +++++++- .../Case/Controller/Component/SessionComponentTest.php | 9 +++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/Cake/Controller/Component/SessionComponent.php b/lib/Cake/Controller/Component/SessionComponent.php index 4c7b467da..f66f5be62 100644 --- a/lib/Cake/Controller/Component/SessionComponent.php +++ b/lib/Cake/Controller/Component/SessionComponent.php @@ -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); } /** diff --git a/lib/Cake/Test/Case/Controller/Component/SessionComponentTest.php b/lib/Cake/Test/Case/Controller/Component/SessionComponentTest.php index dd0df58c7..8814a491f 100644 --- a/lib/Cake/Test/Case/Controller/Component/SessionComponentTest.php +++ b/lib/Cake/Test/Case/Controller/Component/SessionComponentTest.php @@ -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'); }