Adding ACL component test coverage and whitespace fixes

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6451 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2008-02-11 02:27:16 +00:00
parent 14523dc8c4
commit 96d2b4b738
2 changed files with 67 additions and 31 deletions

View file

@ -94,39 +94,46 @@ class AclNode extends AppModel {
$start = $path[0];
unset($path[0]);
$queryData = array('conditions' => array(
$db->name("{$type}.lft") . ' <= ' . $db->name("{$type}0.lft"),
$db->name("{$type}.rght") . ' >= ' . $db->name("{$type}0.rght")),
'fields' => array('id', 'parent_id', 'model', 'foreign_key', 'alias'),
'joins' => array(array('table' => $db->name($prefix . $table),
'alias' => "{$type}0",
'type' => 'LEFT',
'conditions' => array("{$type}0.alias" => $start))),
'order' => $db->name("{$type}.lft") . ' DESC');
$queryData = array(
'conditions' => array(
$db->name("{$type}.lft") . ' <= ' . $db->name("{$type}0.lft"),
$db->name("{$type}.rght") . ' >= ' . $db->name("{$type}0.rght")),
'fields' => array('id', 'parent_id', 'model', 'foreign_key', 'alias'),
'joins' => array(array(
'table' => $db->name($prefix . $table),
'alias' => "{$type}0",
'type' => 'LEFT',
'conditions' => array("{$type}0.alias" => $start)
)),
'order' => $db->name("{$type}.lft") . ' DESC'
);
foreach ($path as $i => $alias) {
$j = $i - 1;
array_push($queryData['joins'], array(
'table' => $db->name($prefix . $table),
'alias' => "{$type}{$i}",
'type' => 'LEFT',
'conditions' => array(
$db->name("{$type}{$i}.lft") . ' > ' . $db->name("{$type}{$j}.lft"),
$db->name("{$type}{$i}.rght") . ' < ' . $db->name("{$type}{$j}.rght"),
$db->name("{$type}{$i}.alias") . ' = ' . $db->value($alias))));
$queryData['joins'][] = array(
'table' => $db->name($prefix . $table),
'alias' => "{$type}{$i}",
'type' => 'LEFT',
'conditions' => array(
$db->name("{$type}{$i}.lft") . ' > ' . $db->name("{$type}{$j}.lft"),
$db->name("{$type}{$i}.rght") . ' < ' . $db->name("{$type}{$j}.rght"),
$db->name("{$type}{$i}.alias") . ' = ' . $db->value($alias)
)
);
$queryData['conditions'] = array('or' => array(
$db->name("{$type}.lft") . ' <= ' . $db->name("{$type}0.lft") . ' AND ' . $db->name("{$type}.rght") . ' >= ' . $db->name("{$type}0.rght"),
$db->name("{$type}.lft") . ' <= ' . $db->name("{$type}{$i}.lft") . ' AND ' . $db->name("{$type}.rght") . ' >= ' . $db->name("{$type}{$i}.rght")));
$db->name("{$type}.lft") . ' <= ' . $db->name("{$type}0.lft") . ' AND ' . $db->name("{$type}.rght") . ' >= ' . $db->name("{$type}0.rght"),
$db->name("{$type}.lft") . ' <= ' . $db->name("{$type}{$i}.lft") . ' AND ' . $db->name("{$type}.rght") . ' >= ' . $db->name("{$type}{$i}.rght"))
);
}
$result = $db->read($this, $queryData, -1);
} elseif (is_object($ref) && is_a($ref, 'Model')) {
$ref = array('model' => $ref->alias, 'foreign_key' => $ref->id);
} elseif (is_array($ref) && !(isset($ref['model']) && isset($ref['foreign_key']))) {
$name = key($ref);
if(PHP5) {
if (PHP5) {
$model = ClassRegistry::init(array('class' => $name, 'alias' => $name));
} else {
$model =& ClassRegistry::init(array('class' => $name, 'alias' => $name));
@ -157,15 +164,20 @@ class AclNode extends AppModel {
$ref["{$type}0.{$key}"] = $val;
}
}
$queryData = array('conditions' => $ref,
'fields' => array('id', 'parent_id', 'model', 'foreign_key', 'alias'),
'joins' => array(array('table' => $db->name($prefix . $table),
'alias' => "{$type}0",
'type' => 'LEFT',
'conditions' => array(
$db->name("{$type}.lft") . ' <= ' . $db->name("{$type}0.lft"),
$db->name("{$type}.rght") . ' >= ' . $db->name("{$type}0.rght")))),
'order' => $db->name("{$type}.lft") . ' DESC');
$queryData = array(
'conditions' => $ref,
'fields' => array('id', 'parent_id', 'model', 'foreign_key', 'alias'),
'joins' => array(array(
'table' => $db->name($prefix . $table),
'alias' => "{$type}0",
'type' => 'LEFT',
'conditions' => array(
$db->name("{$type}.lft") . ' <= ' . $db->name("{$type}0.lft"),
$db->name("{$type}.rght") . ' >= ' . $db->name("{$type}0.rght")
)
)),
'order' => $db->name("{$type}.lft") . ' DESC'
);
$result = $db->read($this, $queryData, -1);
if (!$result) {

View file

@ -181,8 +181,20 @@ class AclComponentTest extends CakeTestCase {
$result = $this->Acl->allow('Manager', 'Reports', array('read','delete','update'));
$this->assertTrue($result);
$result = $this->Acl->check('Manager', 'Reports', 'create');
$this->assertFalse($result);
$result = $this->Acl->check('Secretary', 'Links', 'create');
$this->assertFalse($result);
$result = $this->Acl->allow('Secretary', 'Links', array('create'));
$this->assertTrue($result);
$result = $this->Acl->check('Manager', 'Reports', 'create');
$this->assertFalse($result);
$result = $this->Acl->check('Secretary', 'Links', 'create');
$this->assertTrue($result);
}
function testDbAclCheck() {
@ -237,8 +249,10 @@ class AclComponentTest extends CakeTestCase {
}
function testDbAclDeny() {
$this->Acl->deny('Secretary','Links',array('delete'));
$result = $this->Acl->check('Secretary', 'Links', 'delete');
$this->assertTrue($result);
$this->Acl->deny('Secretary','Links',array('delete'));
$result = $this->Acl->check('Secretary','Links','delete');
$this->assertFalse($result);
@ -269,6 +283,16 @@ class AclComponentTest extends CakeTestCase {
$this->assertFalse($result);
}
function testAclNodeLookup() {
$result = $this->Acl->Aro->node('Global/Manager/Secretary');
$expected = array(
array('AroTest' => array('id' => '4', 'parent_id' => '3', 'model' => null, 'foreign_key' => null, 'alias' => 'Secretary')),
array('AroTest' => array('id' => '3', 'parent_id' => '1', 'model' => null, 'foreign_key' => null, 'alias' => 'Manager')),
array('AroTest' => array('id' => '1', 'parent_id' => null, 'model' => null, 'foreign_key' => null, 'alias' => 'Global'))
);
$this->assertEqual($result, $expected);
}
function tearDown() {
}
}