mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
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:
parent
14523dc8c4
commit
96d2b4b738
2 changed files with 67 additions and 31 deletions
|
@ -94,33 +94,40 @@ class AclNode extends AppModel {
|
|||
$start = $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}.rght") . ' >= ' . $db->name("{$type}0.rght")),
|
||||
'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",
|
||||
'type' => 'LEFT',
|
||||
'conditions' => array("{$type}0.alias" => $start))),
|
||||
'order' => $db->name("{$type}.lft") . ' DESC');
|
||||
'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(
|
||||
$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))));
|
||||
$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}{$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']))) {
|
||||
|
@ -157,15 +164,20 @@ class AclNode extends AppModel {
|
|||
$ref["{$type}0.{$key}"] = $val;
|
||||
}
|
||||
}
|
||||
$queryData = array('conditions' => $ref,
|
||||
$queryData = array(
|
||||
'conditions' => $ref,
|
||||
'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",
|
||||
'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');
|
||||
$db->name("{$type}.rght") . ' >= ' . $db->name("{$type}0.rght")
|
||||
)
|
||||
)),
|
||||
'order' => $db->name("{$type}.lft") . ' DESC'
|
||||
);
|
||||
$result = $db->read($this, $queryData, -1);
|
||||
|
||||
if (!$result) {
|
||||
|
|
|
@ -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() {
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue