mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Ticket 5041: have Auth::login() send Auth.afterIdentify event
This commit is contained in:
parent
07c91d4b3e
commit
0cdb93b265
2 changed files with 31 additions and 0 deletions
|
@ -608,6 +608,9 @@ class AuthComponent extends Component {
|
|||
if ($user) {
|
||||
$this->Session->renew();
|
||||
$this->Session->write(self::$sessionKey, $user);
|
||||
App::uses('CakeEvent', 'Event');
|
||||
$event = new CakeEvent('Auth.afterIdentify', $this, array('user' => $user));
|
||||
$this->_Collection->getController()->getEventManager()->dispatch($event);
|
||||
}
|
||||
return (bool)$this->user();
|
||||
}
|
||||
|
|
|
@ -266,6 +266,27 @@ class AjaxAuthController extends Controller {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock class used to test event dispatching
|
||||
*
|
||||
* @package Cake.Test.Case.Event
|
||||
*/
|
||||
class CakeEventTestListener {
|
||||
|
||||
public $callStack = array();
|
||||
|
||||
/**
|
||||
* Test function to be used in event dispatching
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function listenerFunction() {
|
||||
$this->callStack[] = __FUNCTION__;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* AuthComponentTest class
|
||||
*
|
||||
|
@ -404,6 +425,13 @@ class AuthComponentTest extends CakeTestCase {
|
|||
$this->Auth->Session->expects($this->once())
|
||||
->method('renew');
|
||||
|
||||
$manager = $this->Controller->getEventManager();
|
||||
$listener = $this->getMock('CakeEventTestListener');
|
||||
$manager->attach(array($listener, 'listenerFunction'), 'Auth.afterIdentify');
|
||||
App::uses('CakeEvent', 'Event');
|
||||
$event = new CakeEvent('Auth.afterIdentify', $this->Auth, array('user' => $user));
|
||||
$listener->expects($this->once())->method('listenerFunction')->with($event);
|
||||
|
||||
$result = $this->Auth->login();
|
||||
$this->assertTrue($result);
|
||||
|
||||
|
|
Loading…
Reference in a new issue