2007-07-09 20:07:38 +00:00
|
|
|
<?php
|
|
|
|
/* SVN FILE: $Id$ */
|
|
|
|
/**
|
2007-07-09 20:45:29 +00:00
|
|
|
* Short description for file.
|
2007-07-09 20:07:38 +00:00
|
|
|
*
|
|
|
|
* 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.cases.libs.controller.components
|
|
|
|
* @since CakePHP(tm) v 1.2.0.5435
|
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
|
|
|
*/
|
|
|
|
uses('controller' . DS . 'components' . DS .'acl');
|
2007-08-21 14:29:39 +00:00
|
|
|
|
|
|
|
uses('controller'.DS.'components'.DS.'acl', 'model'.DS.'db_acl');
|
2007-07-09 20:07:38 +00:00
|
|
|
/**
|
|
|
|
* Short description for class.
|
|
|
|
*
|
|
|
|
* @package cake.tests
|
|
|
|
* @subpackage cake.tests.cases.libs.controller.components
|
|
|
|
*/
|
|
|
|
class AclComponentTest extends CakeTestCase {
|
2007-08-21 14:29:39 +00:00
|
|
|
|
|
|
|
var $fixtures = array('core.aro', 'core.aco', 'core.aros_aco', 'core.aco_action');
|
2007-07-09 20:07:38 +00:00
|
|
|
|
|
|
|
function skip() {
|
2007-10-14 01:09:21 +00:00
|
|
|
$this->skipif (false, 'AclComponentTest almost implemented');
|
2007-08-21 14:29:39 +00:00
|
|
|
}
|
|
|
|
|
2007-10-14 01:09:21 +00:00
|
|
|
function startTest() {
|
|
|
|
Configure::write('Acl.classname', 'DB_ACL');
|
|
|
|
Configure::write('Acl.database', 'test_suite');
|
2007-08-21 14:29:39 +00:00
|
|
|
$this->Acl =& new AclComponent();
|
2007-10-14 01:09:21 +00:00
|
|
|
$this->__testInitDbAcl();
|
2007-08-21 14:29:39 +00:00
|
|
|
}
|
|
|
|
|
2007-10-14 01:09:21 +00:00
|
|
|
function __testInitDbAcl() {
|
2007-08-21 14:29:39 +00:00
|
|
|
|
|
|
|
$this->Acl->Aro->id = null;
|
|
|
|
$this->Acl->Aro->create(array('alias'=>'Roles'));
|
|
|
|
$result = $this->Acl->Aro->save();
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$this->Acl->Aro->create(array('alias'=>'Admin'));
|
|
|
|
$result = $this->Acl->Aro->save();
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$this->Acl->Aro->create(array('model'=>'AuthUser', 'foreign_key'=>'1', 'alias'=> 'mariano'));
|
|
|
|
$result = $this->Acl->Aro->save();
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$this->Acl->Aro->setParent(1, 2);
|
|
|
|
$this->Acl->Aro->setParent(2, 3);
|
|
|
|
|
|
|
|
$this->Acl->Aco->create(array('alias'=>'Root'));
|
|
|
|
$result = $this->Acl->Aco->save();
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$this->Acl->Aco->create(array('alias'=>'AuthTest'));
|
|
|
|
$result = $this->Acl->Aco->save();
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$this->Acl->Aco->setParent(1, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testDbAclAllow() {
|
|
|
|
|
|
|
|
$result = $this->Acl->allow('Roles/Admin', 'Root');
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$result = $this->Acl->allow('Roles/Admin', 'Root/AuthTest');
|
|
|
|
$this->assertTrue($result);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testDbAclCheck() {
|
|
|
|
|
|
|
|
$aro = null;
|
|
|
|
$aco = null;
|
|
|
|
$action = "*";
|
|
|
|
|
|
|
|
$result = $this->Acl->check('Roles/Admin', 'Root', $action);
|
|
|
|
$this->assertFalse($result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function testDbAclDeny() {
|
2007-10-14 01:09:21 +00:00
|
|
|
|
|
|
|
$action = "*";
|
2007-08-21 14:29:39 +00:00
|
|
|
|
|
|
|
$result = $this->Acl->deny('Roles/Admin', 'Root/AuthTest', $action);
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$result = $this->Acl->check('Roles/Admin', 'Root/AuthTest', $action);
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testDbAclInherit() {
|
2007-10-14 01:09:21 +00:00
|
|
|
|
|
|
|
$action = "*";
|
2007-08-21 14:29:39 +00:00
|
|
|
|
|
|
|
$result = $this->Acl->inherit('Roles/Admin', 'Root/AuthTest', $action);
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
}
|
|
|
|
function testDbAclGrant() {
|
|
|
|
|
2007-10-14 01:09:21 +00:00
|
|
|
$aro = 'Roles/Admin';
|
|
|
|
$aco = 'Root/AuthTest';
|
2007-08-21 14:29:39 +00:00
|
|
|
$action = "*";
|
|
|
|
|
|
|
|
$result = $this->Acl->grant($aro, $aco, $action);
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
}
|
|
|
|
function testDbAclRevoke() {
|
|
|
|
|
2007-10-14 01:09:21 +00:00
|
|
|
$aro = 'Roles/Admin';
|
|
|
|
$aco = 'Root/AuthTest';
|
2007-08-21 14:29:39 +00:00
|
|
|
$action = "*";
|
|
|
|
|
|
|
|
$result = $this->Acl->revoke($aro, $aco, $action);
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-10-14 01:09:21 +00:00
|
|
|
function endTest() {
|
2007-08-21 14:29:39 +00:00
|
|
|
unset($this->Acl);
|
2007-07-09 20:07:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|