Skip to content

Commit

Permalink
Expanding test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Feb 4, 2011
1 parent 060360c commit 59dac22
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions cake/tests/cases/libs/controller/components/auth.test.php
Expand Up @@ -500,13 +500,13 @@ function testIsAuthorizedDelegation() {
$this->getMock('BaseAuthorize', array('authorize'), array(), 'AuthMockTwoAuthorize', false);
$this->getMock('BaseAuthorize', array('authorize'), array(), 'AuthMockThreeAuthorize', false);

$this->Controller->Auth->authorize = array(
$this->Auth->authorize = array(
'AuthMockOne',
'AuthMockTwo',
'AuthMockThree'
);
$mocks = $this->Controller->Auth->constructAuthorize();
$request = $this->Controller->request;
$mocks = $this->Auth->constructAuthorize();
$request = $this->Auth->request;

$this->assertEquals(3, count($mocks));
$mocks[0]->expects($this->once())
Expand All @@ -522,7 +522,29 @@ function testIsAuthorizedDelegation() {
$mocks[2]->expects($this->never())
->method('authorize');

$this->assertTrue($this->Controller->Auth->isAuthorized(array('User'), $request));
$this->assertTrue($this->Auth->isAuthorized(array('User'), $request));
}

/**
* test that isAuthorized will use the session user if none is given.
*
* @return void
*/
function testIsAuthorizedUsingUserInSession() {
$this->getMock('BaseAuthorize', array('authorize'), array(), 'AuthMockFourAuthorize', false);
$this->Auth->authorize = array('AuthMockFour');

$user = array('user' => 'mark');
$this->Auth->Session->write('Auth.User', $user);
$mocks = $this->Auth->constructAuthorize();
$request = $this->Controller->request;

$mocks[0]->expects($this->once())
->method('authorize')
->with($user, $request)
->will($this->returnValue(true));

$this->assertTrue($this->Auth->isAuthorized(null, $request));
}

/**
Expand Down Expand Up @@ -1120,4 +1142,16 @@ function testRedirectSessionReadEqualToLoginAction() {
$this->assertEquals('/users/home', $result);
$this->assertFalse($this->Auth->Session->check('Auth.redirect'));
}

/**
* test password hashing
*
* @return void
*/
function testPassword() {
$result = $this->Auth->password('password');
$expected = Security::hash('password', null, true);
$this->assertEquals($expected, $result);

}
}

0 comments on commit 59dac22

Please sign in to comment.