Skip to content

Commit

Permalink
Fixing whitespacing on aco_fixture.
Browse files Browse the repository at this point in the history
Adding tests to AclShell::grant()
Refactoring __getParams()
  • Loading branch information
markstory committed Aug 5, 2009
1 parent 6775e09 commit 9e36d1b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 30 deletions.
22 changes: 7 additions & 15 deletions cake/console/libs/acl.php
Expand Up @@ -530,23 +530,15 @@ function _getNodeId($class, $identifier) {
* @access private
*/
function __getParams() {
$aro = ife(is_numeric($this->args[0]), intval($this->args[0]), $this->args[0]);
$aco = ife(is_numeric($this->args[1]), intval($this->args[1]), $this->args[1]);

if (is_string($aro) && preg_match('/^([\w]+)\.(.*)$/', $aro, $matches)) {
$aro = array(
'model' => $matches[1],
'foreign_key' => $matches[2],
);
$aro = is_numeric($this->args[0]) ? intval($this->args[0]) : $this->args[0];
$aco = is_numeric($this->args[1]) ? intval($this->args[1]) : $this->args[1];

if (is_string($aro)) {
$aro = $this->parseIdentifier($aro);
}

if (is_string($aco) && preg_match('/^([\w]+)\.(.*)$/', $aco, $matches)) {
$aco = array(
'model' => $matches[1],
'foreign_key' => $matches[2],
);
if (is_string($aco)) {
$aco = $this->parseIdentifier($aco);
}

$action = null;
if (isset($this->args[2])) {
$action = $this->args[2];
Expand Down
15 changes: 15 additions & 0 deletions cake/tests/cases/console/libs/acl.test.php
Expand Up @@ -217,5 +217,20 @@ function testSetParent() {
$result = $Aro->read(null, 4);
$this->assertEqual($result['Aro']['parent_id'], null);
}

/**
* test grant
*
* @return void
**/
function testGrant() {
$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'create');
$this->Task->expectAt(0, 'out', array(new PatternExpectation('/Permission granted/'), true));
$this->Task->grant();

$node = $this->Task->Acl->Aro->read(null, 4);
$this->assertFalse(empty($node['Aco'][0]));
$this->assertEqual($node['Aco'][0]['Permission']['_create'], 1);
}
}
?>
30 changes: 15 additions & 15 deletions cake/tests/fixtures/aco_fixture.php
Expand Up @@ -49,13 +49,13 @@ class AcoFixture extends CakeTestFixture {
* @access public
*/
var $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true),
'model' => array('type' => 'string', 'default' => ''),
'id' => array('type' => 'integer', 'key' => 'primary'),
'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true),
'model' => array('type' => 'string', 'default' => ''),
'foreign_key' => array('type' => 'integer', 'length' => 10, 'null' => true),
'alias' => array('type' => 'string', 'default' => ''),
'lft' => array('type' => 'integer', 'length' => 10, 'null' => true),
'rght' => array('type' => 'integer', 'length' => 10, 'null' => true)
'alias' => array('type' => 'string', 'default' => ''),
'lft' => array('type' => 'integer', 'length' => 10, 'null' => true),
'rght' => array('type' => 'integer', 'length' => 10, 'null' => true)
);

/**
Expand All @@ -65,15 +65,15 @@ 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' => 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),
array('parent_id' => 2, 'model' => null, 'foreign_key' => null, 'alias' => 'action2', 'lft' => 7, 'rght' => 8),
array('parent_id' => 1, 'model' => null, 'foreign_key' => null, 'alias' => 'Controller2', 'lft' => 10, 'rght' => 17),
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' => null, 'model' => null, 'foreign_key' => null, 'alias' => 'ROOT', 'lft' => 1, 'rght' => 18),
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),
array('parent_id' => 2, 'model' => null, 'foreign_key' => null, 'alias' => 'action2', 'lft' => 7, 'rght' => 8),
array('parent_id' => 1, 'model' => null, 'foreign_key' => null, 'alias' => 'Controller2','lft' => 10, 'rght' => 17),
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),
);
}

Expand Down

0 comments on commit 9e36d1b

Please sign in to comment.