Skip to content

Commit

Permalink
Fixing AclNode::node() so that node expressions that could match deep…
Browse files Browse the repository at this point in the history
…er elements are contained to their parent elements. Test added.
  • Loading branch information
markstory committed Mar 28, 2010
1 parent 46348e9 commit 068631e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
3 changes: 2 additions & 1 deletion cake/libs/model/db_acl.php
Expand Up @@ -111,7 +111,8 @@ function node($ref = null) {
'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, 'string')
$db->name("{$type}{$i}.alias") . ' = ' . $db->value($alias, 'string'),
$db->name("{$type}{$j}.id") . ' = ' . $db->name("{$type}{$i}.parent_id")
)
);

Expand Down
16 changes: 14 additions & 2 deletions cake/tests/cases/libs/model/db_acl.test.php
Expand Up @@ -283,7 +283,7 @@ function setUp() {
* @return void
*/
function testNode() {
$Aco = new DbAcoTest();
$Aco =& new DbAcoTest();
$result = Set::extract($Aco->node('Controller1'), '{n}.DbAcoTest.id');
$expected = array(2, 1);
$this->assertEqual($result, $expected);
Expand Down Expand Up @@ -317,7 +317,19 @@ function testNode() {
$result = $Aco->node('');
$this->assertEqual($result, null);
}
/**

/**
* test that node() doesn't dig deeper than it should.
*
* @return void
*/
function testNodeWithDuplicatePathSegments() {
$Aco =& new DbAcoTest();
$nodes = $Aco->node('ROOT/Users');
$this->assertEqual($nodes[0]['DbAcoTest']['parent_id'], 1, 'Parent id does not point at ROOT. %s');
}

/**
* testNodeArrayFind method
*
* @access public
Expand Down
5 changes: 4 additions & 1 deletion cake/tests/fixtures/aco_fixture.php
Expand Up @@ -57,7 +57,7 @@ class AcoFixture extends CakeTestFixture {
* @access public
*/
var $records = array(
array('parent_id' => null, 'model' => null, 'foreign_key' => null, 'alias' => 'ROOT', 'lft' => 1, 'rght' => 18),
array('parent_id' => null, 'model' => null, 'foreign_key' => null, 'alias' => 'ROOT', 'lft' => 1, 'rght' => 24),
array('parent_id' => 1, 'model' => null, 'foreign_key' => null, 'alias' => 'Controller1', 'lft' => 2, 'rght' => 9),
array('parent_id' => 2, 'model' => null, 'foreign_key' => null, 'alias' => 'action1', 'lft' => 3, 'rght' => 6),
array('parent_id' => 3, 'model' => null, 'foreign_key' => null, 'alias' => 'record1', 'lft' => 4, 'rght' => 5),
Expand All @@ -66,6 +66,9 @@ class AcoFixture extends CakeTestFixture {
array('parent_id' => 6, 'model' => null, 'foreign_key' => null, 'alias' => 'action1', 'lft' => 11, 'rght' => 14),
array('parent_id' => 7, 'model' => null, 'foreign_key' => null, 'alias' => 'record1', 'lft' => 12, 'rght' => 13),
array('parent_id' => 6, 'model' => null, 'foreign_key' => null, 'alias' => 'action2', 'lft' => 15, 'rght' => 16),
array('parent_id' => 1, 'model' => null, 'foreign_key' => null, 'alias' => 'Users', 'lft' => 18, 'rght' => 23),
array('parent_id' => 9, 'model' => null, 'foreign_key' => null, 'alias' => 'Users', 'lft' => 19, 'rght' => 22),
array('parent_id' => 10, 'model' => null, 'foreign_key' => null, 'alias' => 'view', 'lft' => 20, 'rght' => 21),
);
}

Expand Down

0 comments on commit 068631e

Please sign in to comment.