request = new CakeRequest('posts/index', false); Router::setRequestInfo($this->request); $this->Collection = new ComponentCollection(); $this->Collection->load('Cookie'); $this->Collection->load('Session'); $this->auth = new CookieAuthenticate($this->Collection, array( 'fields' => array('username' => 'user', 'password' => 'password'), 'userModel' => 'MultiUser', )); $password = Security::hash('password', null, true); $User = ClassRegistry::init('MultiUser'); $User->updateAll(array('password' => $User->getDataSource()->value($password))); $this->response = $this->getMock('CakeResponse'); } /** * tearDown * * @return void */ public function tearDown() { parent::tearDown(); $this->Collection->Cookie->destroy(); } /** * test authenticate email or username * * @return void */ public function testAuthenticate() { $expected = array( 'id' => 1, 'user' => 'mariano', 'email' => 'mariano@example.com', 'token' => '12345', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31' ); $result = $this->auth->authenticate($this->request, $this->response); $this->assertFalse($result); $this->Collection->Cookie->write('MultiUser', array('user' => 'mariano', 'password' => 'password')); $result = $this->auth->authenticate($this->request, $this->response); $this->assertEquals($expected, $result); } }