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

View file

@ -181,8 +181,20 @@ class AclComponentTest extends CakeTestCase {
$result = $this->Acl->allow('Manager', 'Reports', array('read','delete','update')); $result = $this->Acl->allow('Manager', 'Reports', array('read','delete','update'));
$this->assertTrue($result); $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')); $result = $this->Acl->allow('Secretary', 'Links', array('create'));
$this->assertTrue($result); $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() { function testDbAclCheck() {
@ -237,8 +249,10 @@ class AclComponentTest extends CakeTestCase {
} }
function testDbAclDeny() { 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'); $result = $this->Acl->check('Secretary','Links','delete');
$this->assertFalse($result); $this->assertFalse($result);
@ -269,6 +283,16 @@ class AclComponentTest extends CakeTestCase {
$this->assertFalse($result); $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() { function tearDown() {
} }
} }