2011-05-14 15:28:58 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* TreeBehaviorNumberTest file
|
|
|
|
*
|
|
|
|
* This is the basic Tree behavior test
|
|
|
|
*
|
|
|
|
* PHP 5
|
|
|
|
*
|
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)
|
2011-05-14 15:28:58 +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
|
2011-05-14 15:28:58 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice
|
|
|
|
*
|
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.Behavior
|
2011-05-14 15:28:58 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.5330
|
2013-05-30 22:11:14 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
2011-05-14 15:28:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
App::uses('Model', 'Model');
|
|
|
|
App::uses('AppModel', 'Model');
|
2012-03-18 18:31:13 +00:00
|
|
|
require_once dirname(dirname(__FILE__)) . DS . 'models.php';
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* TreeBehaviorNumberTest class
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Model.Behavior
|
2011-05-14 15:28:58 +00:00
|
|
|
*/
|
|
|
|
class TreeBehaviorNumberTest extends CakeTestCase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether backup global state for each test method or not
|
|
|
|
*
|
|
|
|
* @var bool false
|
|
|
|
*/
|
|
|
|
public $backupGlobals = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* settings property
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2012-03-18 18:31:13 +00:00
|
|
|
public $settings = array(
|
2011-05-14 15:28:58 +00:00
|
|
|
'modelClass' => 'NumberTree',
|
|
|
|
'leftField' => 'lft',
|
|
|
|
'rightField' => 'rght',
|
|
|
|
'parentField' => 'parent_id'
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* fixtures property
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2012-01-19 22:20:15 +00:00
|
|
|
public $fixtures = array('core.number_tree', 'core.person');
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* testInitialize method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testInitialize() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
|
|
|
|
$result = $this->Tree->find('count');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(7, $result);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$validTree = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($validTree, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testDetectInvalidLeft method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDetectInvalidLeft() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
|
|
|
|
$result = $this->Tree->findByName('1.1');
|
|
|
|
|
|
|
|
$save[$modelClass]['id'] = $result[$modelClass]['id'];
|
|
|
|
$save[$modelClass][$leftField] = 0;
|
|
|
|
|
|
|
|
$this->Tree->save($save);
|
|
|
|
$result = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertNotSame($result, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$result = $this->Tree->recover();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($result, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$result = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($result, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testDetectInvalidRight method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDetectInvalidRight() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
|
|
|
|
$result = $this->Tree->findByName('1.1');
|
|
|
|
|
|
|
|
$save[$modelClass]['id'] = $result[$modelClass]['id'];
|
|
|
|
$save[$modelClass][$rightField] = 0;
|
|
|
|
|
|
|
|
$this->Tree->save($save);
|
|
|
|
$result = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertNotSame($result, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$result = $this->Tree->recover();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($result, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$result = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($result, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testDetectInvalidParent method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDetectInvalidParent() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
|
|
|
|
$result = $this->Tree->findByName('1.1');
|
|
|
|
|
|
|
|
// Bypass behavior and any other logic
|
|
|
|
$this->Tree->updateAll(array($parentField => null), array('id' => $result[$modelClass]['id']));
|
|
|
|
|
|
|
|
$result = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertNotSame($result, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$result = $this->Tree->recover();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($result, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$result = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($result, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-02-23 23:29:53 +00:00
|
|
|
* testDetectNoneExistentParent method
|
2011-05-14 15:28:58 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-02-23 23:29:53 +00:00
|
|
|
public function testDetectNoneExistentParent() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
|
|
|
|
$result = $this->Tree->findByName('1.1');
|
|
|
|
$this->Tree->updateAll(array($parentField => 999999), array('id' => $result[$modelClass]['id']));
|
|
|
|
|
|
|
|
$result = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertNotSame($result, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$result = $this->Tree->recover('MPTT');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($result, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$result = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($result, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
2011-12-18 09:34:26 +00:00
|
|
|
/**
|
|
|
|
* testRecoverUsingParentMode method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRecoverUsingParentMode() {
|
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-12-18 09:34:26 +00:00
|
|
|
$this->Tree->Behaviors->disable('Tree');
|
|
|
|
|
2012-11-13 20:12:46 +00:00
|
|
|
$this->Tree->save(array('name' => 'Main', $parentField => null, $leftField => 0, $rightField => 0));
|
2012-11-13 10:18:17 +00:00
|
|
|
$node1 = $this->Tree->id;
|
2011-12-18 09:34:26 +00:00
|
|
|
|
|
|
|
$this->Tree->create();
|
2012-11-13 20:12:46 +00:00
|
|
|
$this->Tree->save(array('name' => 'About Us', $parentField => $node1, $leftField => 0, $rightField => 0));
|
2012-11-14 08:55:33 +00:00
|
|
|
$node11 = $this->Tree->id;
|
2011-12-18 09:34:26 +00:00
|
|
|
$this->Tree->create();
|
2012-11-13 20:12:46 +00:00
|
|
|
$this->Tree->save(array('name' => 'Programs', $parentField => $node1, $leftField => 0, $rightField => 0));
|
2012-11-14 08:55:33 +00:00
|
|
|
$node12 = $this->Tree->id;
|
2011-12-18 09:34:26 +00:00
|
|
|
$this->Tree->create();
|
2012-11-13 20:12:46 +00:00
|
|
|
$this->Tree->save(array('name' => 'Mission and History', $parentField => $node11, $leftField => 0, $rightField => 0));
|
2011-12-18 09:34:26 +00:00
|
|
|
$this->Tree->create();
|
2012-11-13 20:12:46 +00:00
|
|
|
$this->Tree->save(array('name' => 'Overview', $parentField => $node12, $leftField => 0, $rightField => 0));
|
2011-12-18 09:34:26 +00:00
|
|
|
|
|
|
|
$this->Tree->Behaviors->enable('Tree');
|
|
|
|
|
|
|
|
$result = $this->Tree->verify();
|
|
|
|
$this->assertNotSame($result, true);
|
|
|
|
|
|
|
|
$result = $this->Tree->recover();
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$result = $this->Tree->verify();
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$result = $this->Tree->find('first', array(
|
|
|
|
'fields' => array('name', $parentField, $leftField, $rightField),
|
|
|
|
'conditions' => array('name' => 'Main'),
|
|
|
|
'recursive' => -1
|
|
|
|
));
|
|
|
|
$expected = array(
|
|
|
|
$modelClass => array(
|
|
|
|
'name' => 'Main',
|
|
|
|
$parentField => null,
|
2012-11-13 10:18:17 +00:00
|
|
|
$leftField => 1,
|
|
|
|
$rightField => 10
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testRecoverUsingParentModeAndDelete method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRecoverUsingParentModeAndDelete() {
|
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2012-11-13 10:18:17 +00:00
|
|
|
$this->Tree->Behaviors->disable('Tree');
|
|
|
|
|
2012-11-13 20:12:46 +00:00
|
|
|
$this->Tree->save(array('name' => 'Main', $parentField => null, $leftField => 0, $rightField => 0));
|
2012-11-13 10:18:17 +00:00
|
|
|
$node1 = $this->Tree->id;
|
|
|
|
|
|
|
|
$this->Tree->create();
|
2012-11-13 20:12:46 +00:00
|
|
|
$this->Tree->save(array('name' => 'About Us', $parentField => $node1, $leftField => 0, $rightField => 0));
|
2012-11-14 08:55:33 +00:00
|
|
|
$node11 = $this->Tree->id;
|
2012-11-13 10:18:17 +00:00
|
|
|
$this->Tree->create();
|
2012-11-13 20:12:46 +00:00
|
|
|
$this->Tree->save(array('name' => 'Programs', $parentField => $node1, $leftField => 0, $rightField => 0));
|
2012-11-14 08:55:33 +00:00
|
|
|
$node12 = $this->Tree->id;
|
2012-11-13 10:18:17 +00:00
|
|
|
$this->Tree->create();
|
2012-11-13 20:12:46 +00:00
|
|
|
$this->Tree->save(array('name' => 'Mission and History', $parentField => $node11, $leftField => 0, $rightField => 0));
|
2012-11-13 10:18:17 +00:00
|
|
|
$this->Tree->create();
|
2012-11-13 20:12:46 +00:00
|
|
|
$this->Tree->save(array('name' => 'Overview', $parentField => $node12, $leftField => 0, $rightField => 0));
|
2012-11-13 10:18:17 +00:00
|
|
|
$this->Tree->create();
|
2012-11-13 20:12:46 +00:00
|
|
|
$this->Tree->save(array('name' => 'Lost', $parentField => 9, $leftField => 0, $rightField => 0));
|
2012-11-13 10:18:17 +00:00
|
|
|
|
|
|
|
$this->Tree->Behaviors->enable('Tree');
|
|
|
|
|
2012-11-13 20:12:46 +00:00
|
|
|
$this->Tree->bindModel(array('belongsTo' => array('Parent' => array(
|
|
|
|
'className' => $this->Tree->name,
|
|
|
|
'foreignKey' => $parentField
|
|
|
|
))));
|
|
|
|
$this->Tree->bindModel(array('hasMany' => array('Child' => array(
|
|
|
|
'className' => $this->Tree->name,
|
|
|
|
'foreignKey' => $parentField
|
|
|
|
))));
|
|
|
|
|
2012-11-13 10:18:17 +00:00
|
|
|
$result = $this->Tree->verify();
|
|
|
|
$this->assertNotSame($result, true);
|
|
|
|
|
|
|
|
$count = $this->Tree->find('count');
|
|
|
|
$this->assertEquals(6, $count);
|
|
|
|
|
|
|
|
$result = $this->Tree->recover('parent', 'delete');
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$result = $this->Tree->verify();
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$count = $this->Tree->find('count');
|
|
|
|
$this->assertEquals(5, $count);
|
|
|
|
|
2011-12-18 09:34:26 +00:00
|
|
|
$result = $this->Tree->find('first', array(
|
|
|
|
'fields' => array('name', $parentField, $leftField, $rightField),
|
|
|
|
'conditions' => array('name' => 'Main'),
|
|
|
|
'recursive' => -1
|
|
|
|
));
|
|
|
|
$expected = array(
|
|
|
|
$modelClass => array(
|
|
|
|
'name' => 'Main',
|
|
|
|
$parentField => null,
|
|
|
|
$leftField => 1,
|
|
|
|
$rightField => 10
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
2011-05-14 15:28:58 +00:00
|
|
|
/**
|
|
|
|
* testRecoverFromMissingParent method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRecoverFromMissingParent() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
|
|
|
|
$result = $this->Tree->findByName('1.1');
|
|
|
|
$this->Tree->updateAll(array($parentField => 999999), array('id' => $result[$modelClass]['id']));
|
|
|
|
|
|
|
|
$result = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertNotSame($result, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$result = $this->Tree->recover();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($result, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$result = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($result, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testDetectInvalidParents method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDetectInvalidParents() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
|
|
|
|
$this->Tree->updateAll(array($parentField => null));
|
|
|
|
|
|
|
|
$result = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertNotSame($result, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$result = $this->Tree->recover();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($result, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$result = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($result, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testDetectInvalidLftsRghts method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDetectInvalidLftsRghts() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
|
|
|
|
$this->Tree->updateAll(array($leftField => 0, $rightField => 0));
|
|
|
|
|
|
|
|
$result = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertNotSame($result, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$this->Tree->recover();
|
|
|
|
|
|
|
|
$result = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($result, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reproduces a situation where a single node has lft= rght, and all other lft and rght fields follow sequentially
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDetectEqualLftsRghts() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(1, 3);
|
|
|
|
|
|
|
|
$result = $this->Tree->findByName('1.1');
|
|
|
|
$this->Tree->updateAll(array($rightField => $result[$modelClass][$leftField]), array('id' => $result[$modelClass]['id']));
|
|
|
|
$this->Tree->updateAll(array($leftField => $this->Tree->escapeField($leftField) . ' -1'),
|
|
|
|
array($leftField . ' >' => $result[$modelClass][$leftField]));
|
|
|
|
$this->Tree->updateAll(array($rightField => $this->Tree->escapeField($rightField) . ' -1'),
|
|
|
|
array($rightField . ' >' => $result[$modelClass][$leftField]));
|
|
|
|
|
|
|
|
$result = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertNotSame($result, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$result = $this->Tree->recover();
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$result = $this->Tree->verify();
|
|
|
|
$this->assertTrue($result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testAddOrphan method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testAddOrphan() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
|
|
|
|
$this->Tree->save(array($modelClass => array('name' => 'testAddOrphan', $parentField => null)));
|
|
|
|
$result = $this->Tree->find('first', array('fields' => array('name', $parentField), 'order' => $modelClass . '.' . $leftField . ' desc'));
|
|
|
|
$expected = array($modelClass => array('name' => 'testAddOrphan', $parentField => null));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$validTree = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($validTree, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testAddMiddle method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testAddMiddle() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
|
|
|
|
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1')));
|
|
|
|
$initialCount = $this->Tree->find('count');
|
|
|
|
|
|
|
|
$this->Tree->create();
|
|
|
|
$result = $this->Tree->save(array($modelClass => array('name' => 'testAddMiddle', $parentField => $data[$modelClass]['id'])));
|
|
|
|
$expected = array_merge(array($modelClass => array('name' => 'testAddMiddle', $parentField => '2')), $result);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($expected, $result);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$laterCount = $this->Tree->find('count');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($initialCount + 1, $laterCount);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$children = $this->Tree->children($data[$modelClass]['id'], true, array('name'));
|
|
|
|
$expects = array(array($modelClass => array('name' => '1.1.1')),
|
|
|
|
array($modelClass => array('name' => '1.1.2')),
|
|
|
|
array($modelClass => array('name' => 'testAddMiddle')));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($children, $expects);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$validTree = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($validTree, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
2012-10-10 11:51:16 +00:00
|
|
|
/**
|
|
|
|
* testAddWithPreSpecifiedId method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testAddWithPreSpecifiedId() {
|
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2012-10-10 11:51:16 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
|
|
|
|
$data = $this->Tree->find('first', array(
|
|
|
|
'fields' => array('id'),
|
|
|
|
'conditions' => array($modelClass . '.name' => '1.1')
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->Tree->create();
|
|
|
|
$result = $this->Tree->save(array($modelClass => array(
|
|
|
|
'id' => 100,
|
|
|
|
'name' => 'testAddMiddle',
|
|
|
|
$parentField => $data[$modelClass]['id'])
|
|
|
|
));
|
|
|
|
$expected = array_merge(
|
|
|
|
array($modelClass => array('id' => 100, 'name' => 'testAddMiddle', $parentField => '2')),
|
|
|
|
$result
|
|
|
|
);
|
|
|
|
$this->assertSame($expected, $result);
|
|
|
|
|
|
|
|
$this->assertTrue($this->Tree->verify());
|
|
|
|
}
|
|
|
|
|
2011-05-14 15:28:58 +00:00
|
|
|
/**
|
|
|
|
* testAddInvalid method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testAddInvalid() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
$this->Tree->id = null;
|
|
|
|
|
|
|
|
$initialCount = $this->Tree->find('count');
|
|
|
|
//$this->expectError('Trying to save a node under a none-existant node in TreeBehavior::beforeSave');
|
|
|
|
|
|
|
|
$saveSuccess = $this->Tree->save(array($modelClass => array('name' => 'testAddInvalid', $parentField => 99999)));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($saveSuccess, false);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$laterCount = $this->Tree->find('count');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($initialCount, $laterCount);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$validTree = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($validTree, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testAddNotIndexedByModel method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testAddNotIndexedByModel() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
|
|
|
|
$this->Tree->save(array('name' => 'testAddNotIndexed', $parentField => null));
|
|
|
|
$result = $this->Tree->find('first', array('fields' => array('name', $parentField), 'order' => $modelClass . '.' . $leftField . ' desc'));
|
|
|
|
$expected = array($modelClass => array('name' => 'testAddNotIndexed', $parentField => null));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$validTree = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($validTree, true);
|
2012-03-18 18:31:13 +00:00
|
|
|
}
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* testMovePromote method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMovePromote() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
$this->Tree->id = null;
|
|
|
|
|
|
|
|
$parent = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1. Root')));
|
2012-03-18 18:31:13 +00:00
|
|
|
$parentId = $parent[$modelClass]['id'];
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1.1')));
|
2012-03-18 18:31:13 +00:00
|
|
|
$this->Tree->id = $data[$modelClass]['id'];
|
|
|
|
$this->Tree->saveField($parentField, $parentId);
|
|
|
|
$direct = $this->Tree->children($parentId, true, array('id', 'name', $parentField, $leftField, $rightField));
|
2011-05-14 15:28:58 +00:00
|
|
|
$expects = array(array($modelClass => array('id' => 2, 'name' => '1.1', $parentField => 1, $leftField => 2, $rightField => 5)),
|
|
|
|
array($modelClass => array('id' => 5, 'name' => '1.2', $parentField => 1, $leftField => 6, $rightField => 11)),
|
|
|
|
array($modelClass => array('id' => 3, 'name' => '1.1.1', $parentField => 1, $leftField => 12, $rightField => 13)));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($direct, $expects);
|
2011-05-14 15:28:58 +00:00
|
|
|
$validTree = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($validTree, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testMoveWithWhitelist method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMoveWithWhitelist() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
$this->Tree->id = null;
|
|
|
|
|
|
|
|
$parent = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1. Root')));
|
2012-03-18 18:31:13 +00:00
|
|
|
$parentId = $parent[$modelClass]['id'];
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1.1')));
|
|
|
|
$this->Tree->id = $data[$modelClass]['id'];
|
|
|
|
$this->Tree->whitelist = array($parentField, 'name', 'description');
|
2012-03-18 18:31:13 +00:00
|
|
|
$this->Tree->saveField($parentField, $parentId);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
2012-03-18 18:31:13 +00:00
|
|
|
$result = $this->Tree->children($parentId, true, array('id', 'name', $parentField, $leftField, $rightField));
|
2011-05-14 15:28:58 +00:00
|
|
|
$expected = array(array($modelClass => array('id' => 2, 'name' => '1.1', $parentField => 1, $leftField => 2, $rightField => 5)),
|
|
|
|
array($modelClass => array('id' => 5, 'name' => '1.2', $parentField => 1, $leftField => 6, $rightField => 11)),
|
|
|
|
array($modelClass => array('id' => 3, 'name' => '1.1.1', $parentField => 1, $leftField => 12, $rightField => 13)));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->assertTrue($this->Tree->verify());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testInsertWithWhitelist method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testInsertWithWhitelist() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
|
|
|
|
$this->Tree->whitelist = array('name', $parentField);
|
|
|
|
$this->Tree->save(array($modelClass => array('name' => 'testAddOrphan', $parentField => null)));
|
|
|
|
$result = $this->Tree->findByName('testAddOrphan', array('name', $parentField, $leftField, $rightField));
|
|
|
|
$expected = array('name' => 'testAddOrphan', $parentField => null, $leftField => '15', $rightField => 16);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expected, $result[$modelClass]);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($this->Tree->verify(), true);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testMoveBefore method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMoveBefore() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
$this->Tree->id = null;
|
|
|
|
|
|
|
|
$parent = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1.1')));
|
2012-03-18 18:31:13 +00:00
|
|
|
$parentId = $parent[$modelClass]['id'];
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.2')));
|
|
|
|
$this->Tree->id = $data[$modelClass]['id'];
|
2012-03-18 18:31:13 +00:00
|
|
|
$this->Tree->saveField($parentField, $parentId);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
2012-03-18 18:31:13 +00:00
|
|
|
$result = $this->Tree->children($parentId, true, array('name'));
|
2011-05-14 15:28:58 +00:00
|
|
|
$expects = array(array($modelClass => array('name' => '1.1.1')),
|
|
|
|
array($modelClass => array('name' => '1.1.2')),
|
|
|
|
array($modelClass => array('name' => '1.2')));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expects, $result);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$validTree = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($validTree, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testMoveAfter method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMoveAfter() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
$this->Tree->id = null;
|
|
|
|
|
|
|
|
$parent = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1.2')));
|
2012-03-18 18:31:13 +00:00
|
|
|
$parentId = $parent[$modelClass]['id'];
|
2011-05-14 15:28:58 +00:00
|
|
|
|
2012-03-18 18:31:13 +00:00
|
|
|
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1')));
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->id = $data[$modelClass]['id'];
|
2012-03-18 18:31:13 +00:00
|
|
|
$this->Tree->saveField($parentField, $parentId);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
2012-03-18 18:31:13 +00:00
|
|
|
$result = $this->Tree->children($parentId, true, array('name'));
|
2011-05-14 15:28:58 +00:00
|
|
|
$expects = array(array($modelClass => array('name' => '1.2.1')),
|
|
|
|
array($modelClass => array('name' => '1.2.2')),
|
|
|
|
array($modelClass => array('name' => '1.1')));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expects, $result);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$validTree = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($validTree, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testMoveDemoteInvalid method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMoveDemoteInvalid() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
$this->Tree->id = null;
|
|
|
|
|
|
|
|
$parent = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1. Root')));
|
2012-03-18 18:31:13 +00:00
|
|
|
$parentId = $parent[$modelClass]['id'];
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1.1')));
|
|
|
|
|
|
|
|
$expects = $this->Tree->find('all');
|
|
|
|
$before = $this->Tree->read(null, $data[$modelClass]['id']);
|
|
|
|
|
2012-03-18 18:31:13 +00:00
|
|
|
$this->Tree->id = $parentId;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->saveField($parentField, $data[$modelClass]['id']);
|
|
|
|
|
|
|
|
$results = $this->Tree->find('all');
|
|
|
|
$after = $this->Tree->read(null, $data[$modelClass]['id']);
|
|
|
|
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expects, $results);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($before, $after);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$validTree = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($validTree, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testMoveInvalid method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMoveInvalid() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
$this->Tree->id = null;
|
|
|
|
|
|
|
|
$initialCount = $this->Tree->find('count');
|
2012-03-18 18:31:13 +00:00
|
|
|
$data = $this->Tree->findByName('1.1');
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$this->Tree->id = $data[$modelClass]['id'];
|
|
|
|
$this->Tree->saveField($parentField, 999999);
|
|
|
|
|
|
|
|
$laterCount = $this->Tree->find('count');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($initialCount, $laterCount);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$validTree = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($validTree, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testMoveSelfInvalid method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMoveSelfInvalid() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
$this->Tree->id = null;
|
|
|
|
|
|
|
|
$initialCount = $this->Tree->find('count');
|
2012-03-18 18:31:13 +00:00
|
|
|
$data = $this->Tree->findByName('1.1');
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$this->Tree->id = $data[$modelClass]['id'];
|
|
|
|
$saveSuccess = $this->Tree->saveField($parentField, $this->Tree->id);
|
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($saveSuccess, false);
|
2011-05-14 15:28:58 +00:00
|
|
|
$laterCount = $this->Tree->find('count');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($initialCount, $laterCount);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$validTree = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($validTree, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testMoveUpSuccess method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMoveUpSuccess() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
|
|
|
|
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.2')));
|
|
|
|
$this->Tree->moveUp($data[$modelClass]['id']);
|
|
|
|
|
|
|
|
$parent = $this->Tree->findByName('1. Root', array('id'));
|
|
|
|
$this->Tree->id = $parent[$modelClass]['id'];
|
|
|
|
$result = $this->Tree->children(null, true, array('name'));
|
2012-09-28 11:49:51 +00:00
|
|
|
$expected = array(array($modelClass => array('name' => '1.2')),
|
|
|
|
array($modelClass => array('name' => '1.1')));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($expected, $result);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testMoveUpFail method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMoveUpFail() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
|
|
|
|
$data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1.1')));
|
|
|
|
|
|
|
|
$this->Tree->moveUp($data[$modelClass]['id']);
|
|
|
|
|
|
|
|
$parent = $this->Tree->findByName('1. Root', array('id'));
|
|
|
|
$this->Tree->id = $parent[$modelClass]['id'];
|
|
|
|
$result = $this->Tree->children(null, true, array('name'));
|
2012-09-28 11:49:51 +00:00
|
|
|
$expected = array(array($modelClass => array('name' => '1.1')),
|
|
|
|
array($modelClass => array('name' => '1.2')));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($expected, $result);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testMoveUp2 method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMoveUp2() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(1, 10);
|
|
|
|
|
|
|
|
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.5')));
|
|
|
|
$this->Tree->moveUp($data[$modelClass]['id'], 2);
|
|
|
|
|
|
|
|
$parent = $this->Tree->findByName('1. Root', array('id'));
|
|
|
|
$this->Tree->id = $parent[$modelClass]['id'];
|
|
|
|
$result = $this->Tree->children(null, true, array('name'));
|
|
|
|
$expected = array(
|
2012-09-28 11:49:51 +00:00
|
|
|
array($modelClass => array('name' => '1.1')),
|
|
|
|
array($modelClass => array('name' => '1.2')),
|
|
|
|
array($modelClass => array('name' => '1.5')),
|
|
|
|
array($modelClass => array('name' => '1.3')),
|
|
|
|
array($modelClass => array('name' => '1.4')),
|
|
|
|
array($modelClass => array('name' => '1.6')),
|
|
|
|
array($modelClass => array('name' => '1.7')),
|
|
|
|
array($modelClass => array('name' => '1.8')),
|
|
|
|
array($modelClass => array('name' => '1.9')),
|
|
|
|
array($modelClass => array('name' => '1.10')));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($expected, $result);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testMoveUpFirst method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMoveUpFirst() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(1, 10);
|
|
|
|
|
|
|
|
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.5')));
|
|
|
|
$this->Tree->moveUp($data[$modelClass]['id'], true);
|
|
|
|
|
|
|
|
$parent = $this->Tree->findByName('1. Root', array('id'));
|
|
|
|
$this->Tree->id = $parent[$modelClass]['id'];
|
|
|
|
$result = $this->Tree->children(null, true, array('name'));
|
|
|
|
$expected = array(
|
2012-09-28 11:49:51 +00:00
|
|
|
array($modelClass => array('name' => '1.5')),
|
|
|
|
array($modelClass => array('name' => '1.1')),
|
|
|
|
array($modelClass => array('name' => '1.2')),
|
|
|
|
array($modelClass => array('name' => '1.3')),
|
|
|
|
array($modelClass => array('name' => '1.4')),
|
|
|
|
array($modelClass => array('name' => '1.6')),
|
|
|
|
array($modelClass => array('name' => '1.7')),
|
|
|
|
array($modelClass => array('name' => '1.8')),
|
|
|
|
array($modelClass => array('name' => '1.9')),
|
|
|
|
array($modelClass => array('name' => '1.10')));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($expected, $result);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testMoveDownSuccess method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMoveDownSuccess() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
|
|
|
|
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1')));
|
|
|
|
$this->Tree->moveDown($data[$modelClass]['id']);
|
|
|
|
|
|
|
|
$parent = $this->Tree->findByName('1. Root', array('id'));
|
|
|
|
$this->Tree->id = $parent[$modelClass]['id'];
|
|
|
|
$result = $this->Tree->children(null, true, array('name'));
|
2012-09-28 11:49:51 +00:00
|
|
|
$expected = array(array($modelClass => array('name' => '1.2')),
|
|
|
|
array($modelClass => array('name' => '1.1')));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($expected, $result);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testMoveDownFail method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMoveDownFail() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
|
|
|
|
$data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1.2')));
|
|
|
|
$this->Tree->moveDown($data[$modelClass]['id']);
|
|
|
|
|
|
|
|
$parent = $this->Tree->findByName('1. Root', array('id'));
|
|
|
|
$this->Tree->id = $parent[$modelClass]['id'];
|
|
|
|
$result = $this->Tree->children(null, true, array('name'));
|
2012-09-28 11:49:51 +00:00
|
|
|
$expected = array(array($modelClass => array('name' => '1.1')),
|
|
|
|
array($modelClass => array('name' => '1.2')));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($expected, $result);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testMoveDownLast method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMoveDownLast() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(1, 10);
|
|
|
|
|
|
|
|
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.5')));
|
|
|
|
$this->Tree->moveDown($data[$modelClass]['id'], true);
|
|
|
|
|
|
|
|
$parent = $this->Tree->findByName('1. Root', array('id'));
|
|
|
|
$this->Tree->id = $parent[$modelClass]['id'];
|
|
|
|
$result = $this->Tree->children(null, true, array('name'));
|
|
|
|
$expected = array(
|
2012-09-28 11:49:51 +00:00
|
|
|
array($modelClass => array('name' => '1.1')),
|
|
|
|
array($modelClass => array('name' => '1.2')),
|
|
|
|
array($modelClass => array('name' => '1.3')),
|
|
|
|
array($modelClass => array('name' => '1.4')),
|
|
|
|
array($modelClass => array('name' => '1.6')),
|
|
|
|
array($modelClass => array('name' => '1.7')),
|
|
|
|
array($modelClass => array('name' => '1.8')),
|
|
|
|
array($modelClass => array('name' => '1.9')),
|
|
|
|
array($modelClass => array('name' => '1.10')),
|
|
|
|
array($modelClass => array('name' => '1.5')));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($expected, $result);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testMoveDown2 method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMoveDown2() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(1, 10);
|
|
|
|
|
|
|
|
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.5')));
|
|
|
|
$this->Tree->moveDown($data[$modelClass]['id'], 2);
|
|
|
|
|
|
|
|
$parent = $this->Tree->findByName('1. Root', array('id'));
|
|
|
|
$this->Tree->id = $parent[$modelClass]['id'];
|
|
|
|
$result = $this->Tree->children(null, true, array('name'));
|
|
|
|
$expected = array(
|
2012-09-28 11:49:51 +00:00
|
|
|
array($modelClass => array('name' => '1.1')),
|
|
|
|
array($modelClass => array('name' => '1.2')),
|
|
|
|
array($modelClass => array('name' => '1.3')),
|
|
|
|
array($modelClass => array('name' => '1.4')),
|
|
|
|
array($modelClass => array('name' => '1.6')),
|
|
|
|
array($modelClass => array('name' => '1.7')),
|
|
|
|
array($modelClass => array('name' => '1.5')),
|
|
|
|
array($modelClass => array('name' => '1.8')),
|
|
|
|
array($modelClass => array('name' => '1.9')),
|
|
|
|
array($modelClass => array('name' => '1.10')));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($expected, $result);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testSaveNoMove method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSaveNoMove() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(1, 10);
|
|
|
|
|
|
|
|
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.5')));
|
|
|
|
$this->Tree->id = $data[$modelClass]['id'];
|
|
|
|
$this->Tree->saveField('name', 'renamed');
|
|
|
|
$parent = $this->Tree->findByName('1. Root', array('id'));
|
|
|
|
$this->Tree->id = $parent[$modelClass]['id'];
|
|
|
|
$result = $this->Tree->children(null, true, array('name'));
|
|
|
|
$expected = array(
|
2012-09-28 11:49:51 +00:00
|
|
|
array($modelClass => array('name' => '1.1')),
|
|
|
|
array($modelClass => array('name' => '1.2')),
|
|
|
|
array($modelClass => array('name' => '1.3')),
|
|
|
|
array($modelClass => array('name' => '1.4')),
|
|
|
|
array($modelClass => array('name' => 'renamed')),
|
|
|
|
array($modelClass => array('name' => '1.6')),
|
|
|
|
array($modelClass => array('name' => '1.7')),
|
|
|
|
array($modelClass => array('name' => '1.8')),
|
|
|
|
array($modelClass => array('name' => '1.9')),
|
|
|
|
array($modelClass => array('name' => '1.10')));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($expected, $result);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testMoveToRootAndMoveUp method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMoveToRootAndMoveUp() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(1, 1);
|
|
|
|
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1')));
|
|
|
|
$this->Tree->id = $data[$modelClass]['id'];
|
|
|
|
$this->Tree->save(array($parentField => null));
|
|
|
|
|
|
|
|
$result = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($result, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$this->Tree->moveUp();
|
|
|
|
|
|
|
|
$result = $this->Tree->find('all', array('fields' => 'name', 'order' => $modelClass . '.' . $leftField . ' ASC'));
|
|
|
|
$expected = array(array($modelClass => array('name' => '1.1')),
|
|
|
|
array($modelClass => array('name' => '1. Root')));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($expected, $result);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testDelete method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDelete() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
|
|
|
|
$initialCount = $this->Tree->find('count');
|
|
|
|
$result = $this->Tree->findByName('1.1.1');
|
|
|
|
|
|
|
|
$return = $this->Tree->delete($result[$modelClass]['id']);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(true, $return);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$laterCount = $this->Tree->find('count');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($initialCount - 1, $laterCount);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
2012-03-18 18:31:13 +00:00
|
|
|
$validTree = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($validTree, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$initialCount = $this->Tree->find('count');
|
2012-03-18 18:31:13 +00:00
|
|
|
$result = $this->Tree->findByName('1.1');
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$return = $this->Tree->delete($result[$modelClass]['id']);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(true, $return);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$laterCount = $this->Tree->find('count');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($initialCount - 2, $laterCount);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$validTree = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($validTree, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
2012-07-14 19:54:07 +00:00
|
|
|
/**
|
|
|
|
* Test deleting a record that doesn't exist.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testDeleteDoesNotExist() {
|
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2012-07-14 19:54:07 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
$this->Tree->delete(99999);
|
|
|
|
}
|
|
|
|
|
2011-05-14 15:28:58 +00:00
|
|
|
/**
|
|
|
|
* testRemove method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRemove() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
$initialCount = $this->Tree->find('count');
|
|
|
|
$result = $this->Tree->findByName('1.1');
|
|
|
|
|
|
|
|
$this->Tree->removeFromTree($result[$modelClass]['id']);
|
|
|
|
|
|
|
|
$laterCount = $this->Tree->find('count');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($initialCount, $laterCount);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$children = $this->Tree->children($result[$modelClass][$parentField], true, array('name'));
|
|
|
|
$expects = array(array($modelClass => array('name' => '1.1.1')),
|
|
|
|
array($modelClass => array('name' => '1.1.2')),
|
|
|
|
array($modelClass => array('name' => '1.2')));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($children, $expects);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
2013-05-17 08:36:17 +00:00
|
|
|
$topNodes = $this->Tree->children(false, true, array('name'));
|
2011-05-14 15:28:58 +00:00
|
|
|
$expects = array(array($modelClass => array('name' => '1. Root')),
|
|
|
|
array($modelClass => array('name' => '1.1')));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($topNodes, $expects);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$validTree = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($validTree, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testRemoveLastTopParent method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRemoveLastTopParent() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
|
|
|
|
$initialCount = $this->Tree->find('count');
|
|
|
|
$initialTopNodes = $this->Tree->childCount(false);
|
|
|
|
|
|
|
|
$result = $this->Tree->findByName('1. Root');
|
|
|
|
$this->Tree->removeFromTree($result[$modelClass]['id']);
|
|
|
|
|
|
|
|
$laterCount = $this->Tree->find('count');
|
|
|
|
$laterTopNodes = $this->Tree->childCount(false);
|
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($initialCount, $laterCount);
|
|
|
|
$this->assertEquals($initialTopNodes, $laterTopNodes);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
2013-05-17 08:36:17 +00:00
|
|
|
$topNodes = $this->Tree->children(false, true, array('name'));
|
2011-05-14 15:28:58 +00:00
|
|
|
$expects = array(array($modelClass => array('name' => '1.1')),
|
|
|
|
array($modelClass => array('name' => '1.2')),
|
|
|
|
array($modelClass => array('name' => '1. Root')));
|
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($topNodes, $expects);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$validTree = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($validTree, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testRemoveNoChildren method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRemoveNoChildren() {
|
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
$initialCount = $this->Tree->find('count');
|
|
|
|
|
|
|
|
$result = $this->Tree->findByName('1.1.1');
|
|
|
|
$this->Tree->removeFromTree($result[$modelClass]['id']);
|
|
|
|
|
|
|
|
$laterCount = $this->Tree->find('count');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($initialCount, $laterCount);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$nodes = $this->Tree->find('list', array('order' => $leftField));
|
|
|
|
$expects = array(
|
|
|
|
1 => '1. Root',
|
|
|
|
2 => '1.1',
|
|
|
|
4 => '1.1.2',
|
|
|
|
5 => '1.2',
|
|
|
|
6 => '1.2.1',
|
|
|
|
7 => '1.2.2',
|
|
|
|
3 => '1.1.1',
|
|
|
|
);
|
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($nodes, $expects);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$validTree = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($validTree, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testRemoveAndDelete method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRemoveAndDelete() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
|
|
|
|
$initialCount = $this->Tree->find('count');
|
|
|
|
$result = $this->Tree->findByName('1.1');
|
|
|
|
|
|
|
|
$this->Tree->removeFromTree($result[$modelClass]['id'], true);
|
|
|
|
|
|
|
|
$laterCount = $this->Tree->find('count');
|
2012-03-18 18:31:13 +00:00
|
|
|
$this->assertEquals($initialCount - 1, $laterCount);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$children = $this->Tree->children($result[$modelClass][$parentField], true, array('name'), $leftField . ' asc');
|
2012-03-18 18:31:13 +00:00
|
|
|
$expects = array(
|
|
|
|
array($modelClass => array('name' => '1.1.1')),
|
2011-05-14 15:28:58 +00:00
|
|
|
array($modelClass => array('name' => '1.1.2')),
|
2012-03-18 18:31:13 +00:00
|
|
|
array($modelClass => array('name' => '1.2'))
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($children, $expects);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
2013-05-17 08:36:17 +00:00
|
|
|
$topNodes = $this->Tree->children(false, true, array('name'));
|
2011-05-14 15:28:58 +00:00
|
|
|
$expects = array(array($modelClass => array('name' => '1. Root')));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($topNodes, $expects);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$validTree = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($validTree, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testRemoveAndDeleteNoChildren method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRemoveAndDeleteNoChildren() {
|
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
$initialCount = $this->Tree->find('count');
|
|
|
|
|
|
|
|
$result = $this->Tree->findByName('1.1.1');
|
|
|
|
$this->Tree->removeFromTree($result[$modelClass]['id'], true);
|
|
|
|
|
|
|
|
$laterCount = $this->Tree->find('count');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($initialCount - 1, $laterCount);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$nodes = $this->Tree->find('list', array('order' => $leftField));
|
|
|
|
$expects = array(
|
|
|
|
1 => '1. Root',
|
|
|
|
2 => '1.1',
|
|
|
|
4 => '1.1.2',
|
|
|
|
5 => '1.2',
|
|
|
|
6 => '1.2.1',
|
|
|
|
7 => '1.2.2',
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($nodes, $expects);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$validTree = $this->Tree->verify();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($validTree, true);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testChildren method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testChildren() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
|
|
|
|
$data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1. Root')));
|
2012-03-18 18:31:13 +00:00
|
|
|
$this->Tree->id = $data[$modelClass]['id'];
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$direct = $this->Tree->children(null, true, array('id', 'name', $parentField, $leftField, $rightField));
|
|
|
|
$expects = array(array($modelClass => array('id' => 2, 'name' => '1.1', $parentField => 1, $leftField => 2, $rightField => 7)),
|
|
|
|
array($modelClass => array('id' => 5, 'name' => '1.2', $parentField => 1, $leftField => 8, $rightField => 13)));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($direct, $expects);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$total = $this->Tree->children(null, null, array('id', 'name', $parentField, $leftField, $rightField));
|
|
|
|
$expects = array(array($modelClass => array('id' => 2, 'name' => '1.1', $parentField => 1, $leftField => 2, $rightField => 7)),
|
|
|
|
array($modelClass => array('id' => 3, 'name' => '1.1.1', $parentField => 2, $leftField => 3, $rightField => 4)),
|
|
|
|
array($modelClass => array('id' => 4, 'name' => '1.1.2', $parentField => 2, $leftField => 5, $rightField => 6)),
|
|
|
|
array($modelClass => array('id' => 5, 'name' => '1.2', $parentField => 1, $leftField => 8, $rightField => 13)),
|
2011-12-01 07:21:31 +00:00
|
|
|
array($modelClass => array('id' => 6, 'name' => '1.2.1', $parentField => 5, $leftField => 9, $rightField => 10)),
|
2011-05-14 15:28:58 +00:00
|
|
|
array($modelClass => array('id' => 7, 'name' => '1.2.2', $parentField => 5, $leftField => 11, $rightField => 12)));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($total, $expects);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(array(), $this->Tree->children(10000));
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testCountChildren method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCountChildren() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
|
|
|
|
$data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1. Root')));
|
|
|
|
$this->Tree->id = $data[$modelClass]['id'];
|
|
|
|
|
|
|
|
$direct = $this->Tree->childCount(null, true);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(2, $direct);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$total = $this->Tree->childCount();
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(6, $total);
|
2011-07-30 19:37:46 +00:00
|
|
|
|
|
|
|
$this->Tree->read(null, $data[$modelClass]['id']);
|
|
|
|
$id = $this->Tree->field('id', array($modelClass . '.name' => '1.2'));
|
|
|
|
$total = $this->Tree->childCount($id);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(2, $total);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testGetParentNode method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testGetParentNode() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
|
|
|
|
$data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1.2.2')));
|
2012-03-18 18:31:13 +00:00
|
|
|
$this->Tree->id = $data[$modelClass]['id'];
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$result = $this->Tree->getParentNode(null, array('name'));
|
|
|
|
$expects = array($modelClass => array('name' => '1.2'));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertSame($expects, $result);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testGetPath method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testGetPath() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
|
|
|
|
$data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1.2.2')));
|
2012-03-18 18:31:13 +00:00
|
|
|
$this->Tree->id = $data[$modelClass]['id'];
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$result = $this->Tree->getPath(null, array('name'));
|
|
|
|
$expects = array(array($modelClass => array('name' => '1. Root')),
|
|
|
|
array($modelClass => array('name' => '1.2')),
|
|
|
|
array($modelClass => array('name' => '1.2.2')));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertSame($expects, $result);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testNoAmbiguousColumn method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testNoAmbiguousColumn() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->bindModel(array('belongsTo' => array('Dummy' =>
|
|
|
|
array('className' => $modelClass, 'foreignKey' => $parentField, 'conditions' => array('Dummy.id' => null)))), false);
|
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
|
|
|
|
$data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1. Root')));
|
2012-03-18 18:31:13 +00:00
|
|
|
$this->Tree->id = $data[$modelClass]['id'];
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$direct = $this->Tree->children(null, true, array('id', 'name', $parentField, $leftField, $rightField));
|
|
|
|
$expects = array(array($modelClass => array('id' => 2, 'name' => '1.1', $parentField => 1, $leftField => 2, $rightField => 7)),
|
|
|
|
array($modelClass => array('id' => 5, 'name' => '1.2', $parentField => 1, $leftField => 8, $rightField => 13)));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($direct, $expects);
|
2011-05-14 15:28:58 +00:00
|
|
|
|
|
|
|
$total = $this->Tree->children(null, null, array('id', 'name', $parentField, $leftField, $rightField));
|
|
|
|
$expects = array(
|
|
|
|
array($modelClass => array('id' => 2, 'name' => '1.1', $parentField => 1, $leftField => 2, $rightField => 7)),
|
|
|
|
array($modelClass => array('id' => 3, 'name' => '1.1.1', $parentField => 2, $leftField => 3, $rightField => 4)),
|
|
|
|
array($modelClass => array('id' => 4, 'name' => '1.1.2', $parentField => 2, $leftField => 5, $rightField => 6)),
|
|
|
|
array($modelClass => array('id' => 5, 'name' => '1.2', $parentField => 1, $leftField => 8, $rightField => 13)),
|
2011-12-01 07:21:31 +00:00
|
|
|
array($modelClass => array('id' => 6, 'name' => '1.2.1', $parentField => 5, $leftField => 9, $rightField => 10)),
|
2011-05-14 15:28:58 +00:00
|
|
|
array($modelClass => array('id' => 7, 'name' => '1.2.2', $parentField => 5, $leftField => 11, $rightField => 12))
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($total, $expects);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testReorderTree method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testReorderTree() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(3, 3);
|
|
|
|
$nodes = $this->Tree->find('list', array('order' => $leftField));
|
|
|
|
|
|
|
|
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1')));
|
|
|
|
$this->Tree->moveDown($data[$modelClass]['id']);
|
|
|
|
|
|
|
|
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.2.1')));
|
|
|
|
$this->Tree->moveDown($data[$modelClass]['id']);
|
|
|
|
|
|
|
|
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.3.2.2')));
|
|
|
|
$this->Tree->moveDown($data[$modelClass]['id']);
|
|
|
|
|
|
|
|
$unsortedNodes = $this->Tree->find('list', array('order' => $leftField));
|
|
|
|
$this->assertEquals($nodes, $unsortedNodes);
|
|
|
|
$this->assertNotEquals(array_keys($nodes), array_keys($unsortedNodes));
|
|
|
|
|
|
|
|
$this->Tree->reorder();
|
|
|
|
$sortedNodes = $this->Tree->find('list', array('order' => $leftField));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($nodes, $sortedNodes);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test reordering large-ish trees with cacheQueries = true.
|
|
|
|
* This caused infinite loops when moving down elements as stale data is returned
|
|
|
|
* from the memory cache
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testReorderBigTreeWithQueryCaching() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(2, 10);
|
|
|
|
|
|
|
|
$original = $this->Tree->cacheQueries;
|
|
|
|
$this->Tree->cacheQueries = true;
|
|
|
|
$this->Tree->reorder(array('field' => 'name', 'direction' => 'DESC'));
|
|
|
|
$this->assertTrue($this->Tree->cacheQueries, 'cacheQueries was not restored after reorder(). %s');
|
|
|
|
$this->Tree->cacheQueries = $original;
|
|
|
|
}
|
2011-12-06 20:52:48 +00:00
|
|
|
|
2011-05-14 15:28:58 +00:00
|
|
|
/**
|
|
|
|
* testGenerateTreeListWithSelfJoin method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testGenerateTreeListWithSelfJoin() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->bindModel(array('belongsTo' => array('Dummy' =>
|
|
|
|
array('className' => $modelClass, 'foreignKey' => $parentField, 'conditions' => array('Dummy.id' => null)))), false);
|
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
|
|
|
|
$result = $this->Tree->generateTreeList();
|
|
|
|
$expected = array(1 => '1. Root', 2 => '_1.1', 3 => '__1.1.1', 4 => '__1.1.2', 5 => '_1.2', 6 => '__1.2.1', 7 => '__1.2.2');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($expected, $result);
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
|
|
|
|
2012-07-18 01:06:41 +00:00
|
|
|
/**
|
|
|
|
* Test the formatting options of generateTreeList()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testGenerateTreeListFormatting() {
|
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2012-07-18 01:06:41 +00:00
|
|
|
$this->Tree->initialize(2, 2);
|
|
|
|
|
|
|
|
$result = $this->Tree->generateTreeList(
|
|
|
|
null,
|
|
|
|
"{n}.$modelClass.id",
|
|
|
|
array('%s - %s', "{n}.$modelClass.id", "{n}.$modelClass.name")
|
|
|
|
);
|
|
|
|
$this->assertEquals('1 - 1. Root', $result[1]);
|
|
|
|
$this->assertEquals('_2 - 1.1', $result[2]);
|
|
|
|
$this->assertEquals('__3 - 1.1.1', $result[3]);
|
|
|
|
}
|
|
|
|
|
2011-05-14 15:28:58 +00:00
|
|
|
/**
|
|
|
|
* testArraySyntax method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testArraySyntax() {
|
2011-05-14 15:28:58 +00:00
|
|
|
extract($this->settings);
|
|
|
|
$this->Tree = new $modelClass();
|
2013-07-19 20:31:09 +00:00
|
|
|
$this->Tree->order = null;
|
2011-05-14 15:28:58 +00:00
|
|
|
$this->Tree->initialize(3, 3);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($this->Tree->childCount(2), $this->Tree->childCount(array('id' => 2)));
|
|
|
|
$this->assertSame($this->Tree->getParentNode(2), $this->Tree->getParentNode(array('id' => 2)));
|
|
|
|
$this->assertSame($this->Tree->getPath(4), $this->Tree->getPath(array('id' => 4)));
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|
2012-01-19 22:20:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* testFindThreaded method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testFindThreaded() {
|
|
|
|
$Model = new Person();
|
|
|
|
$Model->recursive = -1;
|
|
|
|
$Model->Behaviors->attach('Tree', array('parent' => 'mother_id'));
|
|
|
|
|
|
|
|
$result = $Model->find('threaded');
|
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'Person' => array(
|
|
|
|
'id' => '4',
|
|
|
|
'name' => 'mother - grand mother',
|
|
|
|
'mother_id' => '0',
|
|
|
|
'father_id' => '0'
|
|
|
|
),
|
|
|
|
'children' => array(
|
|
|
|
array(
|
|
|
|
'Person' => array(
|
|
|
|
'id' => '2',
|
|
|
|
'name' => 'mother',
|
|
|
|
'mother_id' => '4',
|
|
|
|
'father_id' => '5'
|
|
|
|
),
|
|
|
|
'children' => array(
|
|
|
|
array(
|
|
|
|
'Person' => array(
|
|
|
|
'id' => '1',
|
|
|
|
'name' => 'person',
|
|
|
|
'mother_id' => '2',
|
|
|
|
'father_id' => '3'
|
|
|
|
),
|
|
|
|
'children' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Person' => array(
|
|
|
|
'id' => '5',
|
|
|
|
'name' => 'mother - grand father',
|
|
|
|
'mother_id' => '0',
|
|
|
|
'father_id' => '0'
|
|
|
|
),
|
|
|
|
'children' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Person' => array(
|
|
|
|
'id' => '6',
|
|
|
|
'name' => 'father - grand mother',
|
|
|
|
'mother_id' => '0',
|
|
|
|
'father_id' => '0'
|
|
|
|
),
|
|
|
|
'children' => array(
|
|
|
|
array(
|
|
|
|
'Person' => array(
|
|
|
|
'id' => '3',
|
|
|
|
'name' => 'father',
|
|
|
|
'mother_id' => '6',
|
|
|
|
'father_id' => '7'
|
|
|
|
),
|
|
|
|
'children' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Person' => array(
|
|
|
|
'id' => '7',
|
|
|
|
'name' => 'father - grand father',
|
|
|
|
'mother_id' => '0',
|
|
|
|
'father_id' => '0'
|
|
|
|
),
|
|
|
|
'children' => array()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
2011-05-14 15:28:58 +00:00
|
|
|
}
|