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

Changed 'Flash.' to 'Message.' and also provided backwards compatibility
in FlashHelper->render
This commit is contained in:
Highstrike 2015-06-24 14:06:35 +03:00
parent 26b3713bd6
commit 58983f717a
4 changed files with 27 additions and 18 deletions

View file

@ -84,7 +84,7 @@ class FlashComponent extends Component {
$options['element'] = 'Flash/' . $element;
}
CakeSession::write('Flash.' . $options['key'], array(
CakeSession::write('Message.' . $options['key'], array(
'message' => $message,
'key' => $options['key'],
'element' => $options['element'],

View file

@ -55,7 +55,7 @@ class FlashComponentTest extends CakeTestCase {
* @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 @@ class FlashComponentTest extends CakeTestCase {
'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 @@ class FlashComponentTest extends CakeTestCase {
'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 @@ class FlashComponentTest extends CakeTestCase {
'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 @@ class FlashComponentTest extends CakeTestCase {
'element' => 'Flash/default',
'params' => array()
);
$result = CakeSession::read('Flash.foobar');
$result = CakeSession::read('Message.foobar');
$this->assertEquals($expected, $result);
}
@ -107,7 +107,7 @@ class FlashComponentTest extends CakeTestCase {
* @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 @@ class FlashComponentTest extends CakeTestCase {
'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 @@ class FlashComponentTest extends CakeTestCase {
* @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 @@ class FlashComponentTest extends CakeTestCase {
'element' => 'Flash/test',
'params' => array()
);
$result = CakeSession::read('Flash.flash');
$result = CakeSession::read('Message.flash');
$this->assertEquals($expected, $result);
}
@ -146,7 +146,7 @@ class FlashComponentTest extends CakeTestCase {
* @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 @@ class FlashComponentTest extends CakeTestCase {
'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 @@ class FlashComponentTest extends CakeTestCase {
'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.');
}
}

View file

@ -120,7 +120,7 @@ class FlashHelperTest extends CakeTestCase {
* @expectedException UnexpectedValueException
*/
public function testFlashThrowsException() {
CakeSession::write('Flash.foo', 'bar');
CakeSession::write('Message.foo', 'bar');
$this->Flash->render('foo');
}

View file

@ -61,7 +61,7 @@ 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
@ -69,11 +69,11 @@ class FlashHelper extends AppHelper {
* @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 @@ class FlashHelper extends AppHelper {
}
$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);
}