From 9e36d1bedc168e4b16233826b540520f8fc7766f Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 5 Aug 2009 00:23:59 -0400 Subject: [PATCH] Fixing whitespacing on aco_fixture. Adding tests to AclShell::grant() Refactoring __getParams() --- cake/console/libs/acl.php | 22 +++++----------- cake/tests/cases/console/libs/acl.test.php | 15 +++++++++++ cake/tests/fixtures/aco_fixture.php | 30 +++++++++++----------- 3 files changed, 37 insertions(+), 30 deletions(-) diff --git a/cake/console/libs/acl.php b/cake/console/libs/acl.php index 18d73fe7c81..1b31ac5d315 100644 --- a/cake/console/libs/acl.php +++ b/cake/console/libs/acl.php @@ -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]; diff --git a/cake/tests/cases/console/libs/acl.test.php b/cake/tests/cases/console/libs/acl.test.php index c65f02b1618..010c0eea0cf 100644 --- a/cake/tests/cases/console/libs/acl.test.php +++ b/cake/tests/cases/console/libs/acl.test.php @@ -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); + } } ?> \ No newline at end of file diff --git a/cake/tests/fixtures/aco_fixture.php b/cake/tests/fixtures/aco_fixture.php index 57e0172dd2e..e13f8745c87 100644 --- a/cake/tests/fixtures/aco_fixture.php +++ b/cake/tests/fixtures/aco_fixture.php @@ -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) ); /** @@ -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), ); }