Skip to content

Commit

Permalink
Merge branch '2.0' into 2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Jan 28, 2012
2 parents 7eda0af + fb3c3e4 commit d904ab0
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
7 changes: 4 additions & 3 deletions lib/Cake/Model/AclNode.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -120,11 +120,12 @@ public function node($ref = null) {
return false; return false;
} }
} elseif (is_object($ref) && is_a($ref, 'Model')) { } elseif (is_object($ref) && is_a($ref, 'Model')) {
$ref = array('model' => $ref->alias, 'foreign_key' => $ref->id); $ref = array('model' => $ref->name, 'foreign_key' => $ref->id);
} elseif (is_array($ref) && !(isset($ref['model']) && isset($ref['foreign_key']))) { } elseif (is_array($ref) && !(isset($ref['model']) && isset($ref['foreign_key']))) {
$name = key($ref); $name = key($ref);
list($plugin, $alias) = pluginSplit($name);


$model = ClassRegistry::init(array('class' => $name, 'alias' => $name)); $model = ClassRegistry::init(array('class' => $name, 'alias' => $alias));


if (empty($model)) { if (empty($model)) {
trigger_error(__d('cake_dev', "Model class '%s' not found in AclNode::node() when trying to bind %s object", $type, $this->alias), E_USER_WARNING); trigger_error(__d('cake_dev', "Model class '%s' not found in AclNode::node() when trying to bind %s object", $type, $this->alias), E_USER_WARNING);
Expand All @@ -136,7 +137,7 @@ public function node($ref = null) {
$tmpRef = $model->bindNode($ref); $tmpRef = $model->bindNode($ref);
} }
if (empty($tmpRef)) { if (empty($tmpRef)) {
$ref = array('model' => $name, 'foreign_key' => $ref[$name][$model->primaryKey]); $ref = array('model' => $alias, 'foreign_key' => $ref[$name][$model->primaryKey]);
} else { } else {
if (is_string($tmpRef)) { if (is_string($tmpRef)) {
return $this->node($tmpRef); return $this->node($tmpRef);
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -110,6 +110,36 @@ public function testAuthorizeSuccess() {
$this->assertTrue($this->auth->authorize($user['User'], $request)); $this->assertTrue($this->auth->authorize($user['User'], $request));
} }


/**
* testAuthorizeSettings
*
* @return void
*/
public function testAuthorizeSettings() {
$request = new CakeRequest('/posts/index', false);
$request->addParams(array(
'plugin' => null,
'controller' => 'posts',
'action' => 'index'
));

$this->_mockAcl();

$this->auth->settings['userModel'] = 'TestPlugin.TestPluginAuthUser';
$user = array(
'id' => 1,
'user' => 'mariano'
);

$expected = array('TestPlugin.TestPluginAuthUser' => array('id' => 1, 'user' => 'mariano'));
$this->Acl->expects($this->once())
->method('check')
->with($expected, '/controllers/Posts/index')
->will($this->returnValue(true));

$this->assertTrue($this->auth->authorize($user, $request));
}

/** /**
* test action() * test action()
* *
Expand Down
28 changes: 27 additions & 1 deletion lib/Cake/Test/Case/Model/DbAclTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ public function testNodeArrayFind() {
$expected = array(4); $expected = array(4);
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
} }
/**
/**
* testNodeObjectFind method * testNodeObjectFind method
* *
* @return void * @return void
Expand Down Expand Up @@ -359,4 +360,29 @@ public function testNodeAliasParenting() {
); );
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
} }

/**
* testNodeActionAuthorize method
*
* @return void
*/
public function testNodeActionAuthorize() {
App::build(array(
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
), App::RESET);
CakePlugin::load('TestPlugin');

$Aro = new DbAroTest();
$Aro->create();
$Aro->save(array('model' => 'TestPluginAuthUser', 'foreign_key' => 1));
$result = $Aro->id;
$expected = 5;
$this->assertEquals($expected, $result);

$node = $Aro->node(array('TestPlugin.TestPluginAuthUser' => array('id' => 1, 'user' => 'mariano')));
$result = Set::extract($node, '0.DbAroTest.id');
$expected = $Aro->id;
$this->assertEquals($expected, $result);
CakePlugin::unload('TestPlugin');
}
} }

0 comments on commit d904ab0

Please sign in to comment.