Skip to content

Commit

Permalink
Ticket 5041: have Auth::login() send Auth.afterIdentify event
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienbarre committed Nov 22, 2014
1 parent 21b5233 commit 43413f0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/Cake/Controller/Component/AuthComponent.php
Expand Up @@ -608,6 +608,9 @@ public function login($user = null) {
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();
}
Expand Down
28 changes: 28 additions & 0 deletions lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php
Expand Up @@ -266,6 +266,27 @@ public function redirect($url, $status = null, $exit = true) {

}

/**
* 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
*
Expand Down Expand Up @@ -404,6 +425,13 @@ public function testLogin() {
$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);

Expand Down

0 comments on commit 43413f0

Please sign in to comment.