Skip to content

Commit

Permalink
Fix an issue where custom Auth config would cause errors.
Browse files Browse the repository at this point in the history
When the params key is omitted from the AuthComponent config a fatal
error would happen.
  • Loading branch information
markstory committed May 27, 2014
1 parent 00c94bd commit b01ef90
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Controller/Component/AuthComponent.php
Expand Up @@ -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'));
}

}
11 changes: 10 additions & 1 deletion tests/TestCase/Controller/Component/AuthComponentTest.php
Expand Up @@ -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');
}

/**
Expand Down

0 comments on commit b01ef90

Please sign in to comment.