Skip to content

Commit

Permalink
Changed SessionHelper::flash to return message instead of echoing it
Browse files Browse the repository at this point in the history
  • Loading branch information
jippi committed Nov 16, 2009
1 parent d93c94f commit 2cb0c3a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 22 deletions.
8 changes: 4 additions & 4 deletions cake/libs/view/helpers/session.php
Expand Up @@ -125,10 +125,12 @@ function error() {
* Will default to flash if no param is passed
*
* @param string $key The [Message.]key you are rendering in the view.
* @return string Will echo the value if $key is set, or false if not set.
* @return boolean|string Will return the value if $key is set, or false if not set.
* @access public
*/
function flash($key = 'flash') {
$out = false;

if ($this->__active === true && $this->__start()) {
if (parent::check('Message.' . $key)) {
$flash = parent::read('Message.' . $key);
Expand All @@ -148,12 +150,10 @@ function flash($key = 'flash') {
$tmpVars['message'] = $flash['message'];
$out = $view->element($flash['element'], $tmpVars);
}
echo($out);
parent::delete('Message.' . $key);
return true;
}
}
return false;
return $out;
}

/**
Expand Down
22 changes: 4 additions & 18 deletions cake/tests/cases/libs/view/helpers/session.test.php
Expand Up @@ -148,19 +148,13 @@ function testWrite() {
* @return void
*/
function testFlash() {
ob_start();
$this->Session->flash();
$result = ob_get_contents();
ob_clean();

$result = $this->Session->flash('flash', true);
$expected = '<div id="flashMessage" class="message">This is a calling</div>';
$this->assertEqual($result, $expected);
$this->assertFalse($this->Session->check('Message.flash'));

$expected = '<div id="classyMessage" class="positive">Recorded</div>';
ob_start();
$this->Session->flash('classy');
$result = ob_get_clean();
$result = $this->Session->flash('classy', true);
$this->assertEqual($result, $expected);

App::build(array(
Expand All @@ -169,21 +163,13 @@ function testFlash() {
$controller = new Controller();
$this->Session->view = new View($controller);

ob_start();
$this->Session->flash('notification');
$result = ob_get_contents();
ob_clean();

$result = $this->Session->flash('notification', true);
$result = str_replace("\r\n", "\n", $result);
$expected = "<div id=\"notificationLayout\">\n\t<h1>Alert!</h1>\n\t<h3>Notice!</h3>\n\t<p>This is a test of the emergency broadcasting system</p>\n</div>";
$this->assertEqual($result, $expected);
$this->assertFalse($this->Session->check('Message.notification'));

ob_start();
$this->Session->flash('bare');
$result = ob_get_contents();
ob_clean();

$result = $this->Session->flash('bare');
$expected = 'Bare message';
$this->assertEqual($result, $expected);
$this->assertFalse($this->Session->check('Message.bare'));
Expand Down

0 comments on commit 2cb0c3a

Please sign in to comment.