Skip to content
Permalink
Browse files

2.7.0-RC Auth doesn't use the new Flash component

Changed 'Flash.' to 'Message.' and also provided backwards compatibility
in FlashHelper->render
  • Loading branch information...
highstrike committed Jun 24, 2015
1 parent 26b3713 commit 58983f717aa811f5fef81a67b43cbae58b1a1167
@@ -84,7 +84,7 @@ public function set($message, $options = array()) {
$options['element'] = 'Flash/' . $element;
}
CakeSession::write('Flash.' . $options['key'], array(
CakeSession::write('Message.' . $options['key'], array(
'message' => $message,
'key' => $options['key'],
'element' => $options['element'],
@@ -55,7 +55,7 @@ public function tearDown() {
* @return void
*/
public function testSet() {
$this->assertNull(CakeSession::read('Flash.flash'));
$this->assertNull(CakeSession::read('Message.flash'));
$this->Flash->set('This is a test message');
$expected = array(
@@ -64,7 +64,7 @@ public function testSet() {
'element' => 'Flash/default',
'params' => array()
);
$result = CakeSession::read('Flash.flash');
$result = CakeSession::read('Message.flash');
$this->assertEquals($expected, $result);
$this->Flash->set('This is a test message', array(
@@ -77,7 +77,7 @@ public function testSet() {
'element' => 'Flash/test',
'params' => array('foo' => 'bar')
);
$result = CakeSession::read('Flash.flash');
$result = CakeSession::read('Message.flash');
$this->assertEquals($expected, $result);
$this->Flash->set('This is a test message', array('element' => 'MyPlugin.alert'));
@@ -87,7 +87,7 @@ public function testSet() {
'element' => 'MyPlugin.Flash/alert',
'params' => array()
);
$result = CakeSession::read('Flash.flash');
$result = CakeSession::read('Message.flash');
$this->assertEquals($expected, $result);
$this->Flash->set('This is a test message', array('key' => 'foobar'));
@@ -97,7 +97,7 @@ public function testSet() {
'element' => 'Flash/default',
'params' => array()
);
$result = CakeSession::read('Flash.foobar');
$result = CakeSession::read('Message.foobar');
$this->assertEquals($expected, $result);
}
@@ -107,7 +107,7 @@ public function testSet() {
* @return void
*/
public function testSetWithException() {
$this->assertNull(CakeSession::read('Flash.flash'));
$this->assertNull(CakeSession::read('Message.flash'));
$this->Flash->set(new Exception('This is a test message', 404));
$expected = array(
@@ -116,7 +116,7 @@ public function testSetWithException() {
'element' => 'Flash/default',
'params' => array('code' => 404)
);
$result = CakeSession::read('Flash.flash');
$result = CakeSession::read('Message.flash');
$this->assertEquals($expected, $result);
}
@@ -126,7 +126,7 @@ public function testSetWithException() {
* @return void
*/
public function testSetWithComponentConfiguration() {
$this->assertNull(CakeSession::read('Flash.flash'));
$this->assertNull(CakeSession::read('Message.flash'));
$FlashWithSettings = $this->Components->load('Flash', array('element' => 'test'));
$FlashWithSettings->set('This is a test message');
@@ -136,7 +136,7 @@ public function testSetWithComponentConfiguration() {
'element' => 'Flash/test',
'params' => array()
);
$result = CakeSession::read('Flash.flash');
$result = CakeSession::read('Message.flash');
$this->assertEquals($expected, $result);
}
@@ -146,7 +146,7 @@ public function testSetWithComponentConfiguration() {
* @return void
*/
public function testCall() {
$this->assertNull(CakeSession::read('Flash.flash'));
$this->assertNull(CakeSession::read('Message.flash'));
$this->Flash->success('It worked');
$expected = array(
@@ -155,7 +155,7 @@ public function testCall() {
'element' => 'Flash/success',
'params' => array()
);
$result = CakeSession::read('Flash.flash');
$result = CakeSession::read('Message.flash');
$this->assertEquals($expected, $result);
$this->Flash->error('It did not work', array('element' => 'error_thing'));
@@ -165,7 +165,7 @@ public function testCall() {
'element' => 'Flash/error',
'params' => array()
);
$result = CakeSession::read('Flash.flash');
$result = CakeSession::read('Message.flash');
$this->assertEquals($expected, $result, 'Element is ignored in magic call.');
}
}
@@ -120,7 +120,7 @@ public function testFlash() {
* @expectedException UnexpectedValueException
*/
public function testFlashThrowsException() {
CakeSession::write('Flash.foo', 'bar');
CakeSession::write('Message.foo', 'bar');
$this->Flash->render('foo');
}
@@ -61,19 +61,19 @@ class FlashHelper extends AppHelper {
* ));
* ```
*
* @param string $key The [Flash.]key you are rendering in the view.
* @param string $key The [Message.]key you are rendering in the view.
* @param array $options Additional options to use for the creation of this flash message.
* Supports the 'params', and 'element' keys that are used in the helper.
* @return string|null Rendered flash message or null if flash key does not exist
* in session.
* @throws UnexpectedValueException If value for flash settings key is not an array.
*/
public function render($key = 'flash', $options = array()) {
if (!CakeSession::check("Flash.$key")) {
if (!CakeSession::check("Message.$key")) {
return;
}
$flash = CakeSession::read("Flash.$key");
$flash = CakeSession::read("Message.$key");
if (!is_array($flash)) {
throw new UnexpectedValueException(sprintf(
@@ -83,7 +83,16 @@ public function render($key = 'flash', $options = array()) {
}
$flash = $options + $flash;
CakeSession::delete("Flash.$key");
CakeSession::delete("Message.$key");
// backwards compatibility with Session->setFlash
if($flash['element'] === 'default') {
$class = 'message';
if (!empty($flash['params']['class'])) {
$class = $flash['params']['class'];
}
return '<div id="' . $key . 'Message" class="' . $class . '">' . $flash['message'] . '</div>';
}
return $this->_View->element($flash['element'], $flash);
}

0 comments on commit 58983f7

Please sign in to comment.
You can’t perform that action at this time.