From 25558fbd33eb0b13bc49fc5bb823870b6bc802bb Mon Sep 17 00:00:00 2001 From: gwoo Date: Sun, 8 Jul 2007 00:49:36 +0000 Subject: [PATCH] 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 --- .../libs/controller/components/auth.test.php | 36 ++++++------- cake/tests/fixtures/auth_user_fixture.php | 52 +++++++++++++++++++ 2 files changed, 70 insertions(+), 18 deletions(-) create mode 100644 cake/tests/fixtures/auth_user_fixture.php diff --git a/cake/tests/cases/libs/controller/components/auth.test.php b/cake/tests/cases/libs/controller/components/auth.test.php index efe4fb9f5..a59563697 100644 --- a/cake/tests/cases/libs/controller/components/auth.test.php +++ b/cake/tests/cases/libs/controller/components/auth.test.php @@ -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); } } ?> \ No newline at end of file diff --git a/cake/tests/fixtures/auth_user_fixture.php b/cake/tests/fixtures/auth_user_fixture.php new file mode 100644 index 000000000..b7cb25158 --- /dev/null +++ b/cake/tests/fixtures/auth_user_fixture.php @@ -0,0 +1,52 @@ + + * 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'), + ); +} + +?> \ No newline at end of file