diff --git a/lib/Cake/Controller/Component/AuthComponent.php b/lib/Cake/Controller/Component/AuthComponent.php index 165dee00c..bde9c206f 100644 --- a/lib/Cake/Controller/Component/AuthComponent.php +++ b/lib/Cake/Controller/Component/AuthComponent.php @@ -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(); } diff --git a/lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php b/lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php index 29266cf1f..260b0ec3c 100644 --- a/lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php +++ b/lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php @@ -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);