2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* DbAclTest 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
|
|
|
*
|
2010-05-19 01:15:13 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
2010-01-26 19:18:20 +00:00
|
|
|
* Copyright 2005-2010, 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
|
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-01-26 19:18:20 +00:00
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-05-19 01:15:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller.components.dbacl.models
|
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
|
|
|
*/
|
2010-12-09 05:55:24 +00:00
|
|
|
|
|
|
|
App::uses('AclComponent', 'Controller/Component');
|
2010-12-22 04:35:46 +00:00
|
|
|
App::uses('AclNode', 'Model');
|
|
|
|
class_exists('AclComponent');
|
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
|
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller.components
|
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
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller.components
|
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'
|
|
|
|
* @access public
|
|
|
|
*/
|
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'
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller.components
|
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'
|
|
|
|
* @access public
|
|
|
|
*/
|
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'
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller.components
|
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'
|
|
|
|
* @access public
|
|
|
|
*/
|
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'
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller.components
|
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'
|
|
|
|
* @access public
|
|
|
|
*/
|
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'
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller.components
|
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'
|
|
|
|
* @access public
|
|
|
|
*/
|
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'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = 'auth_users';
|
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
|
|
|
*
|
|
|
|
* @param mixed $ref
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function bindNode($ref = null) {
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller.components
|
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
|
|
|
* @access private
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
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
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller.components.dbacl.models
|
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
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function 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
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-06-20 20:17:23 +00:00
|
|
|
function testNode() {
|
2010-11-13 04:05:44 +00:00
|
|
|
$Aco = new DbAcoTest();
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = Set::extract($Aco->node('Controller1'), '{n}.DbAcoTest.id');
|
|
|
|
$expected = array(2, 1);
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Set::extract($Aco->node('Controller1/action1'), '{n}.DbAcoTest.id');
|
|
|
|
$expected = array(3, 2, 1);
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Set::extract($Aco->node('Controller2/action1'), '{n}.DbAcoTest.id');
|
|
|
|
$expected = array(7, 6, 1);
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Set::extract($Aco->node('Controller1/action2'), '{n}.DbAcoTest.id');
|
|
|
|
$expected = array(5, 2, 1);
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Set::extract($Aco->node('Controller1/action1/record1'), '{n}.DbAcoTest.id');
|
|
|
|
$expected = array(4, 3, 2, 1);
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Set::extract($Aco->node('Controller2/action1/record1'), '{n}.DbAcoTest.id');
|
|
|
|
$expected = array(8, 7, 6, 1);
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = Set::extract($Aco->node('Controller2/action3'), '{n}.DbAcoTest.id');
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
|
|
|
$result = Set::extract($Aco->node('Controller2/action3/record5'), '{n}.DbAcoTest.id');
|
|
|
|
$this->assertFalse($result);
|
2008-11-08 02:58:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $Aco->node('');
|
|
|
|
$this->assertEqual($result, null);
|
|
|
|
}
|
2010-03-28 20:59:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test that node() doesn't dig deeper than it should.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
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');
|
|
|
|
$this->assertEqual($nodes[0]['DbAcoTest']['parent_id'], 1, 'Parent id does not point at ROOT. %s');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testNodeArrayFind() {
|
|
|
|
$Aro = new DbAroTest();
|
|
|
|
Configure::write('DbAclbindMode', 'string');
|
|
|
|
$result = Set::extract($Aro->node(array('DbAroUserTest' => array('id' => '1', 'foreign_key' => '1'))), '{n}.DbAroTest.id');
|
|
|
|
$expected = array(3, 2, 1);
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
Configure::write('DbAclbindMode', 'array');
|
|
|
|
$result = Set::extract($Aro->node(array('DbAroUserTest' => array('id' => 4, 'foreign_key' => 2))), '{n}.DbAroTest.id');
|
|
|
|
$expected = array(4);
|
2008-11-08 02:58:37 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
2008-05-30 11:40:08 +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
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testNodeObjectFind() {
|
|
|
|
$Aro = new DbAroTest();
|
|
|
|
$Model = new DbAroUserTest();
|
|
|
|
$Model->id = 1;
|
|
|
|
$result = Set::extract($Aro->node($Model), '{n}.DbAroTest.id');
|
|
|
|
$expected = array(3, 2, 1);
|
|
|
|
$this->assertEqual($result, $expected);
|
2008-11-08 02:58:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$Model->id = 2;
|
|
|
|
$result = Set::extract($Aro->node($Model), '{n}.DbAroTest.id');
|
|
|
|
$expected = array(4, 2, 1);
|
|
|
|
$this->assertEqual($result, $expected);
|
2008-11-08 02:58:37 +00:00
|
|
|
|
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
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testNodeAliasParenting() {
|
|
|
|
$Aco = new DbAcoTest();
|
2010-09-20 02:58:30 +00:00
|
|
|
$db = ConnectionManager::getDataSource('test');
|
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()),
|
|
|
|
array('DbAcoTest' => array('id' => '2', 'parent_id' => '1', 'model' => null, 'foreign_key' => null, 'alias' => 'Pages', 'lft' => '2', 'rght' => '3', ), 'DbAroTest' => array())
|
|
|
|
);
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
|
|
|
}
|