Ticket 5041: have Auth::login() send Auth.afterIdentify event

This commit is contained in:
Sebastien Barre 2014-11-05 12:34:25 -05:00
parent 07c91d4b3e
commit 0cdb93b265
2 changed files with 31 additions and 0 deletions

View file

@ -608,6 +608,9 @@ class AuthComponent extends Component {
if ($user) { if ($user) {
$this->Session->renew(); $this->Session->renew();
$this->Session->write(self::$sessionKey, $user); $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(); return (bool)$this->user();
} }

View file

@ -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 * AuthComponentTest class
* *
@ -404,6 +425,13 @@ class AuthComponentTest extends CakeTestCase {
$this->Auth->Session->expects($this->once()) $this->Auth->Session->expects($this->once())
->method('renew'); ->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(); $result = $this->Auth->login();
$this->assertTrue($result); $this->assertTrue($result);