From 94d9bcd674bfc59ea4c3b16a6b05a42b849e6a51 Mon Sep 17 00:00:00 2001 From: chinpei215 Date: Thu, 5 Jan 2017 18:47:47 +0900 Subject: [PATCH] Fix FlashHelper::render() cannot render `default` messages Fixes #9910 --- .../Test/Case/View/Helper/FlashHelperTest.php | 15 +++++++++++++++ lib/Cake/View/Helper/FlashHelper.php | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/lib/Cake/Test/Case/View/Helper/FlashHelperTest.php b/lib/Cake/Test/Case/View/Helper/FlashHelperTest.php index b3d1d7440..21dd987f2 100644 --- a/lib/Cake/Test/Case/View/Helper/FlashHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FlashHelperTest.php @@ -76,6 +76,12 @@ class FlashHelperTest extends CakeTestCase { 'message' => 'Recorded', 'element' => 'flash_classy', 'params' => array() + ), + 'default' => array( + 'key' => 'default', + 'message' => 'Default', + 'element' => 'default', + 'params' => array() ) ) )); @@ -154,4 +160,13 @@ class FlashHelperTest extends CakeTestCase { $expected = 'this is the plugin element'; $this->assertContains($expected, $result); } + +/** + * Test that the default element fallbacks to the Flash/default element. + */ + public function testFlashFallback() { + $result = $this->Flash->render('default'); + $expected = '
Default
'; + $this->assertContains($expected, $result); + } } diff --git a/lib/Cake/View/Helper/FlashHelper.php b/lib/Cake/View/Helper/FlashHelper.php index ec26631fa..23582353c 100644 --- a/lib/Cake/View/Helper/FlashHelper.php +++ b/lib/Cake/View/Helper/FlashHelper.php @@ -86,6 +86,10 @@ class FlashHelper extends AppHelper { CakeSession::delete("Message.$key"); $flash['key'] = $key; + if ($flash['element'] === 'default') { + $flash['element'] = 'Flash/default'; + } + return $this->_View->element($flash['element'], $flash); } }