updating Auth test with AuthUser and fixture

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5392 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2007-07-08 00:49:36 +00:00
parent e0d8449b8a
commit 25558fbd33
2 changed files with 70 additions and 18 deletions

View file

@ -28,9 +28,9 @@
*/
uses('controller' . DS . 'components' . DS .'auth');
class User extends CakeTestModel {
class AuthUser extends CakeTestModel {
var $name = 'User';
function parentNode() {
return true;
}
@ -42,9 +42,9 @@ class User extends CakeTestModel {
class AuthTestController extends Controller {
var $name = 'AuthTest';
var $uses = array('User');
var $uses = array('AuthUser');
var $components = array('Auth', 'Acl');
function __construct() {
$this->params = Router::parse('/auth_test');
Router::setRequestInfo(array($this->params, array('base' => '/', 'here' => '/', 'webroot' => '/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array(), 'webservices' => null)));
@ -65,11 +65,11 @@ class AuthTestController extends Controller {
function add() {
}
function redirect() {
return true;
}
function isAuthorized() {
return true;
}
@ -77,8 +77,8 @@ class AuthTestController extends Controller {
class AuthTest extends CakeTestCase {
var $name = 'Auth';
var $fixtures = array('core.user', 'core.aco', 'core.aro', 'core.aros_aco');
var $fixtures = array('core.auth_user', 'core.aco', 'core.aro', 'core.aros_aco');
function setUp() {
$this->Controller =& new AuthTestController();
restore_error_handler();
@ -86,9 +86,9 @@ class AuthTest extends CakeTestCase {
set_error_handler('simpleTestErrorHandler');
ClassRegistry::addObject('view', new View($this->Controller));
}
function testIt(){
$this->User =& new User();
$this->User =& new AuthUser();
$user = $this->User->find();
$this->Controller->Session->write('Auth', $user);
$this->Auth->authorize = 'controller';
@ -98,21 +98,21 @@ class AuthTest extends CakeTestCase {
function testNoAuth() {
$this->assertFalse($this->Controller->Auth->isAuthorized($this->Controller));
}
function testUserData() {
$this->User =& new User();
$this->User =& new AuthUser();
foreach ($this->User->findAll() as $key => $result) {
$result['User']['password'] = Security::hash(CAKE_SESSION_STRING . $result['User']['password']);
$this->User->save($result, false);
$this->User->save($result, false);
}
$authTestUser = $this->User->read();
$data['User']['username'] = $authTestUser['User']['username'];
$data['User']['password'] = $authTestUser['User']['password'];
$this->Auth->authorize = 'Acl';
$this->Controller->Auth->startup($this->Controller);
$this->Controller->Auth->params['controller'] = 'AuthTest';
$this->Controller->Auth->params['action'] = 'add';
$this->Controller->Auth->Acl->Aro->create(1, null, 'chartjes');
@ -122,9 +122,9 @@ class AuthTest extends CakeTestCase {
$this->Controller->Auth->Acl->allow('Users', 'Home/home');
$this->assertTrue($this->Controller->Auth->isAuthorized($this->Controller, 'controller', 'User'));
}
function tearDown() {
unset($this->Controller, $this->User);
unset($this->Controller, $this->AuthUser);
}
}
?>

View file

@ -0,0 +1,52 @@
<?php
/* SVN FILE: $Id$ */
/**
* Short description for file.
*
* Long description for file
*
* PHP versions 4 and 5
*
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
* Copyright 2005-2007, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
* @package cake.tests
* @subpackage cake.tests.fixtures
* @since CakePHP(tm) v 1.2.0.4667
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
/**
* Short description for class.
*
* @package cake.tests
* @subpackage cake.tests.fixtures
*/
class AuthUserFixture extends CakeTestFixture {
var $name = 'AuthUser';
var $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'user' => array('type' => 'string', 'null' => false),
'password' => array('type' => 'string', 'null' => false),
'created' => 'datetime',
'updated' => 'datetime'
);
var $records = array(
array('id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'),
array('id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'),
array('id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'),
array('id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'),
);
}
?>