diff --git a/src/Controller/Component/AuthComponent.php b/src/Controller/Component/AuthComponent.php index fc747169e31..32ab836fbab 100644 --- a/src/Controller/Component/AuthComponent.php +++ b/src/Controller/Component/AuthComponent.php @@ -775,7 +775,11 @@ public function flash($message, $type = 'error') { } $flashConfig = $this->_config['flash']; $key = $flashConfig['key']; - $this->session->flash($message, 'error', $flashConfig['params'] + compact('key')); + $params = []; + if (isset($flashConfig['params'])) { + $params = $flashConfig['params']; + } + $this->session->flash($message, 'error', $params + compact('key')); } } diff --git a/tests/TestCase/Controller/Component/AuthComponentTest.php b/tests/TestCase/Controller/Component/AuthComponentTest.php index 59e087f9867..5974a6801f4 100644 --- a/tests/TestCase/Controller/Component/AuthComponentTest.php +++ b/tests/TestCase/Controller/Component/AuthComponentTest.php @@ -1141,15 +1141,24 @@ public function testLoginWithUserData() { */ public function testFlashSettings() { $this->Auth->session = $this->getMock('Cake\Network\Session'); - $this->Auth->session->expects($this->once()) + $this->Auth->session->expects($this->at(0)) ->method('flash') ->with('Auth failure', 'error', array('key' => 'auth-key', 'element' => 'custom')); + $this->Auth->session->expects($this->at(1)) + ->method('flash') + ->with('Auth failure', 'error', array('key' => 'auth-key')); + $this->Auth->config('flash', [ 'params' => array('element' => 'custom'), 'key' => 'auth-key' ]); $this->Auth->flash('Auth failure'); + + $this->Auth->config('flash', [ + 'key' => 'auth-key' + ], false); + $this->Auth->flash('Auth failure'); } /**