2008-07-31 03:26:15 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* AclBehaviorTest file
|
2008-07-31 03:26:15 +00:00
|
|
|
*
|
|
|
|
* Test the Acl Behavior
|
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2008-07-31 03:26:15 +00:00
|
|
|
*
|
2009-11-06 06:46:59 +00:00
|
|
|
* CakePHP : Rapid Development Framework (http://cakephp.org)
|
2013-02-08 12:28:17 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-07-31 03:26:15 +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
|
2008-07-31 03:26:15 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2013-02-08 12:28:17 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2009-11-06 06:00:11 +00:00
|
|
|
* @link http://cakephp.org CakePHP Project
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Model.Behavior
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP v 1.2.0.4487
|
2013-05-30 22:11:14 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
2008-07-31 03:26:15 +00:00
|
|
|
*/
|
2011-01-28 06:14:04 +00:00
|
|
|
|
2010-12-09 05:55:24 +00:00
|
|
|
App::uses('AclBehavior', 'Model/Behavior');
|
2011-01-28 06:14:04 +00:00
|
|
|
App::uses('Aco', 'Model');
|
|
|
|
App::uses('Aro', 'Model');
|
|
|
|
App::uses('AclNode', 'Model');
|
2010-12-09 05:55:24 +00:00
|
|
|
App::uses('DbAcl', 'Model');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-31 03:26:15 +00:00
|
|
|
/**
|
2012-03-18 18:31:13 +00:00
|
|
|
* Test Person class - self joined model
|
|
|
|
*
|
|
|
|
* @package Cake.Test.Case.Model.Behavior
|
|
|
|
*/
|
2008-07-31 03:26:15 +00:00
|
|
|
class AclPerson extends CakeTestModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-31 03:26:15 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
2008-08-07 15:36:26 +00:00
|
|
|
*
|
|
|
|
* @var string
|
2008-07-31 03:26:15 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = 'people';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-31 03:26:15 +00:00
|
|
|
/**
|
|
|
|
* actsAs property
|
2008-08-07 15:36:26 +00:00
|
|
|
*
|
2008-07-31 03:26:15 +00:00
|
|
|
* @var array
|
2008-08-07 15:36:26 +00:00
|
|
|
*/
|
2011-10-16 10:06:41 +00:00
|
|
|
public $actsAs = array('Acl' => 'both');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-31 03:26:15 +00:00
|
|
|
/**
|
|
|
|
* belongsTo property
|
2008-08-07 15:36:26 +00:00
|
|
|
*
|
2008-07-31 03:26:15 +00:00
|
|
|
* @var array
|
2008-08-07 15:36:26 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $belongsTo = array(
|
2008-07-31 03:26:15 +00:00
|
|
|
'Mother' => array(
|
|
|
|
'className' => 'AclPerson',
|
|
|
|
'foreignKey' => 'mother_id',
|
|
|
|
)
|
|
|
|
);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-31 03:26:15 +00:00
|
|
|
/**
|
|
|
|
* hasMany property
|
2008-08-07 15:36:26 +00:00
|
|
|
*
|
2008-07-31 03:26:15 +00:00
|
|
|
* @var array
|
2008-08-07 15:36:26 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $hasMany = array(
|
2008-07-31 03:26:15 +00:00
|
|
|
'Child' => array(
|
|
|
|
'className' => 'AclPerson',
|
|
|
|
'foreignKey' => 'mother_id'
|
|
|
|
)
|
|
|
|
);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-31 03:26:15 +00:00
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* parentNode method
|
2008-07-31 03:26:15 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-03-19 21:10:13 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function parentNode() {
|
2008-07-31 03:26:15 +00:00
|
|
|
if (!$this->id && empty($this->data)) {
|
|
|
|
return null;
|
|
|
|
}
|
2010-07-30 02:26:30 +00:00
|
|
|
if (isset($this->data['AclPerson']['mother_id'])) {
|
|
|
|
$motherId = $this->data['AclPerson']['mother_id'];
|
|
|
|
} else {
|
|
|
|
$motherId = $this->field('mother_id');
|
2008-08-07 15:36:26 +00:00
|
|
|
}
|
2010-07-30 02:26:30 +00:00
|
|
|
if (!$motherId) {
|
2008-07-31 03:26:15 +00:00
|
|
|
return null;
|
2008-08-07 15:36:26 +00:00
|
|
|
}
|
2013-07-02 23:14:41 +00:00
|
|
|
return array('AclPerson' => array('id' => $motherId));
|
2008-07-31 03:26:15 +00:00
|
|
|
}
|
2012-03-18 18:31:13 +00:00
|
|
|
|
2008-07-31 03:26:15 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-31 03:26:15 +00:00
|
|
|
/**
|
2012-03-18 18:31:13 +00:00
|
|
|
* AclUser class
|
|
|
|
*
|
|
|
|
* @package Cake.Test.Case.Model.Behavior
|
|
|
|
*/
|
2008-07-31 03:26:15 +00:00
|
|
|
class AclUser extends CakeTestModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-31 03:26:15 +00:00
|
|
|
/**
|
|
|
|
* name property
|
2008-08-07 15:36:26 +00:00
|
|
|
*
|
|
|
|
* @var string
|
2008-07-31 03:26:15 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'User';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-31 03:26:15 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
2008-08-07 15:36:26 +00:00
|
|
|
*
|
|
|
|
* @var string
|
2008-07-31 03:26:15 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = 'users';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-31 03:26:15 +00:00
|
|
|
/**
|
|
|
|
* actsAs property
|
2008-08-07 15:36:26 +00:00
|
|
|
*
|
2008-07-31 03:26:15 +00:00
|
|
|
* @var array
|
2008-08-07 15:36:26 +00:00
|
|
|
*/
|
2011-10-15 18:52:41 +00:00
|
|
|
public $actsAs = array('Acl' => array('type' => 'requester'));
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-31 03:26:15 +00:00
|
|
|
/**
|
2008-08-07 15:36:26 +00:00
|
|
|
* parentNode
|
|
|
|
*
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function parentNode() {
|
2008-07-31 03:26:15 +00:00
|
|
|
return null;
|
|
|
|
}
|
2012-03-18 18:31:13 +00:00
|
|
|
|
2008-07-31 03:26:15 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-31 03:26:15 +00:00
|
|
|
/**
|
2012-03-18 18:31:13 +00:00
|
|
|
* AclPost class
|
|
|
|
*
|
|
|
|
* @package Cake.Test.Case.Model.Behavior
|
|
|
|
*/
|
2008-07-31 03:26:15 +00:00
|
|
|
class AclPost extends CakeTestModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-31 03:26:15 +00:00
|
|
|
/**
|
|
|
|
* name property
|
2008-08-07 15:36:26 +00:00
|
|
|
*
|
|
|
|
* @var string
|
2008-07-31 03:26:15 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'Post';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-31 03:26:15 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
2008-08-07 15:36:26 +00:00
|
|
|
*
|
|
|
|
* @var string
|
2008-07-31 03:26:15 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = 'posts';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-31 03:26:15 +00:00
|
|
|
/**
|
|
|
|
* actsAs property
|
2008-08-07 15:36:26 +00:00
|
|
|
*
|
2008-07-31 03:26:15 +00:00
|
|
|
* @var array
|
2008-08-07 15:36:26 +00:00
|
|
|
*/
|
2011-10-15 18:52:41 +00:00
|
|
|
public $actsAs = array('Acl' => array('type' => 'Controlled'));
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-31 03:26:15 +00:00
|
|
|
/**
|
2008-08-07 15:36:26 +00:00
|
|
|
* parentNode
|
|
|
|
*
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function parentNode() {
|
2008-07-31 03:26:15 +00:00
|
|
|
return null;
|
|
|
|
}
|
2012-03-18 18:31:13 +00:00
|
|
|
|
2008-07-31 03:26:15 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-31 03:26:15 +00:00
|
|
|
/**
|
2012-03-18 18:31:13 +00:00
|
|
|
* AclBehaviorTest class
|
|
|
|
*
|
|
|
|
* @package Cake.Test.Case.Model.Behavior
|
|
|
|
*/
|
2010-06-13 14:06:00 +00:00
|
|
|
class AclBehaviorTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-19 21:10:13 +00:00
|
|
|
/**
|
|
|
|
* Aco property
|
|
|
|
*
|
|
|
|
* @var Aco
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $Aco;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-19 21:10:13 +00:00
|
|
|
/**
|
|
|
|
* Aro property
|
|
|
|
*
|
|
|
|
* @var Aro
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $Aro;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-19 21:10:13 +00:00
|
|
|
/**
|
|
|
|
* fixtures property
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $fixtures = array('core.person', 'core.user', 'core.post', 'core.aco', 'core.aro', 'core.aros_aco');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-31 03:26:15 +00:00
|
|
|
/**
|
|
|
|
* Set up the test
|
|
|
|
*
|
|
|
|
* @return void
|
2009-03-19 21:10:13 +00:00
|
|
|
*/
|
2010-06-07 04:04:34 +00:00
|
|
|
public function setUp() {
|
2012-04-16 02:20:34 +00:00
|
|
|
parent::setUp();
|
2010-09-20 02:58:30 +00:00
|
|
|
Configure::write('Acl.database', 'test');
|
2008-08-07 15:36:26 +00:00
|
|
|
|
2010-06-07 04:04:34 +00:00
|
|
|
$this->Aco = new Aco();
|
|
|
|
$this->Aro = new Aro();
|
2008-07-31 03:26:15 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-19 21:10:13 +00:00
|
|
|
/**
|
|
|
|
* tearDown method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function tearDown() {
|
2012-04-16 02:20:34 +00:00
|
|
|
parent::tearDown();
|
2009-03-19 21:10:13 +00:00
|
|
|
unset($this->Aro, $this->Aco);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-31 03:26:15 +00:00
|
|
|
/**
|
|
|
|
* Test Setup of AclBehavior
|
|
|
|
*
|
|
|
|
* @return void
|
2009-03-19 21:10:13 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testSetup() {
|
2010-06-07 04:04:34 +00:00
|
|
|
$User = new AclUser();
|
2008-07-31 03:26:15 +00:00
|
|
|
$this->assertTrue(isset($User->Behaviors->Acl->settings['User']));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('requester', $User->Behaviors->Acl->settings['User']['type']);
|
2008-07-31 03:26:15 +00:00
|
|
|
$this->assertTrue(is_object($User->Aro));
|
2008-08-07 15:36:26 +00:00
|
|
|
|
2010-06-07 04:04:34 +00:00
|
|
|
$Post = new AclPost();
|
2008-07-31 03:26:15 +00:00
|
|
|
$this->assertTrue(isset($Post->Behaviors->Acl->settings['Post']));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('controlled', $Post->Behaviors->Acl->settings['Post']['type']);
|
2008-07-31 03:26:15 +00:00
|
|
|
$this->assertTrue(is_object($Post->Aco));
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-02-27 15:08:52 +00:00
|
|
|
/**
|
|
|
|
* Test Setup of AclBehavior as both requester and controlled
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSetupMulti() {
|
2011-04-29 15:49:33 +00:00
|
|
|
$User = new AclPerson();
|
2011-02-27 15:08:52 +00:00
|
|
|
$this->assertTrue(isset($User->Behaviors->Acl->settings['AclPerson']));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('both', $User->Behaviors->Acl->settings['AclPerson']['type']);
|
2011-02-27 15:08:52 +00:00
|
|
|
$this->assertTrue(is_object($User->Aro));
|
|
|
|
$this->assertTrue(is_object($User->Aco));
|
|
|
|
}
|
|
|
|
|
2008-07-31 03:26:15 +00:00
|
|
|
/**
|
|
|
|
* test After Save
|
|
|
|
*
|
|
|
|
* @return void
|
2009-03-19 21:10:13 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testAfterSave() {
|
2010-06-07 04:04:34 +00:00
|
|
|
$Post = new AclPost();
|
2008-07-31 03:26:15 +00:00
|
|
|
$data = array(
|
|
|
|
'Post' => array(
|
|
|
|
'author_id' => 1,
|
|
|
|
'title' => 'Acl Post',
|
|
|
|
'body' => 'post body',
|
2008-08-07 15:36:26 +00:00
|
|
|
'published' => 1
|
|
|
|
),
|
2008-07-31 03:26:15 +00:00
|
|
|
);
|
|
|
|
$Post->save($data);
|
2010-07-30 02:07:45 +00:00
|
|
|
$result = $this->Aco->find('first', array(
|
|
|
|
'conditions' => array('Aco.model' => 'Post', 'Aco.foreign_key' => $Post->id)
|
|
|
|
));
|
2008-07-31 03:26:15 +00:00
|
|
|
$this->assertTrue(is_array($result));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('Post', $result['Aco']['model']);
|
|
|
|
$this->assertEquals($Post->id, $result['Aco']['foreign_key']);
|
2008-08-07 15:36:26 +00:00
|
|
|
|
2008-07-31 03:26:15 +00:00
|
|
|
$aroData = array(
|
|
|
|
'Aro' => array(
|
2008-08-06 14:13:01 +00:00
|
|
|
'model' => 'AclPerson',
|
2008-07-31 03:26:15 +00:00
|
|
|
'foreign_key' => 2,
|
|
|
|
'parent_id' => null
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->Aro->save($aroData);
|
2008-08-07 15:36:26 +00:00
|
|
|
|
2011-02-27 15:08:52 +00:00
|
|
|
$acoData = array(
|
|
|
|
'Aco' => array(
|
|
|
|
'model' => 'AclPerson',
|
|
|
|
'foreign_key' => 2,
|
|
|
|
'parent_id' => null
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->Aco->save($acoData);
|
|
|
|
|
2010-06-07 04:04:34 +00:00
|
|
|
$Person = new AclPerson();
|
2008-07-31 03:26:15 +00:00
|
|
|
$data = array(
|
2008-08-06 14:13:01 +00:00
|
|
|
'AclPerson' => array(
|
2008-07-31 03:26:15 +00:00
|
|
|
'name' => 'Trent',
|
|
|
|
'mother_id' => 2,
|
|
|
|
'father_id' => 3,
|
|
|
|
),
|
2008-08-07 15:36:26 +00:00
|
|
|
);
|
2008-07-31 03:26:15 +00:00
|
|
|
$Person->save($data);
|
2010-07-30 02:07:45 +00:00
|
|
|
$result = $this->Aro->find('first', array(
|
|
|
|
'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $Person->id)
|
|
|
|
));
|
2008-07-31 03:26:15 +00:00
|
|
|
$this->assertTrue(is_array($result));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(5, $result['Aro']['parent_id']);
|
2008-08-07 15:36:26 +00:00
|
|
|
|
2011-02-27 15:08:52 +00:00
|
|
|
$node = $Person->node(array('model' => 'AclPerson', 'foreign_key' => 8), 'Aro');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(2, count($node));
|
|
|
|
$this->assertEquals(5, $node[0]['Aro']['parent_id']);
|
|
|
|
$this->assertEquals(null, $node[1]['Aro']['parent_id']);
|
2009-09-19 05:17:20 +00:00
|
|
|
|
|
|
|
$aroData = array(
|
|
|
|
'Aro' => array(
|
|
|
|
'model' => 'AclPerson',
|
|
|
|
'foreign_key' => 1,
|
|
|
|
'parent_id' => null
|
|
|
|
)
|
2010-07-30 02:26:30 +00:00
|
|
|
);
|
|
|
|
$this->Aro->create();
|
|
|
|
$this->Aro->save($aroData);
|
2011-02-27 15:08:52 +00:00
|
|
|
$acoData = array(
|
|
|
|
'Aco' => array(
|
|
|
|
'model' => 'AclPerson',
|
|
|
|
'foreign_key' => 1,
|
|
|
|
'parent_id' => null
|
|
|
|
));
|
|
|
|
$this->Aco->create();
|
|
|
|
$this->Aco->save($acoData);
|
2010-07-30 02:26:30 +00:00
|
|
|
$Person->read(null, 8);
|
|
|
|
$Person->set('mother_id', 1);
|
|
|
|
$Person->save();
|
|
|
|
$result = $this->Aro->find('first', array(
|
2010-07-30 02:07:45 +00:00
|
|
|
'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $Person->id)
|
|
|
|
));
|
2011-02-27 15:08:52 +00:00
|
|
|
$this->assertTrue(is_array($result));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(7, $result['Aro']['parent_id']);
|
2011-02-27 15:08:52 +00:00
|
|
|
|
|
|
|
$node = $Person->node(array('model' => 'AclPerson', 'foreign_key' => 8), 'Aro');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(2, count($node));
|
|
|
|
$this->assertEquals(7, $node[0]['Aro']['parent_id']);
|
|
|
|
$this->assertEquals(null, $node[1]['Aro']['parent_id']);
|
2010-07-30 02:26:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test that an afterSave on an update does not cause parent_id to become null.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testAfterSaveUpdateParentIdNotNull() {
|
2010-07-30 02:26:30 +00:00
|
|
|
$aroData = array(
|
|
|
|
'Aro' => array(
|
|
|
|
'model' => 'AclPerson',
|
|
|
|
'foreign_key' => 2,
|
|
|
|
'parent_id' => null
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->Aro->save($aroData);
|
|
|
|
|
2011-02-27 15:08:52 +00:00
|
|
|
$acoData = array(
|
|
|
|
'Aco' => array(
|
|
|
|
'model' => 'AclPerson',
|
|
|
|
'foreign_key' => 2,
|
|
|
|
'parent_id' => null
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->Aco->save($acoData);
|
|
|
|
|
2010-09-25 05:25:42 +00:00
|
|
|
$Person = new AclPerson();
|
2010-07-30 02:26:30 +00:00
|
|
|
$data = array(
|
|
|
|
'AclPerson' => array(
|
|
|
|
'name' => 'Trent',
|
|
|
|
'mother_id' => 2,
|
|
|
|
'father_id' => 3,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
$Person->save($data);
|
|
|
|
$result = $this->Aro->find('first', array(
|
|
|
|
'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $Person->id)
|
|
|
|
));
|
|
|
|
$this->assertTrue(is_array($result));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(5, $result['Aro']['parent_id']);
|
2010-07-30 02:26:30 +00:00
|
|
|
|
|
|
|
$Person->save(array('id' => $Person->id, 'name' => 'Bruce'));
|
|
|
|
$result = $this->Aro->find('first', array(
|
|
|
|
'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $Person->id)
|
|
|
|
));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(5, $result['Aro']['parent_id']);
|
2008-07-31 03:26:15 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-31 03:26:15 +00:00
|
|
|
/**
|
|
|
|
* Test After Delete
|
|
|
|
*
|
|
|
|
* @return void
|
2009-03-19 21:10:13 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testAfterDelete() {
|
2008-07-31 03:26:15 +00:00
|
|
|
$aroData = array(
|
|
|
|
'Aro' => array(
|
2008-08-06 14:13:01 +00:00
|
|
|
'model' => 'AclPerson',
|
2008-07-31 03:26:15 +00:00
|
|
|
'foreign_key' => 2,
|
|
|
|
'parent_id' => null
|
|
|
|
)
|
|
|
|
);
|
2008-08-07 15:36:26 +00:00
|
|
|
$this->Aro->save($aroData);
|
2011-03-19 14:14:10 +00:00
|
|
|
|
2011-02-27 15:08:52 +00:00
|
|
|
$acoData = array(
|
|
|
|
'Aco' => array(
|
|
|
|
'model' => 'AclPerson',
|
|
|
|
'foreign_key' => 2,
|
|
|
|
'parent_id' => null
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->Aco->save($acoData);
|
2010-06-07 04:04:34 +00:00
|
|
|
$Person = new AclPerson();
|
2011-03-19 14:14:10 +00:00
|
|
|
|
2008-07-31 03:26:15 +00:00
|
|
|
$data = array(
|
2008-08-06 14:13:01 +00:00
|
|
|
'AclPerson' => array(
|
2008-07-31 03:26:15 +00:00
|
|
|
'name' => 'Trent',
|
|
|
|
'mother_id' => 2,
|
|
|
|
'father_id' => 3,
|
|
|
|
),
|
2008-08-07 15:36:26 +00:00
|
|
|
);
|
|
|
|
$Person->save($data);
|
2008-07-31 03:26:15 +00:00
|
|
|
$id = $Person->id;
|
2011-02-27 15:08:52 +00:00
|
|
|
$node = $Person->node(null, 'Aro');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(2, count($node));
|
|
|
|
$this->assertEquals(5, $node[0]['Aro']['parent_id']);
|
|
|
|
$this->assertEquals(null, $node[1]['Aro']['parent_id']);
|
2008-08-07 15:36:26 +00:00
|
|
|
|
2008-07-31 03:26:15 +00:00
|
|
|
$Person->delete($id);
|
2010-07-30 02:07:45 +00:00
|
|
|
$result = $this->Aro->find('first', array(
|
|
|
|
'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $id)
|
|
|
|
));
|
2008-08-07 15:36:26 +00:00
|
|
|
$this->assertTrue(empty($result));
|
2010-07-30 02:07:45 +00:00
|
|
|
$result = $this->Aro->find('first', array(
|
|
|
|
'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => 2)
|
|
|
|
));
|
2008-07-31 03:35:26 +00:00
|
|
|
$this->assertFalse(empty($result));
|
2008-08-07 15:36:26 +00:00
|
|
|
|
2008-07-31 03:35:26 +00:00
|
|
|
$data = array(
|
2008-08-06 14:13:01 +00:00
|
|
|
'AclPerson' => array(
|
2008-07-31 03:35:26 +00:00
|
|
|
'name' => 'Trent',
|
|
|
|
'mother_id' => 2,
|
|
|
|
'father_id' => 3,
|
|
|
|
),
|
2008-08-07 15:36:26 +00:00
|
|
|
);
|
2008-07-31 03:35:26 +00:00
|
|
|
$Person->save($data);
|
|
|
|
$id = $Person->id;
|
|
|
|
$Person->delete(2);
|
2010-07-30 02:07:45 +00:00
|
|
|
$result = $this->Aro->find('first', array(
|
|
|
|
'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $id)
|
|
|
|
));
|
2008-08-07 15:36:26 +00:00
|
|
|
$this->assertTrue(empty($result));
|
|
|
|
|
2010-07-30 02:07:45 +00:00
|
|
|
$result = $this->Aro->find('first', array(
|
|
|
|
'conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => 2)
|
|
|
|
));
|
2008-07-31 03:26:15 +00:00
|
|
|
$this->assertTrue(empty($result));
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-31 03:26:15 +00:00
|
|
|
/**
|
|
|
|
* Test Node()
|
|
|
|
*
|
|
|
|
* @return void
|
2009-03-19 21:10:13 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testNode() {
|
2010-06-07 04:04:34 +00:00
|
|
|
$Person = new AclPerson();
|
2008-07-31 03:26:15 +00:00
|
|
|
$aroData = array(
|
|
|
|
'Aro' => array(
|
2008-08-06 14:13:01 +00:00
|
|
|
'model' => 'AclPerson',
|
2008-07-31 03:26:15 +00:00
|
|
|
'foreign_key' => 2,
|
|
|
|
'parent_id' => null
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->Aro->save($aroData);
|
2008-08-07 15:36:26 +00:00
|
|
|
|
2008-07-31 03:26:15 +00:00
|
|
|
$Person->id = 2;
|
2011-02-27 15:08:52 +00:00
|
|
|
$result = $Person->node(null, 'Aro');
|
2008-07-31 03:26:15 +00:00
|
|
|
$this->assertTrue(is_array($result));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(1, count($result));
|
2008-07-31 03:26:15 +00:00
|
|
|
}
|
|
|
|
}
|