Skip to content

Commit

Permalink
Updating SessionComponent::setFlash
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed May 18, 2014
1 parent 4c3f85b commit 346c341
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Controller/Component/SessionComponent.php
Expand Up @@ -122,7 +122,7 @@ public function check($name) {
* @link http://book.cakephp.org/2.0/en/core-libraries/components/sessions.html#creating-notification-messages
*/
public function setFlash($message, $element = 'default', array $params = array(), $key = 'flash') {
$this->write('Message.' . $key, compact('message', 'element', 'params'));
$this->_session->flash($message, 'info', $params + compact('element', 'key'));
}

/**
Expand Down
17 changes: 5 additions & 12 deletions tests/TestCase/Controller/Component/SessionComponentTest.php
Expand Up @@ -171,18 +171,11 @@ public function testSessionFlash() {
$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'));

$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'));

$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'));

$Session->delete('Message');
$this->assertEquals(array(
'message' => 'This is a test message',
'params' => array('element' => 'default'),
'type' => 'info'
), $Session->read('Message.flash'));
}

/**
Expand Down

0 comments on commit 346c341

Please sign in to comment.