diff --git a/cake/libs/view/helpers/session.php b/cake/libs/view/helpers/session.php index fc30e676e..82c7184b4 100644 --- a/cake/libs/view/helpers/session.php +++ b/cake/libs/view/helpers/session.php @@ -125,10 +125,12 @@ class SessionHelper extends CakeSession { * 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); @@ -148,12 +150,10 @@ class SessionHelper extends CakeSession { $tmpVars['message'] = $flash['message']; $out = $view->element($flash['element'], $tmpVars); } - echo($out); parent::delete('Message.' . $key); - return true; } } - return false; + return $out; } /** diff --git a/cake/tests/cases/libs/view/helpers/session.test.php b/cake/tests/cases/libs/view/helpers/session.test.php index eec5805c6..9e5f0498e 100644 --- a/cake/tests/cases/libs/view/helpers/session.test.php +++ b/cake/tests/cases/libs/view/helpers/session.test.php @@ -148,19 +148,13 @@ class SessionHelperTest extends CakeTestCase { * @return void */ function testFlash() { - ob_start(); - $this->Session->flash(); - $result = ob_get_contents(); - ob_clean(); - + $result = $this->Session->flash('flash', true); $expected = '
This is a calling
'; $this->assertEqual($result, $expected); $this->assertFalse($this->Session->check('Message.flash')); $expected = '
Recorded
'; - ob_start(); - $this->Session->flash('classy'); - $result = ob_get_clean(); + $result = $this->Session->flash('classy', true); $this->assertEqual($result, $expected); App::build(array( @@ -169,21 +163,13 @@ class SessionHelperTest extends CakeTestCase { $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 = "
\n\t

Alert!

\n\t

Notice!

\n\t

This is a test of the emergency broadcasting system

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