Skip to content

Commit

Permalink
Change flash session variable from Message to Flash
Browse files Browse the repository at this point in the history
  • Loading branch information
bcrowe committed Jun 11, 2014
1 parent 455ce4a commit 795eb4d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/Controller/Component/FlashComponent.php
Expand Up @@ -63,7 +63,7 @@ public function __construct(ComponentRegistry $collection, array $config = []) {
*
* ### Options:
*
* - `key` The key to set under the session's Message key
* - `key` The key to set under the session's Flash key
* - `element` The element used to render the flash message
* - `params` An array of variables to make available when using an element
*
Expand All @@ -78,7 +78,7 @@ public function set($message, array $options = []) {
$message = $message->getMessage();
}

$this->_session->write("Message.{$opts['key']}", [
$this->_session->write("Flash.{$opts['key']}", [
'message' => $message,
'key' => $opts['key'],
'element' => $opts['element'],
Expand Down
6 changes: 3 additions & 3 deletions src/View/Helper/FlashHelper.php
Expand Up @@ -58,14 +58,14 @@ class FlashHelper extends Helper {
* ]);
* }}}
*
* @param string $key The [Message.]key you are rendering in the view.
* @param string $key The [Flash.]key you are rendering in the view.
* @param array $options Additional options to use for the creation of this flash message.
* Supports the 'params', and 'element' keys that are used in the helper.
* @return string
*/
public function render($key = 'flash', array $options = []) {
$flash = $this->request->session()->read("Message.$key");
$this->request->session()->delete("Message.$key");
$flash = $this->request->session()->read("Flash.$key");
$this->request->session()->delete("Flash.$key");

if (!$flash) {
return '';
Expand Down
14 changes: 7 additions & 7 deletions tests/TestCase/Controller/Component/FlashComponentTest.php
Expand Up @@ -60,7 +60,7 @@ public function tearDown() {
* @covers \Cake\Controller\Component\FlashComponent::set
*/
public function testSet() {
$this->assertNull($this->Session->read('Message.flash'));
$this->assertNull($this->Session->read('Flash.flash'));

$this->Flash->set('This is a test message');
$expected = [
Expand All @@ -69,7 +69,7 @@ public function testSet() {
'element' => null,
'params' => []
];
$result = $this->Session->read('Message.flash');
$result = $this->Session->read('Flash.flash');
$this->assertEquals($expected, $result);

$this->Flash->set('This is a test message', ['element' => 'test', 'params' => ['foo' => 'bar']]);
Expand All @@ -79,7 +79,7 @@ public function testSet() {
'element' => 'test',
'params' => ['foo' => 'bar']
];
$result = $this->Session->read('Message.flash');
$result = $this->Session->read('Flash.flash');
$this->assertEquals($expected, $result);

$this->Flash->set('This is a test message', ['element' => 'MyPlugin.alert']);
Expand All @@ -89,7 +89,7 @@ public function testSet() {
'element' => 'MyPlugin.alert',
'params' => []
];
$result = $this->Session->read('Message.flash');
$result = $this->Session->read('Flash.flash');
$this->assertEquals($expected, $result);

$this->Flash->set('This is a test message', ['key' => 'foobar']);
Expand All @@ -99,7 +99,7 @@ public function testSet() {
'element' => null,
'params' => []
];
$result = $this->Session->read('Message.foobar');
$result = $this->Session->read('Flash.foobar');
$this->assertEquals($expected, $result);
}

Expand All @@ -110,7 +110,7 @@ public function testSet() {
* @covers \Cake\Controller\Component\FlashComponent::set
*/
public function testSetWithException() {
$this->assertNull($this->Session->read('Message.flash'));
$this->assertNull($this->Session->read('Flash.flash'));

$this->Flash->set(new \Exception('This is a test message'));
$expected = [
Expand All @@ -119,7 +119,7 @@ public function testSetWithException() {
'element' => null,
'params' => []
];
$result = $this->Session->read('Message.flash');
$result = $this->Session->read('Flash.flash');
$this->assertEquals($expected, $result);
}
}
2 changes: 1 addition & 1 deletion tests/TestCase/View/Helper/FlashHelperTest.php
Expand Up @@ -42,7 +42,7 @@ public function setUp() {
$this->Flash = new FlashHelper($this->View);

$session->write(array(
'Message' => array(
'Flash' => array(
'flash' => array(
'key' => 'flash',
'message' => 'This is a calling',
Expand Down

0 comments on commit 795eb4d

Please sign in to comment.