Skip to content
Permalink
Browse files

Adding tests for getPath and inherit.

Refactoring the output of getPath
  • Loading branch information...
markstory committed Aug 6, 2009
1 parent 3aa56e8 commit e6b32e21adeaaa96103911992dd09c7bbd2d853c
Showing with 61 additions and 10 deletions.
  1. +29 −8 cake/console/libs/acl.php
  2. +32 −2 cake/tests/cases/console/libs/acl.test.php
@@ -1,10 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Short description for file.
*
* Long description for file
* Acl Shell provides Acl access in the CLI environment
*
* PHP versions 4 and 5
*
@@ -220,13 +216,38 @@ function getPath() {
$this->_checkArgs(2, 'getPath');
$this->checkNodeType();
extract($this->__dataVars());
$id = ife(is_numeric($this->args[1]), intval($this->args[1]), $this->args[1]);
$identifier = $this->parseIdentifier($this->args[1]);
$id = $this->_getNodeId($class, $identifier);
$nodes = $this->Acl->{$class}->getPath($id);
if (empty($nodes)) {
$this->error(sprintf(__("Supplied Node '%s' not found", true), $this->args[1]), __("No tree returned.", true));
$this->error(
sprintf(__("Supplied Node '%s' not found", true), $this->args[1]),
__("No tree returned.", true)
);
}
for ($i = 0; $i < count($nodes); $i++) {
$this->out(str_repeat(' ', $i) . "[" . $nodes[$i][$class]['id'] . "]" . $nodes[$i][$class]['alias'] . "\n");
$this->_outputNode($class, $nodes[$i], $i);
}
}
/**
* Outputs a single node, Either using the alias or Model.key
*
* @param string $class Class name that is being used.
* @param array $node Array of node information.
* @param integer $indent indent level.
* @return void
* @access protected
**/
function _outputNode($class, $node, $indent) {
$indent = str_repeat(' ', $indent);
$data = $node[$class];
if ($data['alias']) {
$this->out($indent . "[" . $data['id'] . "] " . $data['alias']);
} else {
$this->out($indent . "[" . $data['id'] . "] " . $data['model'] . '.' . $data['foreign_key']);
}
}
@@ -1,6 +1,4 @@
<?php
/* SVN FILE: $Id$ */
/**
* AclShell Test file
*
@@ -270,5 +268,37 @@ function testCheck() {
$this->Task->expectAt(3, 'out', array(new PatternExpectation('/not allowed/'), true));
$this->Task->check();
}
/**
* test inherit and that it 0's the permission fields.
*
* @return void
**/
function testInherit() {
$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'create');
$this->Task->expectAt(0, 'out', array(new PatternExpectation('/Permission granted/'), true));
$this->Task->grant();
$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'all');
$this->Task->expectAt(1, 'out', array(new PatternExpectation('/permission inherited/i'), true));
$this->Task->inherit();
$node = $this->Task->Acl->Aro->read(null, 4);
$this->assertFalse(empty($node['Aco'][0]));
$this->assertEqual($node['Aco'][0]['Permission']['_create'], 0);
}
/**
* test getting the path for an aro/aco
*
* @return void
**/
function testGetPath() {
$this->Task->args = array('aro', 'AuthUser.2');
$this->Task->expectAt(0, 'out', array('[1] ROOT'));
$this->Task->expectAt(1, 'out', array(' [2] admins'));
$this->Task->expectAt(2, 'out', array(' [4] Elrond'));
$this->Task->getPath();
}
}
?>

0 comments on commit e6b32e2

Please sign in to comment.
You can’t perform that action at this time.