mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Changed SessionHelper::flash to return message instead of echoing it
This commit is contained in:
parent
d93c94f702
commit
2cb0c3acb3
2 changed files with 8 additions and 22 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 = '<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 @@ 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 = "<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'));
|
||||
|
|
Loading…
Reference in a new issue