Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding tests for getPath and inherit.

Refactoring the output of getPath
  • Loading branch information...
commit e6b32e21adeaaa96103911992dd09c7bbd2d853c 1 parent 3aa56e8
@markstory markstory authored
View
37 cake/console/libs/acl.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']);
}
}
View
34 cake/tests/cases/console/libs/acl.test.php
@@ -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();
+ }
}
?>
Please sign in to comment.
Something went wrong with that request. Please try again.