mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Adding tests for getPath and inherit.
Refactoring the output of getPath
This commit is contained in:
parent
3aa56e82c9
commit
e6b32e21ad
2 changed files with 61 additions and 10 deletions
|
@ -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 @@ class AclShell extends Shell {
|
|||
$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 @@ class AclShellTest extends CakeTestCase {
|
|||
$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();
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Add table
Reference in a new issue