2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2012-02-23 18:45:32 +00:00
|
|
|
* AclNodeTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2012-04-27 02:49:18 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
2013-02-08 11:59:49 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2010-10-03 16:31:21 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2013-02-08 11:59:49 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2012-04-27 02:49:18 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Model
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.4206
|
2010-10-03 16:27:27 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-02-18 14:32:48 +00:00
|
|
|
App::uses('DbAcl', 'Controller/Component/Acl');
|
2010-12-22 04:35:46 +00:00
|
|
|
App::uses('AclNode', 'Model');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* DB ACL wrapper test class
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Model
|
2009-03-19 21:10:13 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class DbAclNodeTestBase extends AclNode {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* useDbConfig property
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2010-09-20 02:58:30 +00:00
|
|
|
* @var string 'test'
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-09-20 02:58:30 +00:00
|
|
|
public $useDbConfig = 'test';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* cacheSources property
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var bool false
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $cacheSources = false;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* Aro Test Wrapper
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Model
|
2009-03-19 21:10:13 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class DbAroTest extends DbAclNodeTestBase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* name property
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'DbAroTest'
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'DbAroTest';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'aros'
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = 'aros';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* hasAndBelongsToMany property
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $hasAndBelongsToMany = array('DbAcoTest' => array('with' => 'DbPermissionTest'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* Aco Test Wrapper
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Model
|
2009-03-19 21:10:13 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class DbAcoTest extends DbAclNodeTestBase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* name property
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'DbAcoTest'
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'DbAcoTest';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'acos'
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = 'acos';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* hasAndBelongsToMany property
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $hasAndBelongsToMany = array('DbAroTest' => array('with' => 'DbPermissionTest'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* Permission Test Wrapper
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Model
|
2009-03-19 21:10:13 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class DbPermissionTest extends CakeTestModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* name property
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'DbPermissionTest'
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'DbPermissionTest';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'aros_acos'
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = 'aros_acos';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* cacheQueries property
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var bool false
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $cacheQueries = false;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* belongsTo property
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $belongsTo = array('DbAroTest' => array('foreignKey' => 'aro_id'), 'DbAcoTest' => array('foreignKey' => 'aco_id'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* DboActionTest class
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Model
|
2009-03-19 21:10:13 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class DbAcoActionTest extends CakeTestModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* name property
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'DbAcoActionTest'
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'DbAcoActionTest';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'aco_actions'
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = 'aco_actions';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* belongsTo property
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $belongsTo = array('DbAcoTest' => array('foreignKey' => 'aco_id'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* DbAroUserTest class
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Model
|
2009-03-19 21:10:13 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class DbAroUserTest extends CakeTestModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* name property
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'AuthUser'
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'AuthUser';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'auth_users'
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = 'auth_users';
|
2011-12-06 20:52:48 +00:00
|
|
|
|
2010-12-14 03:00:37 +00:00
|
|
|
/**
|
2008-06-02 19:22:55 +00:00
|
|
|
* bindNode method
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2012-05-13 00:43:31 +00:00
|
|
|
* @param string|array|Model $ref
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function bindNode($ref = null) {
|
2008-05-30 11:40:08 +00:00
|
|
|
if (Configure::read('DbAclbindMode') == 'string') {
|
|
|
|
return 'ROOT/admins/Gandalf';
|
|
|
|
} elseif (Configure::read('DbAclbindMode') == 'array') {
|
|
|
|
return array('DbAroTest' => array('DbAroTest.model' => 'AuthUser', 'DbAroTest.foreign_key' => 2));
|
|
|
|
}
|
|
|
|
}
|
2012-03-19 01:20:17 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-09-20 00:38:33 +00:00
|
|
|
* TestDbAcl class
|
2009-03-19 21:10:13 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Model
|
2009-03-19 21:10:13 +00:00
|
|
|
*/
|
2010-09-20 00:38:33 +00:00
|
|
|
class TestDbAcl extends DbAcl {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* construct method
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2012-02-17 07:13:12 +00:00
|
|
|
public function __construct() {
|
2010-11-13 04:05:44 +00:00
|
|
|
$this->Aro = new DbAroTest();
|
|
|
|
$this->Aro->Permission = new DbPermissionTest();
|
|
|
|
$this->Aco = new DbAcoTest();
|
|
|
|
$this->Aro->Permission = new DbPermissionTest();
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2012-03-19 01:20:17 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* AclNodeTest class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Model
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class AclNodeTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* fixtures property
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $fixtures = array('core.aro', 'core.aco', 'core.aros_aco', 'core.aco_action', 'core.auth_user');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* setUp method
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function setUp() {
|
2011-11-03 03:44:22 +00:00
|
|
|
parent::setUp();
|
2010-09-20 00:38:33 +00:00
|
|
|
Configure::write('Acl.classname', 'TestDbAcl');
|
2010-09-20 02:58:30 +00:00
|
|
|
Configure::write('Acl.database', 'test');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testNode method
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testNode() {
|
2010-11-13 04:05:44 +00:00
|
|
|
$Aco = new DbAcoTest();
|
2012-03-11 01:57:18 +00:00
|
|
|
$result = Hash::extract($Aco->node('Controller1'), '{n}.DbAcoTest.id');
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(2, 1);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-03-11 01:57:18 +00:00
|
|
|
$result = Hash::extract($Aco->node('Controller1/action1'), '{n}.DbAcoTest.id');
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(3, 2, 1);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-03-11 01:57:18 +00:00
|
|
|
$result = Hash::extract($Aco->node('Controller2/action1'), '{n}.DbAcoTest.id');
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(7, 6, 1);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-03-11 01:57:18 +00:00
|
|
|
$result = Hash::extract($Aco->node('Controller1/action2'), '{n}.DbAcoTest.id');
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(5, 2, 1);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-03-11 01:57:18 +00:00
|
|
|
$result = Hash::extract($Aco->node('Controller1/action1/record1'), '{n}.DbAcoTest.id');
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(4, 3, 2, 1);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-03-11 01:57:18 +00:00
|
|
|
$result = Hash::extract($Aco->node('Controller2/action1/record1'), '{n}.DbAcoTest.id');
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(8, 7, 6, 1);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-03-11 01:57:18 +00:00
|
|
|
$this->assertFalse($Aco->node('Controller2/action3'));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-03-11 01:57:18 +00:00
|
|
|
$this->assertFalse($Aco->node('Controller2/action3/record5'));
|
2008-11-08 02:58:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $Aco->node('');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(null, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2010-03-28 20:59:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test that node() doesn't dig deeper than it should.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testNodeWithDuplicatePathSegments() {
|
2010-11-13 04:05:44 +00:00
|
|
|
$Aco = new DbAcoTest();
|
2010-03-28 20:59:24 +00:00
|
|
|
$nodes = $Aco->node('ROOT/Users');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(1, $nodes[0]['DbAcoTest']['parent_id'], 'Parent id does not point at ROOT. %s');
|
2010-03-28 20:59:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-06-05 15:20:45 +00:00
|
|
|
* testNodeArrayFind method
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testNodeArrayFind() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$Aro = new DbAroTest();
|
|
|
|
Configure::write('DbAclbindMode', 'string');
|
2012-03-11 01:57:18 +00:00
|
|
|
$result = Hash::extract($Aro->node(array('DbAroUserTest' => array('id' => '1', 'foreign_key' => '1'))), '{n}.DbAroTest.id');
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(3, 2, 1);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
Configure::write('DbAclbindMode', 'array');
|
2012-03-11 01:57:18 +00:00
|
|
|
$result = Hash::extract($Aro->node(array('DbAroUserTest' => array('id' => 4, 'foreign_key' => 2))), '{n}.DbAroTest.id');
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(4);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2012-01-11 10:39:06 +00:00
|
|
|
|
|
|
|
/**
|
2008-06-05 15:20:45 +00:00
|
|
|
* testNodeObjectFind method
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testNodeObjectFind() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$Aro = new DbAroTest();
|
|
|
|
$Model = new DbAroUserTest();
|
|
|
|
$Model->id = 1;
|
2012-03-11 01:57:18 +00:00
|
|
|
$result = Hash::extract($Aro->node($Model), '{n}.DbAroTest.id');
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(3, 2, 1);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-11-08 02:58:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$Model->id = 2;
|
2012-03-11 01:57:18 +00:00
|
|
|
$result = Hash::extract($Aro->node($Model), '{n}.DbAroTest.id');
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(4, 2, 1);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testNodeAliasParenting method
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testNodeAliasParenting() {
|
2011-02-23 05:52:23 +00:00
|
|
|
$Aco = ClassRegistry::init('DbAcoTest');
|
|
|
|
$db = $Aco->getDataSource();
|
2008-05-30 11:40:08 +00:00
|
|
|
$db->truncate($Aco);
|
|
|
|
|
|
|
|
$Aco->create(array('model' => null, 'foreign_key' => null, 'parent_id' => null, 'alias' => 'Application'));
|
|
|
|
$Aco->save();
|
|
|
|
|
|
|
|
$Aco->create(array('model' => null, 'foreign_key' => null, 'parent_id' => $Aco->id, 'alias' => 'Pages'));
|
|
|
|
$Aco->save();
|
|
|
|
|
|
|
|
$result = $Aco->find('all');
|
|
|
|
$expected = array(
|
|
|
|
array('DbAcoTest' => array('id' => '1', 'parent_id' => null, 'model' => null, 'foreign_key' => null, 'alias' => 'Application', 'lft' => '1', 'rght' => '4'), 'DbAroTest' => array()),
|
2011-12-16 06:52:07 +00:00
|
|
|
array('DbAcoTest' => array('id' => '2', 'parent_id' => '1', 'model' => null, 'foreign_key' => null, 'alias' => 'Pages', 'lft' => '2', 'rght' => '3'), 'DbAroTest' => array())
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2012-01-11 10:39:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* testNodeActionAuthorize method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testNodeActionAuthorize() {
|
|
|
|
App::build(array(
|
2012-02-18 12:31:29 +00:00
|
|
|
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
2012-01-11 10:39:06 +00:00
|
|
|
), 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')));
|
2012-03-11 01:57:18 +00:00
|
|
|
$result = Hash::get($node, '0.DbAroTest.id');
|
2012-01-11 10:39:06 +00:00
|
|
|
$expected = $Aro->id;
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
CakePlugin::unload('TestPlugin');
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|