From e34fdde91858ed9ed0fc0c02c71fa83f060bb875 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 4 Jan 2011 23:33:09 -0500 Subject: [PATCH] Adding a test for logging users in using request data. --- .../libs/controller/components/auth.test.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/cake/tests/cases/libs/controller/components/auth.test.php b/cake/tests/cases/libs/controller/components/auth.test.php index 97115e5b6..d22b1ea92 100644 --- a/cake/tests/cases/libs/controller/components/auth.test.php +++ b/cake/tests/cases/libs/controller/components/auth.test.php @@ -18,6 +18,7 @@ */ App::import('Core', 'Controller'); App::import('Component', array('Auth', 'Acl')); +App::import('Component', 'auth/form_authenticate'); App::import('Model', 'DbAcl'); App::import('Core', 'Xml'); @@ -1487,6 +1488,28 @@ class AuthTest extends CakeTestCase { $this->Controller->Auth->mapActions(array('create' => array('my_action'))); } +/** + * test logging in with a request. + * + * @return void + */ + function testLoginWithRequestData() { + $this->getMock('FormAuthenticate', array(), array(), 'RequestLoginMockAuthenticate', false); + $request = new CakeRequest('users/login', false); + $user = array('username' => 'mark', 'role' => 'admin'); + + $this->Controller->Auth->request = $request; + $this->Controller->Auth->authenticate = array('RequestLoginMock'); + $mock = $this->Controller->Auth->loadAuthenticateObjects(); + $mock[0]->expects($this->once()) + ->method('authenticate') + ->with($request) + ->will($this->returnValue($user)); + + $this->assertTrue($this->Controller->Auth->login()); + $this->assertEquals($user['username'], $this->Controller->Auth->user('username')); + } + /** * test login() with user data *