Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changed SessionHelper::flash to return message instead of echoing it

  • Loading branch information...
commit 2cb0c3acb3563863ad85dac4ee565b838724b0d7 1 parent d93c94f
Christian Winther jippi authored
8 cake/libs/view/helpers/session.php
View
@@ -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);
@@ -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;
}
/**
22 cake/tests/cases/libs/view/helpers/session.test.php
View
@@ -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(
@@ -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'));
Please sign in to comment.
Something went wrong with that request. Please try again.