mirror of
				https://github.com/brmlab/brmsklad.git
				synced 2025-10-31 08:13:58 +01:00 
			
		
		
		
	Upgrade CakePHP from 2.2.5 to 2.9.5
This commit is contained in:
		
							parent
							
								
									5a580df460
								
							
						
					
					
						commit
						235a541597
					
				
					 793 changed files with 60746 additions and 23753 deletions
				
			
		|  | @ -4,19 +4,18 @@ | |||
|  * | ||||
|  * Test the Acl Behavior | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP : Rapid Development Framework (http://cakephp.org) | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice. | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://cakephp.org CakePHP Project | ||||
|  * @package       Cake.Test.Case.Model.Behavior | ||||
|  * @since         CakePHP v 1.2.0.4487 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('AclBehavior', 'Model/Behavior'); | ||||
|  | @ -25,7 +24,6 @@ App::uses('Aro', 'Model'); | |||
| App::uses('AclNode', 'Model'); | ||||
| App::uses('DbAcl', 'Model'); | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * Test Person class - self joined model | ||||
|  * | ||||
|  | @ -33,13 +31,6 @@ App::uses('DbAcl', 'Model'); | |||
|  */ | ||||
| class AclPerson extends CakeTestModel { | ||||
| 
 | ||||
| /** | ||||
|  * name property | ||||
|  * | ||||
|  * @var string | ||||
|  */ | ||||
| 	public $name = 'AclPerson'; | ||||
| 
 | ||||
| /** | ||||
|  * useTable property | ||||
|  * | ||||
|  | @ -94,9 +85,8 @@ class AclPerson extends CakeTestModel { | |||
| 		} | ||||
| 		if (!$motherId) { | ||||
| 			return null; | ||||
| 		} else { | ||||
| 			return array('AclPerson' => array('id' => $motherId)); | ||||
| 		} | ||||
| 		return array('AclPerson' => array('id' => $motherId)); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
|  | @ -132,6 +122,7 @@ class AclUser extends CakeTestModel { | |||
| /** | ||||
|  * parentNode | ||||
|  * | ||||
|  * @return null | ||||
|  */ | ||||
| 	public function parentNode() { | ||||
| 		return null; | ||||
|  | @ -170,6 +161,7 @@ class AclPost extends CakeTestModel { | |||
| /** | ||||
|  * parentNode | ||||
|  * | ||||
|  * @return null | ||||
|  */ | ||||
| 	public function parentNode() { | ||||
| 		return null; | ||||
|  | @ -234,6 +226,7 @@ class AclBehaviorTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testSetup() { | ||||
| 		parent::setUp(); | ||||
| 		$User = new AclUser(); | ||||
| 		$this->assertTrue(isset($User->Behaviors->Acl->settings['User'])); | ||||
| 		$this->assertEquals('requester', $User->Behaviors->Acl->settings['User']['type']); | ||||
|  |  | |||
|  | @ -2,23 +2,23 @@ | |||
| /** | ||||
|  * ContainableBehaviorTest file | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html> | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests | ||||
|  * @package       Cake.Test.Case.Model.Behavior | ||||
|  * @since         CakePHP(tm) v 1.2.0.5669 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('Model', 'Model'); | ||||
| App::uses('AppModel', 'Model'); | ||||
| 
 | ||||
| require_once dirname(dirname(__FILE__)) . DS . 'models.php'; | ||||
| 
 | ||||
| /** | ||||
|  | @ -43,6 +43,7 @@ class ContainableBehaviorTest extends CakeTestCase { | |||
| /** | ||||
|  * Method executed before each test | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function setUp() { | ||||
| 		parent::setUp(); | ||||
|  | @ -60,14 +61,15 @@ class ContainableBehaviorTest extends CakeTestCase { | |||
| 			'hasAndBelongsToMany' => array('Article') | ||||
| 		), false); | ||||
| 
 | ||||
| 		$this->User->Behaviors->attach('Containable'); | ||||
| 		$this->Article->Behaviors->attach('Containable'); | ||||
| 		$this->Tag->Behaviors->attach('Containable'); | ||||
| 		$this->User->Behaviors->load('Containable'); | ||||
| 		$this->Article->Behaviors->load('Containable'); | ||||
| 		$this->Tag->Behaviors->load('Containable'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Method executed after each test | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function tearDown() { | ||||
| 		unset($this->Article); | ||||
|  | @ -152,7 +154,7 @@ class ContainableBehaviorTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testInvalidContainments() { | ||||
| 		$r = $this->_containments($this->Article, array('Comment', 'InvalidBinding')); | ||||
| 		$this->_containments($this->Article, array('Comment', 'InvalidBinding')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -161,8 +163,8 @@ class ContainableBehaviorTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testInvalidContainmentsNoNotices() { | ||||
| 		$this->Article->Behaviors->attach('Containable', array('notices' => false)); | ||||
| 		$r = $this->_containments($this->Article, array('Comment', 'InvalidBinding')); | ||||
| 		$this->Article->Behaviors->load('Containable', array('notices' => false)); | ||||
| 		$this->_containments($this->Article, array('Comment', 'InvalidBinding')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -243,7 +245,7 @@ class ContainableBehaviorTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testBeforeFindWithNonExistingBinding() { | ||||
| 		$r = $this->Article->find('all', array('contain' => array('Comment' => 'NonExistingBinding'))); | ||||
| 		$this->Article->find('all', array('contain' => array('Comment' => 'NonExistingBinding'))); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -261,6 +263,30 @@ class ContainableBehaviorTest extends CakeTestCase { | |||
| 		$this->assertFalse(Set::matches('/Comment/User', $r)); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testContainFindList method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testContainFindList() { | ||||
| 		$this->Article->contain('Comment.User'); | ||||
| 		$result = $this->Article->find('list'); | ||||
| 		$expected = array( | ||||
| 			1 => 'First Article', | ||||
| 			2 => 'Second Article', | ||||
| 			3 => 'Third Article' | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 
 | ||||
| 		$result = $this->Article->find('list', array('fields' => array('Article.id', 'User.id'), 'contain' => array('User'))); | ||||
| 		$expected = array( | ||||
| 			1 => '1', | ||||
| 			2 => '3', | ||||
| 			3 => '1' | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test that mixing contain() and the contain find option. | ||||
|  * | ||||
|  | @ -657,6 +683,65 @@ class ContainableBehaviorTest extends CakeTestCase { | |||
| 		); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 
 | ||||
| 		$this->Article->contain(array('User' => array('id', 'ArticleFeatured'))); | ||||
| 		$result = $this->Article->find('all', array('recursive' => 2)); | ||||
| 		$expected = array( | ||||
| 			array( | ||||
| 				'Article' => array( | ||||
| 					'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', | ||||
| 					'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' | ||||
| 				), | ||||
| 				'User' => array( | ||||
| 					'id' => 1, | ||||
| 					'ArticleFeatured' => array( | ||||
| 						array( | ||||
| 							'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', | ||||
| 							'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' | ||||
| 						), | ||||
| 						array( | ||||
| 							'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', | ||||
| 							'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' | ||||
| 						) | ||||
| 					) | ||||
| 				) | ||||
| 			), | ||||
| 			array( | ||||
| 				'Article' => array( | ||||
| 					'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', | ||||
| 					'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' | ||||
| 				), | ||||
| 				'User' => array( | ||||
| 					'id' => 3, | ||||
| 					'ArticleFeatured' => array( | ||||
| 						array( | ||||
| 						'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', | ||||
| 						'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' | ||||
| 						) | ||||
| 					) | ||||
| 				) | ||||
| 			), | ||||
| 			array( | ||||
| 				'Article' => array( | ||||
| 					'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', | ||||
| 					'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' | ||||
| 				), | ||||
| 				'User' => array( | ||||
| 					'id' => 1, | ||||
| 					'ArticleFeatured' => array( | ||||
| 						array( | ||||
| 							'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', | ||||
| 							'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' | ||||
| 						), | ||||
| 						array( | ||||
| 							'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', | ||||
| 							'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' | ||||
| 						) | ||||
| 					) | ||||
| 				) | ||||
| 			) | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 
 | ||||
| 		$this->Article->contain(array('User' => array('ArticleFeatured', 'Comment'))); | ||||
| 		$result = $this->Article->find('all', array('recursive' => 2)); | ||||
| 		$expected = array( | ||||
|  | @ -3216,7 +3301,7 @@ class ContainableBehaviorTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testOriginalAssociations() { | ||||
| 		$this->Article->Comment->Behaviors->attach('Containable'); | ||||
| 		$this->Article->Comment->Behaviors->load('Containable'); | ||||
| 
 | ||||
| 		$options = array( | ||||
| 			'conditions' => array( | ||||
|  | @ -3228,7 +3313,7 @@ class ContainableBehaviorTest extends CakeTestCase { | |||
| 
 | ||||
| 		$firstResult = $this->Article->Comment->find('all', $options); | ||||
| 
 | ||||
| 		$dummyResult = $this->Article->Comment->find('all', array( | ||||
| 		$this->Article->Comment->find('all', array( | ||||
| 			'conditions' => array( | ||||
| 				'User.user' => 'mariano' | ||||
| 			), | ||||
|  | @ -3305,6 +3390,7 @@ class ContainableBehaviorTest extends CakeTestCase { | |||
| /** | ||||
|  * testResetAddedAssociation method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testResetAddedAssociation() { | ||||
| 		$this->assertTrue(empty($this->Article->hasMany['ArticlesTag'])); | ||||
|  | @ -3331,9 +3417,9 @@ class ContainableBehaviorTest extends CakeTestCase { | |||
| 		$this->JoinB = ClassRegistry::init('JoinB'); | ||||
| 		$this->JoinC = ClassRegistry::init('JoinC'); | ||||
| 
 | ||||
| 		$this->JoinA->Behaviors->attach('Containable'); | ||||
| 		$this->JoinB->Behaviors->attach('Containable'); | ||||
| 		$this->JoinC->Behaviors->attach('Containable'); | ||||
| 		$this->JoinA->Behaviors->load('Containable'); | ||||
| 		$this->JoinB->Behaviors->load('Containable'); | ||||
| 		$this->JoinC->Behaviors->load('Containable'); | ||||
| 
 | ||||
| 		$this->JoinA->JoinB->find('all', array('contain' => array('JoinA'))); | ||||
| 		$this->JoinA->bindModel(array('hasOne' => array('JoinAsJoinC' => array('joinTable' => 'as_cs'))), false); | ||||
|  | @ -3346,11 +3432,12 @@ class ContainableBehaviorTest extends CakeTestCase { | |||
| /** | ||||
|  * testResetAssociation method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testResetAssociation() { | ||||
| 		$this->Article->Behaviors->attach('Containable'); | ||||
| 		$this->Article->Comment->Behaviors->attach('Containable'); | ||||
| 		$this->Article->User->Behaviors->attach('Containable'); | ||||
| 		$this->Article->Behaviors->load('Containable'); | ||||
| 		$this->Article->Comment->Behaviors->load('Containable'); | ||||
| 		$this->Article->User->Behaviors->load('Containable'); | ||||
| 
 | ||||
| 		$initialOptions = array( | ||||
| 			'conditions' => array( | ||||
|  | @ -3377,6 +3464,7 @@ class ContainableBehaviorTest extends CakeTestCase { | |||
| /** | ||||
|  * testResetDeeperHasOneAssociations method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testResetDeeperHasOneAssociations() { | ||||
| 		$this->Article->User->unbindModel(array( | ||||
|  | @ -3437,23 +3525,24 @@ class ContainableBehaviorTest extends CakeTestCase { | |||
| /** | ||||
|  * testResetMultipleHabtmAssociations method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testResetMultipleHabtmAssociations() { | ||||
| 		$articleHabtm = array( | ||||
| 			'hasAndBelongsToMany' => array( | ||||
| 				'Tag' => array( | ||||
| 					'className'				=> 'Tag', | ||||
| 					'joinTable'				=> 'articles_tags', | ||||
| 					'foreignKey'			=> 'article_id', | ||||
| 					'className' => 'Tag', | ||||
| 					'joinTable' => 'articles_tags', | ||||
| 					'foreignKey' => 'article_id', | ||||
| 					'associationForeignKey' => 'tag_id' | ||||
| 				), | ||||
| 				'ShortTag' => array( | ||||
| 					'className'				=> 'Tag', | ||||
| 					'joinTable'				=> 'articles_tags', | ||||
| 					'foreignKey'			=> 'article_id', | ||||
| 					'className' => 'Tag', | ||||
| 					'joinTable' => 'articles_tags', | ||||
| 					'foreignKey' => 'article_id', | ||||
| 					'associationForeignKey' => 'tag_id', | ||||
| 					// LENGHT function mysql-only, using LIKE does almost the same
 | ||||
| 					'conditions' 			=> "ShortTag.tag LIKE '???'" | ||||
| 					// LENGTH function mysql-only, using LIKE does almost the same
 | ||||
| 					'conditions' => "ShortTag.tag LIKE '???'" | ||||
| 				) | ||||
| 			) | ||||
| 		); | ||||
|  | @ -3527,6 +3616,8 @@ class ContainableBehaviorTest extends CakeTestCase { | |||
| 
 | ||||
| /** | ||||
|  * test that bindModel and unbindModel work with find() calls in between. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testBindMultipleTimesWithFind() { | ||||
| 		$binding = array( | ||||
|  | @ -3647,11 +3738,10 @@ class ContainableBehaviorTest extends CakeTestCase { | |||
| 		if (!is_array($Model)) { | ||||
| 			$result = $Model->containments($contain); | ||||
| 			return $this->_containments($result['models']); | ||||
| 		} else { | ||||
| 			$result = $Model; | ||||
| 			foreach ($result as $i => $containment) { | ||||
| 				$result[$i] = array_diff_key($containment, array('instance' => true)); | ||||
| 			} | ||||
| 		} | ||||
| 		$result = $Model; | ||||
| 		foreach ($result as $i => $containment) { | ||||
| 			$result[$i] = array_diff_key($containment, array('instance' => true)); | ||||
| 		} | ||||
| 		return $result; | ||||
| 	} | ||||
|  | @ -3671,7 +3761,7 @@ class ContainableBehaviorTest extends CakeTestCase { | |||
| 			'hasAndBelongsToMany' => array() | ||||
| 		), $expected); | ||||
| 		foreach ($expected as $binding => $expect) { | ||||
| 			$this->assertEquals(array_keys($Model->$binding), $expect); | ||||
| 			$this->assertEquals($expect, array_keys($Model->$binding)); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  |  | |||
|  | @ -1,19 +1,21 @@ | |||
| <?php | ||||
| /** | ||||
|  * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html> | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests | ||||
|  * @since         CakePHP(tm) v 1.2.0.5669 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('Model', 'Model'); | ||||
| App::uses('AppModel', 'Model'); | ||||
| 
 | ||||
| require_once dirname(dirname(__FILE__)) . DS . 'models.php'; | ||||
| 
 | ||||
| /** | ||||
|  | @ -26,7 +28,7 @@ class TranslateBehaviorTest extends CakeTestCase { | |||
| /** | ||||
|  * autoFixtures property | ||||
|  * | ||||
|  * @var bool false | ||||
|  * @var bool | ||||
|  */ | ||||
| 	public $autoFixtures = false; | ||||
| 
 | ||||
|  | @ -68,13 +70,13 @@ class TranslateBehaviorTest extends CakeTestCase { | |||
| 		$this->loadFixtures('TranslateTable', 'Tag', 'TranslatedItem', 'Translate', 'User', 'TranslatedArticle', 'TranslateArticle'); | ||||
| 		$TestModel = new Tag(); | ||||
| 		$TestModel->translateTable = 'another_i18n'; | ||||
| 		$TestModel->Behaviors->attach('Translate', array('title')); | ||||
| 		$TestModel->Behaviors->load('Translate', array('title')); | ||||
| 		$translateModel = $TestModel->Behaviors->Translate->translateModel($TestModel); | ||||
| 		$this->assertEquals('I18nModel', $translateModel->name); | ||||
| 		$this->assertEquals('another_i18n', $translateModel->useTable); | ||||
| 
 | ||||
| 		$TestModel = new User(); | ||||
| 		$TestModel->Behaviors->attach('Translate', array('title')); | ||||
| 		$TestModel->Behaviors->load('Translate', array('title')); | ||||
| 		$translateModel = $TestModel->Behaviors->Translate->translateModel($TestModel); | ||||
| 		$this->assertEquals('I18nModel', $translateModel->name); | ||||
| 		$this->assertEquals('i18n', $translateModel->useTable); | ||||
|  | @ -230,6 +232,32 @@ class TranslateBehaviorTest extends CakeTestCase { | |||
| 			) | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 
 | ||||
| 		$result = $TestModel->field('title', array('TranslatedItem.id' => 1)); | ||||
| 		$expected = 'Title #1'; | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 
 | ||||
| 		$result = $TestModel->read('title', 1); | ||||
| 		$expected = array( | ||||
| 			'TranslatedItem' => array( | ||||
| 				'id' => 1, | ||||
| 				'slug' => 'first_translated', | ||||
| 				'locale' => 'eng', | ||||
| 				'title' => 'Title #1', | ||||
| 				'translated_article_id' => 1, | ||||
| 			) | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 
 | ||||
| 		$result = $TestModel->read('id, title', 1); | ||||
| 		$expected = array( | ||||
| 			'TranslatedItem' => array( | ||||
| 				'id' => 1, | ||||
| 				'locale' => 'eng', | ||||
| 				'title' => 'Title #1', | ||||
| 			) | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -273,6 +301,40 @@ class TranslateBehaviorTest extends CakeTestCase { | |||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testLocaleSingleCountWithConditions method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testLocaleSingleCountWithConditions() { | ||||
| 		$this->loadFixtures('Translate', 'TranslatedItem'); | ||||
| 
 | ||||
| 		$TestModel = new TranslatedItem(); | ||||
| 		$TestModel->locale = 'eng'; | ||||
| 		$result = $TestModel->find('all', array( | ||||
| 			'conditions' => array('slug' => 'first_translated') | ||||
| 		)); | ||||
| 		$expected = array( | ||||
| 			array( | ||||
| 				'TranslatedItem' => array( | ||||
| 					'id' => 1, | ||||
| 					'slug' => 'first_translated', | ||||
| 					'locale' => 'eng', | ||||
| 					'title' => 'Title #1', | ||||
| 					'content' => 'Content #1', | ||||
| 					'translated_article_id' => 1, | ||||
| 				) | ||||
| 			) | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 
 | ||||
| 		$result = $TestModel->find('count', array( | ||||
| 			'conditions' => array('slug' => 'first_translated') | ||||
| 		)); | ||||
| 		$expected = 1; | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testLocaleSingleAssociations method | ||||
|  * | ||||
|  | @ -352,6 +414,33 @@ class TranslateBehaviorTest extends CakeTestCase { | |||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test loading fields with 0 as the translated value. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testFetchTranslationsWithZero() { | ||||
| 		$this->loadFixtures('Translate', 'TranslatedItem'); | ||||
| 
 | ||||
| 		$model = new TranslatedItem(); | ||||
| 		$translateModel = $model->translateModel(); | ||||
| 		$translateModel->updateAll(array('content' => "'0'")); | ||||
| 		$model->locale = 'eng'; | ||||
| 
 | ||||
| 		$result = $model->read(null, 1); | ||||
| 		$expected = array( | ||||
| 			'TranslatedItem' => array( | ||||
| 				'id' => 1, | ||||
| 				'slug' => 'first_translated', | ||||
| 				'locale' => 'eng', | ||||
| 				'title' => '0', | ||||
| 				'content' => '0', | ||||
| 				'translated_article_id' => 1, | ||||
| 			) | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testLocaleMultiple method | ||||
|  * | ||||
|  | @ -530,6 +619,36 @@ class TranslateBehaviorTest extends CakeTestCase { | |||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test saving/deleting with an alias, uses the model name. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testSaveDeleteIgnoreAlias() { | ||||
| 		$this->loadFixtures('Translate', 'TranslatedItem'); | ||||
| 
 | ||||
| 		$TestModel = new TranslatedItem(array('alias' => 'SomethingElse')); | ||||
| 		$TestModel->locale = 'spa'; | ||||
| 		$data = array( | ||||
| 			'slug' => 'fourth_translated', | ||||
| 			'title' => 'Leyenda #4', | ||||
| 			'content' => 'Contenido #4', | ||||
| 			'translated_article_id' => 1, | ||||
| 		); | ||||
| 		$TestModel->create($data); | ||||
| 		$TestModel->save(); | ||||
| 		$id = $TestModel->id; | ||||
| 		$result = $TestModel->read(); | ||||
| 		$expected = array($TestModel->alias => array_merge($data, array('id' => $id, 'locale' => 'spa'))); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 
 | ||||
| 		$TestModel->delete($id); | ||||
| 		$result = $TestModel->translateModel()->find('count', array( | ||||
| 			'conditions' => array('foreign_key' => $id) | ||||
| 		)); | ||||
| 		$this->assertEquals(0, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test save multiple locales method | ||||
|  * | ||||
|  | @ -600,6 +719,54 @@ class TranslateBehaviorTest extends CakeTestCase { | |||
| 		$this->assertCount(2, $result['Content']); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testSaveAssociatedAtomic method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testSaveAssociatedAtomic() { | ||||
| 		$this->loadFixtures('Translate', 'TranslatedItem'); | ||||
| 
 | ||||
| 		$TestModel = new TranslatedItem(); | ||||
| 		$data = array( | ||||
| 			'slug' => 'fourth_translated', | ||||
| 			'title' => array( | ||||
| 				'eng' => 'Title #4' | ||||
| 			), | ||||
| 			'content' => array( | ||||
| 				'eng' => 'Content #4' | ||||
| 			), | ||||
| 			'translated_article_id' => 1, | ||||
| 		); | ||||
| 		$Mock = $this->getMockForModel('TranslateTestModel', array('save')); | ||||
| 		$TestModel->Behaviors->Translate->runtime[$TestModel->alias]['model'] = $Mock; | ||||
| 
 | ||||
| 		$with = array( | ||||
| 			'TranslateTestModel' => array ( | ||||
| 				'model' => 'TranslatedItem', | ||||
| 				'foreign_key' => '4', | ||||
| 				'field' => 'content', | ||||
| 				'locale' => 'eng', | ||||
| 				'content' => 'Content #4', | ||||
| 			) | ||||
| 		); | ||||
| 		$Mock->expects($this->at(0))->method('save')->with($with, array('atomic' => false)); | ||||
| 
 | ||||
| 		$with = array( | ||||
| 			'TranslateTestModel' => array ( | ||||
| 				'model' => 'TranslatedItem', | ||||
| 				'foreign_key' => '4', | ||||
| 				'field' => 'title', | ||||
| 				'locale' => 'eng', | ||||
| 				'content' => 'Title #4', | ||||
| 			) | ||||
| 		); | ||||
| 		$Mock->expects($this->at(1))->method('save')->with($with, array('atomic' => false)); | ||||
| 
 | ||||
| 		$TestModel->create(); | ||||
| 		$TestModel->saveAssociated($data, array('atomic' => false)); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test that saving only some of the translated fields allows the record to be found again. | ||||
|  * | ||||
|  | @ -628,6 +795,76 @@ class TranslateBehaviorTest extends CakeTestCase { | |||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test that all fields are create with partial data + multiple locales. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testSavePartialFieldMultipleLocales() { | ||||
| 		$this->loadFixtures('Translate', 'TranslatedItem'); | ||||
| 
 | ||||
| 		$TestModel = new TranslatedItem(); | ||||
| 		$TestModel->locale = 'eng'; | ||||
| 		$data = array( | ||||
| 			'slug' => 'fifth_translated', | ||||
| 			'title' => array('eng' => 'Title #5', 'spa' => 'Leyenda #5'), | ||||
| 		); | ||||
| 		$TestModel->create($data); | ||||
| 		$TestModel->save(); | ||||
| 		$TestModel->unbindTranslation(); | ||||
| 
 | ||||
| 		$translations = array('title' => 'Title', 'content' => 'Content'); | ||||
| 		$TestModel->bindTranslation($translations, false); | ||||
| 		$result = $TestModel->read(null, $TestModel->id); | ||||
| 		$expected = array( | ||||
| 			'TranslatedItem' => array( | ||||
| 				'id' => '4', | ||||
| 				'translated_article_id' => null, | ||||
| 				'slug' => 'fifth_translated', | ||||
| 				'locale' => 'eng', | ||||
| 				'title' => 'Title #5', | ||||
| 				'content' => '' | ||||
| 			), | ||||
| 			'Title' => array( | ||||
| 				0 => array( | ||||
| 					'id' => '19', | ||||
| 					'locale' => 'eng', | ||||
| 					'model' => 'TranslatedItem', | ||||
| 					'foreign_key' => '4', | ||||
| 					'field' => 'title', | ||||
| 					'content' => 'Title #5' | ||||
| 				), | ||||
| 				1 => array( | ||||
| 					'id' => '20', | ||||
| 					'locale' => 'spa', | ||||
| 					'model' => 'TranslatedItem', | ||||
| 					'foreign_key' => '4', | ||||
| 					'field' => 'title', | ||||
| 					'content' => 'Leyenda #5' | ||||
| 				) | ||||
| 			), | ||||
| 			'Content' => array( | ||||
| 				0 => array( | ||||
| 					'id' => '21', | ||||
| 					'locale' => 'eng', | ||||
| 					'model' => 'TranslatedItem', | ||||
| 					'foreign_key' => '4', | ||||
| 					'field' => 'content', | ||||
| 					'content' => '' | ||||
| 				), | ||||
| 				1 => array( | ||||
| 					'id' => '22', | ||||
| 					'locale' => 'spa', | ||||
| 					'model' => 'TranslatedItem', | ||||
| 					'foreign_key' => '4', | ||||
| 					'field' => 'content', | ||||
| 					'content' => '' | ||||
| 				) | ||||
| 			) | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testSaveUpdate method | ||||
|  * | ||||
|  | @ -705,7 +942,7 @@ class TranslateBehaviorTest extends CakeTestCase { | |||
| 
 | ||||
| 		$TestModel = new TranslatedItem(); | ||||
| 		$TestModel->locale = 'eng'; | ||||
| 		$TestModel->validate['title'] = 'notEmpty'; | ||||
| 		$TestModel->validate['title'] = 'notBlank'; | ||||
| 		$data = array('TranslatedItem' => array( | ||||
| 			'id' => 1, | ||||
| 			'title' => array('eng' => 'New Title #1', 'deu' => 'Neue Titel #1', 'cze' => 'Novy Titulek #1'), | ||||
|  | @ -841,6 +1078,7 @@ class TranslateBehaviorTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testValidation() { | ||||
| 		Configure::write('Config.language', 'eng'); | ||||
| 		$this->loadFixtures('Translate', 'TranslatedItem'); | ||||
| 
 | ||||
| 		$TestModel = new TranslatedItem(); | ||||
|  | @ -869,6 +1107,29 @@ class TranslateBehaviorTest extends CakeTestCase { | |||
| 		$this->assertFalse(empty($result)); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test restoring fields after temporary binds method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testFieldsRestoreAfterBind() { | ||||
| 		$this->loadFixtures('Translate', 'TranslatedItem'); | ||||
| 
 | ||||
| 		$TestModel = new TranslatedItem(); | ||||
| 
 | ||||
| 		$translations = array('title' => 'Title'); | ||||
| 		$TestModel->bindTranslation($translations); | ||||
| 
 | ||||
| 		$result = $TestModel->find('first'); | ||||
| 		$this->assertArrayHasKey('Title', $result); | ||||
| 		$this->assertArrayHasKey('content', $result['Title'][0]); | ||||
| 		$this->assertArrayNotHasKey('title', $result); | ||||
| 
 | ||||
| 		$result = $TestModel->find('first'); | ||||
| 		$this->assertArrayNotHasKey('Title', $result); | ||||
| 		$this->assertEquals('Title #1', $result['TranslatedItem']['title']); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testAttachDetach method | ||||
|  * | ||||
|  | @ -887,7 +1148,7 @@ class TranslateBehaviorTest extends CakeTestCase { | |||
| 		$expected = array('Title', 'Content'); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 
 | ||||
| 		$TestModel->Behaviors->detach('Translate'); | ||||
| 		$TestModel->Behaviors->unload('Translate'); | ||||
| 		$result = array_keys($TestModel->hasMany); | ||||
| 		$expected = array(); | ||||
| 		$this->assertEquals($expected, $result); | ||||
|  | @ -901,7 +1162,7 @@ class TranslateBehaviorTest extends CakeTestCase { | |||
| 		$result = isset($Behavior->runtime[$TestModel->alias]); | ||||
| 		$this->assertFalse($result); | ||||
| 
 | ||||
| 		$TestModel->Behaviors->attach('Translate', array('title' => 'Title', 'content' => 'Content')); | ||||
| 		$TestModel->Behaviors->load('Translate', array('title' => 'Title', 'content' => 'Content')); | ||||
| 		$result = array_keys($TestModel->hasMany); | ||||
| 		$expected = array('Title', 'Content'); | ||||
| 		$this->assertEquals($expected, $result); | ||||
|  | @ -1083,9 +1344,9 @@ class TranslateBehaviorTest extends CakeTestCase { | |||
| 		$this->loadFixtures('Translate', 'TranslatedItem'); | ||||
| 
 | ||||
| 		$TestModel = new TranslatedItem(); | ||||
| 		$TestModel->Behaviors->detach('Translate'); | ||||
| 		$TestModel->Behaviors->unload('Translate'); | ||||
| 		$TestModel->actsAs = array(); | ||||
| 		$TestModel->Behaviors->attach('Translate'); | ||||
| 		$TestModel->Behaviors->load('Translate'); | ||||
| 		$TestModel->bindTranslation(array('title', 'content'), true); | ||||
| 		$result = $TestModel->unbindTranslation(); | ||||
| 
 | ||||
|  |  | |||
|  | @ -2,25 +2,24 @@ | |||
| /** | ||||
|  * TreeBehaviorAfterTest file | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html> | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests | ||||
|  * @package       Cake.Test.Case.Model.Behavior | ||||
|  * @since         CakePHP(tm) v 1.2.0.5330 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('Model', 'Model'); | ||||
| App::uses('AppModel', 'Model'); | ||||
| require_once dirname(dirname(__FILE__)) . DS . 'models.php'; | ||||
| 
 | ||||
| require_once dirname(dirname(__FILE__)) . DS . 'models.php'; | ||||
| 
 | ||||
| /** | ||||
|  * TreeBehaviorAfterTest class | ||||
|  | @ -32,7 +31,7 @@ class TreeBehaviorAfterTest extends CakeTestCase { | |||
| /** | ||||
|  * Whether backup global state for each test method or not | ||||
|  * | ||||
|  * @var bool false | ||||
|  * @var bool | ||||
|  */ | ||||
| 	public $backupGlobals = false; | ||||
| 
 | ||||
|  | @ -62,6 +61,7 @@ class TreeBehaviorAfterTest extends CakeTestCase { | |||
|  */ | ||||
| 	public function testAftersaveCallback() { | ||||
| 		$this->Tree = new AfterTree(); | ||||
| 		$this->Tree->order = null; | ||||
| 
 | ||||
| 		$expected = array('AfterTree' => array('name' => 'Six and One Half Changed in AfterTree::afterSave() but not in database', 'parent_id' => 6, 'lft' => 11, 'rght' => 12)); | ||||
| 		$result = $this->Tree->save(array('AfterTree' => array('name' => 'Six and One Half', 'parent_id' => 6))); | ||||
|  | @ -73,5 +73,3 @@ class TreeBehaviorAfterTest extends CakeTestCase { | |||
| 		$this->assertEquals($expected, $result[7]); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -4,23 +4,23 @@ | |||
|  * | ||||
|  * This is the basic Tree behavior test | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html> | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests | ||||
|  * @package       Cake.Test.Case.Model.Behavior | ||||
|  * @since         CakePHP(tm) v 1.2.0.5330 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('Model', 'Model'); | ||||
| App::uses('AppModel', 'Model'); | ||||
| 
 | ||||
| require_once dirname(dirname(__FILE__)) . DS . 'models.php'; | ||||
| 
 | ||||
| /** | ||||
|  | @ -33,7 +33,7 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| /** | ||||
|  * Whether backup global state for each test method or not | ||||
|  * | ||||
|  * @var bool false | ||||
|  * @var bool | ||||
|  */ | ||||
| 	public $backupGlobals = false; | ||||
| 
 | ||||
|  | @ -46,7 +46,8 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		'modelClass' => 'NumberTree', | ||||
| 		'leftField' => 'lft', | ||||
| 		'rightField' => 'rght', | ||||
| 		'parentField' => 'parent_id' | ||||
| 		'parentField' => 'parent_id', | ||||
| 		'level' => 'level' | ||||
| 	); | ||||
| 
 | ||||
| /** | ||||
|  | @ -70,7 +71,7 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->assertEquals(7, $result); | ||||
| 
 | ||||
| 		$validTree = $this->Tree->verify(); | ||||
| 		$this->assertSame($validTree, true); | ||||
| 		$this->assertTrue($validTree); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -88,15 +89,16 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$save[$modelClass]['id'] = $result[$modelClass]['id']; | ||||
| 		$save[$modelClass][$leftField] = 0; | ||||
| 
 | ||||
| 		$this->Tree->create(); | ||||
| 		$this->Tree->save($save); | ||||
| 		$result = $this->Tree->verify(); | ||||
| 		$this->assertNotSame($result, true); | ||||
| 		$this->assertNotSame(true, $result); | ||||
| 
 | ||||
| 		$result = $this->Tree->recover(); | ||||
| 		$this->assertSame($result, true); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = $this->Tree->verify(); | ||||
| 		$this->assertSame($result, true); | ||||
| 		$this->assertTrue($result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -114,15 +116,16 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$save[$modelClass]['id'] = $result[$modelClass]['id']; | ||||
| 		$save[$modelClass][$rightField] = 0; | ||||
| 
 | ||||
| 		$this->Tree->create(); | ||||
| 		$this->Tree->save($save); | ||||
| 		$result = $this->Tree->verify(); | ||||
| 		$this->assertNotSame($result, true); | ||||
| 		$this->assertNotSame(true, $result); | ||||
| 
 | ||||
| 		$result = $this->Tree->recover(); | ||||
| 		$this->assertSame($result, true); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = $this->Tree->verify(); | ||||
| 		$this->assertSame($result, true); | ||||
| 		$this->assertTrue($result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -141,13 +144,13 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->Tree->updateAll(array($parentField => null), array('id' => $result[$modelClass]['id'])); | ||||
| 
 | ||||
| 		$result = $this->Tree->verify(); | ||||
| 		$this->assertNotSame($result, true); | ||||
| 		$this->assertNotSame(true, $result); | ||||
| 
 | ||||
| 		$result = $this->Tree->recover(); | ||||
| 		$this->assertSame($result, true); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = $this->Tree->verify(); | ||||
| 		$this->assertSame($result, true); | ||||
| 		$this->assertTrue($result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -164,13 +167,13 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->Tree->updateAll(array($parentField => 999999), array('id' => $result[$modelClass]['id'])); | ||||
| 
 | ||||
| 		$result = $this->Tree->verify(); | ||||
| 		$this->assertNotSame($result, true); | ||||
| 		$this->assertNotSame(true, $result); | ||||
| 
 | ||||
| 		$result = $this->Tree->recover('MPTT'); | ||||
| 		$this->assertSame($result, true); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = $this->Tree->verify(); | ||||
| 		$this->assertSame($result, true); | ||||
| 		$this->assertTrue($result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -183,24 +186,28 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->Tree = new $modelClass(); | ||||
| 		$this->Tree->Behaviors->disable('Tree'); | ||||
| 
 | ||||
| 		$this->Tree->create(); | ||||
| 		$this->Tree->save(array('name' => 'Main', $parentField => null, $leftField => 0, $rightField => 0)); | ||||
| 		$node1 = $this->Tree->id; | ||||
| 
 | ||||
| 		$this->Tree->create(); | ||||
| 		$this->Tree->save(array('name' => 'About Us', $parentField => $node1, $leftField => 0, $rightField => 0)); | ||||
| 		$node11 = $this->Tree->id; | ||||
| 
 | ||||
| 		$this->Tree->create(); | ||||
| 		$this->Tree->save(array('name' => 'Programs', $parentField => $node1, $leftField => 0, $rightField => 0)); | ||||
| 		$node12 = $this->Tree->id; | ||||
| 
 | ||||
| 		$this->Tree->create(); | ||||
| 		$this->Tree->save(array('name' => 'Mission and History', $parentField => $node11, $leftField => 0, $rightField => 0)); | ||||
| 
 | ||||
| 		$this->Tree->create(); | ||||
| 		$this->Tree->save(array('name' => 'Overview', $parentField => $node12, $leftField => 0, $rightField => 0)); | ||||
| 
 | ||||
| 		$this->Tree->Behaviors->enable('Tree'); | ||||
| 
 | ||||
| 		$result = $this->Tree->verify(); | ||||
| 		$this->assertNotSame($result, true); | ||||
| 		$this->assertNotSame(true, $result); | ||||
| 
 | ||||
| 		$result = $this->Tree->recover(); | ||||
| 		$this->assertTrue($result); | ||||
|  | @ -234,19 +241,24 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->Tree = new $modelClass(); | ||||
| 		$this->Tree->Behaviors->disable('Tree'); | ||||
| 
 | ||||
| 		$this->Tree->create(); | ||||
| 		$this->Tree->save(array('name' => 'Main', $parentField => null, $leftField => 0, $rightField => 0)); | ||||
| 		$node1 = $this->Tree->id; | ||||
| 
 | ||||
| 		$this->Tree->create(); | ||||
| 		$this->Tree->save(array('name' => 'About Us', $parentField => $node1, $leftField => 0, $rightField => 0)); | ||||
| 		$node11 = $this->Tree->id; | ||||
| 
 | ||||
| 		$this->Tree->create(); | ||||
| 		$this->Tree->save(array('name' => 'Programs', $parentField => $node1, $leftField => 0, $rightField => 0)); | ||||
| 		$node12 = $this->Tree->id; | ||||
| 
 | ||||
| 		$this->Tree->create(); | ||||
| 		$this->Tree->save(array('name' => 'Mission and History', $parentField => $node11, $leftField => 0, $rightField => 0)); | ||||
| 
 | ||||
| 		$this->Tree->create(); | ||||
| 		$this->Tree->save(array('name' => 'Overview', $parentField => $node12, $leftField => 0, $rightField => 0)); | ||||
| 
 | ||||
| 		$this->Tree->create(); | ||||
| 		$this->Tree->save(array('name' => 'Lost', $parentField => 9, $leftField => 0, $rightField => 0)); | ||||
| 
 | ||||
|  | @ -262,7 +274,7 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		)))); | ||||
| 
 | ||||
| 		$result = $this->Tree->verify(); | ||||
| 		$this->assertNotSame($result, true); | ||||
| 		$this->assertNotSame(true, $result); | ||||
| 
 | ||||
| 		$count = $this->Tree->find('count'); | ||||
| 		$this->assertEquals(6, $count); | ||||
|  | @ -306,13 +318,13 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->Tree->updateAll(array($parentField => 999999), array('id' => $result[$modelClass]['id'])); | ||||
| 
 | ||||
| 		$result = $this->Tree->verify(); | ||||
| 		$this->assertNotSame($result, true); | ||||
| 		$this->assertNotSame(true, $result); | ||||
| 
 | ||||
| 		$result = $this->Tree->recover(); | ||||
| 		$this->assertSame($result, true); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = $this->Tree->verify(); | ||||
| 		$this->assertSame($result, true); | ||||
| 		$this->assertTrue($result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -328,13 +340,13 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->Tree->updateAll(array($parentField => null)); | ||||
| 
 | ||||
| 		$result = $this->Tree->verify(); | ||||
| 		$this->assertNotSame($result, true); | ||||
| 		$this->assertNotSame(true, $result); | ||||
| 
 | ||||
| 		$result = $this->Tree->recover(); | ||||
| 		$this->assertSame($result, true); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = $this->Tree->verify(); | ||||
| 		$this->assertSame($result, true); | ||||
| 		$this->assertTrue($result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -350,12 +362,12 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->Tree->updateAll(array($leftField => 0, $rightField => 0)); | ||||
| 
 | ||||
| 		$result = $this->Tree->verify(); | ||||
| 		$this->assertNotSame($result, true); | ||||
| 		$this->assertNotSame(true, $result); | ||||
| 
 | ||||
| 		$this->Tree->recover(); | ||||
| 
 | ||||
| 		$result = $this->Tree->verify(); | ||||
| 		$this->assertSame($result, true); | ||||
| 		$this->assertTrue($result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -376,7 +388,7 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 			array($rightField . ' >' => $result[$modelClass][$leftField])); | ||||
| 
 | ||||
| 		$result = $this->Tree->verify(); | ||||
| 		$this->assertNotSame($result, true); | ||||
| 		$this->assertNotSame(true, $result); | ||||
| 
 | ||||
| 		$result = $this->Tree->recover(); | ||||
| 		$this->assertTrue($result); | ||||
|  | @ -395,13 +407,14 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->Tree = new $modelClass(); | ||||
| 		$this->Tree->initialize(2, 2); | ||||
| 
 | ||||
| 		$this->Tree->create(); | ||||
| 		$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)); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 
 | ||||
| 		$validTree = $this->Tree->verify(); | ||||
| 		$this->assertSame($validTree, true); | ||||
| 		$this->assertTrue($validTree); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -426,13 +439,13 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->assertEquals($initialCount + 1, $laterCount); | ||||
| 
 | ||||
| 		$children = $this->Tree->children($data[$modelClass]['id'], true, array('name')); | ||||
| 		$expects = array(array($modelClass => array('name' => '1.1.1')), | ||||
| 		$expected = array(array($modelClass => array('name' => '1.1.1')), | ||||
| 			array($modelClass => array('name' => '1.1.2')), | ||||
| 			array($modelClass => array('name' => 'testAddMiddle'))); | ||||
| 		$this->assertSame($children, $expects); | ||||
| 		$this->assertSame($expected, $children); | ||||
| 
 | ||||
| 		$validTree = $this->Tree->verify(); | ||||
| 		$this->assertSame($validTree, true); | ||||
| 		$this->assertTrue($validTree); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -479,14 +492,15 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$initialCount = $this->Tree->find('count'); | ||||
| 		//$this->expectError('Trying to save a node under a none-existant node in TreeBehavior::beforeSave');
 | ||||
| 
 | ||||
| 		$this->Tree->create(); | ||||
| 		$saveSuccess = $this->Tree->save(array($modelClass => array('name' => 'testAddInvalid', $parentField => 99999))); | ||||
| 		$this->assertSame($saveSuccess, false); | ||||
| 		$this->assertFalse($saveSuccess); | ||||
| 
 | ||||
| 		$laterCount = $this->Tree->find('count'); | ||||
| 		$this->assertSame($initialCount, $laterCount); | ||||
| 
 | ||||
| 		$validTree = $this->Tree->verify(); | ||||
| 		$this->assertSame($validTree, true); | ||||
| 		$this->assertTrue($validTree); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -499,13 +513,14 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->Tree = new $modelClass(); | ||||
| 		$this->Tree->initialize(2, 2); | ||||
| 
 | ||||
| 		$this->Tree->create(); | ||||
| 		$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)); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 
 | ||||
| 		$validTree = $this->Tree->verify(); | ||||
| 		$this->assertSame($validTree, true); | ||||
| 		$this->assertTrue($validTree); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -526,12 +541,32 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->Tree->id = $data[$modelClass]['id']; | ||||
| 		$this->Tree->saveField($parentField, $parentId); | ||||
| 		$direct = $this->Tree->children($parentId, true, array('id', 'name', $parentField, $leftField, $rightField)); | ||||
| 		$expects = array(array($modelClass => array('id' => 2, 'name' => '1.1', $parentField => 1, $leftField => 2, $rightField => 5)), | ||||
| 		$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))); | ||||
| 		$this->assertEquals($direct, $expects); | ||||
| 		$this->assertEquals($expected, $direct); | ||||
| 		$validTree = $this->Tree->verify(); | ||||
| 		$this->assertSame($validTree, true); | ||||
| 		$this->assertTrue($validTree); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testGetLevel method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testGetLevel() { | ||||
| 		extract($this->settings); | ||||
| 		$this->Tree = new $modelClass(); | ||||
| 		$this->Tree->initialize(2, 2); | ||||
| 		$this->Tree->id = null; | ||||
| 
 | ||||
| 		$result = $this->Tree->getLevel(5); | ||||
| 		$this->assertEquals(1, $result); | ||||
| 
 | ||||
| 		$result = $this->Tree->getLevel(3); | ||||
| 		$this->assertEquals(2, $result); | ||||
| 
 | ||||
| 		$this->assertFalse($this->Tree->getLevel(999)); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -572,11 +607,12 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->Tree->initialize(2, 2); | ||||
| 
 | ||||
| 		$this->Tree->whitelist = array('name', $parentField); | ||||
| 		$this->Tree->create(); | ||||
| 		$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); | ||||
| 		$this->assertEquals($expected, $result[$modelClass]); | ||||
| 		$this->assertSame($this->Tree->verify(), true); | ||||
| 		$this->assertTrue($this->Tree->verify()); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -598,13 +634,13 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->Tree->saveField($parentField, $parentId); | ||||
| 
 | ||||
| 		$result = $this->Tree->children($parentId, true, array('name')); | ||||
| 		$expects = array(array($modelClass => array('name' => '1.1.1')), | ||||
| 		$expected = array(array($modelClass => array('name' => '1.1.1')), | ||||
| 			array($modelClass => array('name' => '1.1.2')), | ||||
| 			array($modelClass => array('name' => '1.2'))); | ||||
| 		$this->assertEquals($expects, $result); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 
 | ||||
| 		$validTree = $this->Tree->verify(); | ||||
| 		$this->assertSame($validTree, true); | ||||
| 		$this->assertTrue($validTree); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -626,13 +662,13 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->Tree->saveField($parentField, $parentId); | ||||
| 
 | ||||
| 		$result = $this->Tree->children($parentId, true, array('name')); | ||||
| 		$expects = array(array($modelClass => array('name' => '1.2.1')), | ||||
| 		$expected = array(array($modelClass => array('name' => '1.2.1')), | ||||
| 			array($modelClass => array('name' => '1.2.2')), | ||||
| 			array($modelClass => array('name' => '1.1'))); | ||||
| 		$this->assertEquals($expects, $result); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 
 | ||||
| 		$validTree = $this->Tree->verify(); | ||||
| 		$this->assertSame($validTree, true); | ||||
| 		$this->assertTrue($validTree); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -651,7 +687,7 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 
 | ||||
| 		$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1.1'))); | ||||
| 
 | ||||
| 		$expects = $this->Tree->find('all'); | ||||
| 		$expected = $this->Tree->find('all'); | ||||
| 		$before = $this->Tree->read(null, $data[$modelClass]['id']); | ||||
| 
 | ||||
| 		$this->Tree->id = $parentId; | ||||
|  | @ -660,11 +696,11 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$results = $this->Tree->find('all'); | ||||
| 		$after = $this->Tree->read(null, $data[$modelClass]['id']); | ||||
| 
 | ||||
| 		$this->assertEquals($expects, $results); | ||||
| 		$this->assertEquals($expected, $results); | ||||
| 		$this->assertEquals($before, $after); | ||||
| 
 | ||||
| 		$validTree = $this->Tree->verify(); | ||||
| 		$this->assertSame($validTree, true); | ||||
| 		$this->assertTrue($validTree); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -688,7 +724,7 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->assertSame($initialCount, $laterCount); | ||||
| 
 | ||||
| 		$validTree = $this->Tree->verify(); | ||||
| 		$this->assertSame($validTree, true); | ||||
| 		$this->assertTrue($validTree); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -708,12 +744,12 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->Tree->id = $data[$modelClass]['id']; | ||||
| 		$saveSuccess = $this->Tree->saveField($parentField, $this->Tree->id); | ||||
| 
 | ||||
| 		$this->assertSame($saveSuccess, false); | ||||
| 		$this->assertFalse($saveSuccess); | ||||
| 		$laterCount = $this->Tree->find('count'); | ||||
| 		$this->assertSame($initialCount, $laterCount); | ||||
| 
 | ||||
| 		$validTree = $this->Tree->verify(); | ||||
| 		$this->assertSame($validTree, true); | ||||
| 		$this->assertTrue($validTree); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -732,8 +768,8 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$parent = $this->Tree->findByName('1. Root', array('id')); | ||||
| 		$this->Tree->id = $parent[$modelClass]['id']; | ||||
| 		$result = $this->Tree->children(null, true, array('name')); | ||||
| 		$expected = array(array($modelClass => array('name' => '1.2', )), | ||||
| 			array($modelClass => array('name' => '1.1', ))); | ||||
| 		$expected = array(array($modelClass => array('name' => '1.2')), | ||||
| 			array($modelClass => array('name' => '1.1'))); | ||||
| 		$this->assertSame($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -754,8 +790,8 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$parent = $this->Tree->findByName('1. Root', array('id')); | ||||
| 		$this->Tree->id = $parent[$modelClass]['id']; | ||||
| 		$result = $this->Tree->children(null, true, array('name')); | ||||
| 		$expected = array(array($modelClass => array('name' => '1.1', )), | ||||
| 			array($modelClass => array('name' => '1.2', ))); | ||||
| 		$expected = array(array($modelClass => array('name' => '1.1')), | ||||
| 			array($modelClass => array('name' => '1.2'))); | ||||
| 		$this->assertSame($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -776,16 +812,16 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->Tree->id = $parent[$modelClass]['id']; | ||||
| 		$result = $this->Tree->children(null, true, array('name')); | ||||
| 		$expected = array( | ||||
| 			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', ))); | ||||
| 			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'))); | ||||
| 		$this->assertSame($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -806,16 +842,16 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->Tree->id = $parent[$modelClass]['id']; | ||||
| 		$result = $this->Tree->children(null, true, array('name')); | ||||
| 		$expected = array( | ||||
| 			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', ))); | ||||
| 			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'))); | ||||
| 		$this->assertSame($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -835,8 +871,8 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$parent = $this->Tree->findByName('1. Root', array('id')); | ||||
| 		$this->Tree->id = $parent[$modelClass]['id']; | ||||
| 		$result = $this->Tree->children(null, true, array('name')); | ||||
| 		$expected = array(array($modelClass => array('name' => '1.2', )), | ||||
| 			array($modelClass => array('name' => '1.1', ))); | ||||
| 		$expected = array(array($modelClass => array('name' => '1.2')), | ||||
| 			array($modelClass => array('name' => '1.1'))); | ||||
| 		$this->assertSame($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -856,8 +892,8 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$parent = $this->Tree->findByName('1. Root', array('id')); | ||||
| 		$this->Tree->id = $parent[$modelClass]['id']; | ||||
| 		$result = $this->Tree->children(null, true, array('name')); | ||||
| 		$expected = array(array($modelClass => array('name' => '1.1', )), | ||||
| 			array($modelClass => array('name' => '1.2', ))); | ||||
| 		$expected = array(array($modelClass => array('name' => '1.1')), | ||||
| 			array($modelClass => array('name' => '1.2'))); | ||||
| 		$this->assertSame($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -878,16 +914,16 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->Tree->id = $parent[$modelClass]['id']; | ||||
| 		$result = $this->Tree->children(null, true, array('name')); | ||||
| 		$expected = array( | ||||
| 			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', ))); | ||||
| 			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'))); | ||||
| 		$this->assertSame($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -908,16 +944,16 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->Tree->id = $parent[$modelClass]['id']; | ||||
| 		$result = $this->Tree->children(null, true, array('name')); | ||||
| 		$expected = array( | ||||
| 			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', ))); | ||||
| 			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'))); | ||||
| 		$this->assertSame($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -938,16 +974,16 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->Tree->id = $parent[$modelClass]['id']; | ||||
| 		$result = $this->Tree->children(null, true, array('name')); | ||||
| 		$expected = array( | ||||
| 			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', ))); | ||||
| 			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'))); | ||||
| 		$this->assertSame($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -965,7 +1001,7 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->Tree->save(array($parentField => null)); | ||||
| 
 | ||||
| 		$result = $this->Tree->verify(); | ||||
| 		$this->assertSame($result, true); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$this->Tree->moveUp(); | ||||
| 
 | ||||
|  | @ -995,7 +1031,7 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->assertEquals($initialCount - 1, $laterCount); | ||||
| 
 | ||||
| 		$validTree = $this->Tree->verify(); | ||||
| 		$this->assertSame($validTree, true); | ||||
| 		$this->assertTrue($validTree); | ||||
| 
 | ||||
| 		$initialCount = $this->Tree->find('count'); | ||||
| 		$result = $this->Tree->findByName('1.1'); | ||||
|  | @ -1007,7 +1043,7 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->assertEquals($initialCount - 2, $laterCount); | ||||
| 
 | ||||
| 		$validTree = $this->Tree->verify(); | ||||
| 		$this->assertSame($validTree, true); | ||||
| 		$this->assertTrue($validTree); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -1040,18 +1076,18 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->assertEquals($initialCount, $laterCount); | ||||
| 
 | ||||
| 		$children = $this->Tree->children($result[$modelClass][$parentField], true, array('name')); | ||||
| 		$expects = array(array($modelClass => array('name' => '1.1.1')), | ||||
| 		$expected = array(array($modelClass => array('name' => '1.1.1')), | ||||
| 			array($modelClass => array('name' => '1.1.2')), | ||||
| 			array($modelClass => array('name' => '1.2'))); | ||||
| 		$this->assertEquals($children, $expects); | ||||
| 		$this->assertEquals($expected, $children); | ||||
| 
 | ||||
| 		$topNodes = $this->Tree->children(false, true,array('name')); | ||||
| 		$expects = array(array($modelClass => array('name' => '1. Root')), | ||||
| 		$topNodes = $this->Tree->children(false, true, array('name')); | ||||
| 		$expected = array(array($modelClass => array('name' => '1. Root')), | ||||
| 			array($modelClass => array('name' => '1.1'))); | ||||
| 		$this->assertEquals($topNodes, $expects); | ||||
| 		$this->assertEquals($expected, $topNodes); | ||||
| 
 | ||||
| 		$validTree = $this->Tree->verify(); | ||||
| 		$this->assertSame($validTree, true); | ||||
| 		$this->assertTrue($validTree); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -1076,15 +1112,15 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->assertEquals($initialCount, $laterCount); | ||||
| 		$this->assertEquals($initialTopNodes, $laterTopNodes); | ||||
| 
 | ||||
| 		$topNodes = $this->Tree->children(false, true,array('name')); | ||||
| 		$expects = array(array($modelClass => array('name' => '1.1')), | ||||
| 		$topNodes = $this->Tree->children(false, true, array('name')); | ||||
| 		$expected = array(array($modelClass => array('name' => '1.1')), | ||||
| 			array($modelClass => array('name' => '1.2')), | ||||
| 			array($modelClass => array('name' => '1. Root'))); | ||||
| 
 | ||||
| 		$this->assertEquals($topNodes, $expects); | ||||
| 		$this->assertEquals($expected, $topNodes); | ||||
| 
 | ||||
| 		$validTree = $this->Tree->verify(); | ||||
| 		$this->assertSame($validTree, true); | ||||
| 		$this->assertTrue($validTree); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -1105,7 +1141,7 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->assertEquals($initialCount, $laterCount); | ||||
| 
 | ||||
| 		$nodes = $this->Tree->find('list', array('order' => $leftField)); | ||||
| 		$expects = array( | ||||
| 		$expected = array( | ||||
| 			1 => '1. Root', | ||||
| 			2 => '1.1', | ||||
| 			4 => '1.1.2', | ||||
|  | @ -1115,10 +1151,10 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 			3 => '1.1.1', | ||||
| 		); | ||||
| 
 | ||||
| 		$this->assertEquals($nodes, $expects); | ||||
| 		$this->assertEquals($expected, $nodes); | ||||
| 
 | ||||
| 		$validTree = $this->Tree->verify(); | ||||
| 		$this->assertSame($validTree, true); | ||||
| 		$this->assertTrue($validTree); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -1140,19 +1176,19 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->assertEquals($initialCount - 1, $laterCount); | ||||
| 
 | ||||
| 		$children = $this->Tree->children($result[$modelClass][$parentField], true, array('name'), $leftField . ' asc'); | ||||
| 		$expects = array( | ||||
| 		$expected = array( | ||||
| 			array($modelClass => array('name' => '1.1.1')), | ||||
| 			array($modelClass => array('name' => '1.1.2')), | ||||
| 			array($modelClass => array('name' => '1.2')) | ||||
| 		); | ||||
| 		$this->assertEquals($children, $expects); | ||||
| 		$this->assertEquals($expected, $children); | ||||
| 
 | ||||
| 		$topNodes = $this->Tree->children(false, true,array('name')); | ||||
| 		$expects = array(array($modelClass => array('name' => '1. Root'))); | ||||
| 		$this->assertEquals($topNodes, $expects); | ||||
| 		$topNodes = $this->Tree->children(false, true, array('name')); | ||||
| 		$expected = array(array($modelClass => array('name' => '1. Root'))); | ||||
| 		$this->assertEquals($expected, $topNodes); | ||||
| 
 | ||||
| 		$validTree = $this->Tree->verify(); | ||||
| 		$this->assertSame($validTree, true); | ||||
| 		$this->assertTrue($validTree); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -1173,7 +1209,7 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->assertEquals($initialCount - 1, $laterCount); | ||||
| 
 | ||||
| 		$nodes = $this->Tree->find('list', array('order' => $leftField)); | ||||
| 		$expects = array( | ||||
| 		$expected = array( | ||||
| 			1 => '1. Root', | ||||
| 			2 => '1.1', | ||||
| 			4 => '1.1.2', | ||||
|  | @ -1181,10 +1217,10 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 			6 => '1.2.1', | ||||
| 			7 => '1.2.2', | ||||
| 		); | ||||
| 		$this->assertEquals($nodes, $expects); | ||||
| 		$this->assertEquals($expected, $nodes); | ||||
| 
 | ||||
| 		$validTree = $this->Tree->verify(); | ||||
| 		$this->assertSame($validTree, true); | ||||
| 		$this->assertTrue($validTree); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -1201,18 +1237,18 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->Tree->id = $data[$modelClass]['id']; | ||||
| 
 | ||||
| 		$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)), | ||||
| 		$expected = 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))); | ||||
| 		$this->assertEquals($direct, $expects); | ||||
| 		$this->assertEquals($expected, $direct); | ||||
| 
 | ||||
| 		$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)), | ||||
| 		$expected = 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)), | ||||
| 			array($modelClass => array('id' => 6, 'name' => '1.2.1', $parentField => 5, $leftField => 9, $rightField => 10)), | ||||
| 			array($modelClass => array('id' => 7, 'name' => '1.2.2', $parentField => 5, $leftField => 11, $rightField => 12))); | ||||
| 		$this->assertEquals($total, $expects); | ||||
| 		$this->assertEquals($expected, $total); | ||||
| 
 | ||||
| 		$this->assertEquals(array(), $this->Tree->children(10000)); | ||||
| 	} | ||||
|  | @ -1256,8 +1292,8 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->Tree->id = $data[$modelClass]['id']; | ||||
| 
 | ||||
| 		$result = $this->Tree->getParentNode(null, array('name')); | ||||
| 		$expects = array($modelClass => array('name' => '1.2')); | ||||
| 		$this->assertSame($expects, $result); | ||||
| 		$expected = array($modelClass => array('name' => '1.2')); | ||||
| 		$this->assertSame($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -1274,10 +1310,10 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->Tree->id = $data[$modelClass]['id']; | ||||
| 
 | ||||
| 		$result = $this->Tree->getPath(null, array('name')); | ||||
| 		$expects = array(array($modelClass => array('name' => '1. Root')), | ||||
| 		$expected = array(array($modelClass => array('name' => '1. Root')), | ||||
| 			array($modelClass => array('name' => '1.2')), | ||||
| 			array($modelClass => array('name' => '1.2.2'))); | ||||
| 		$this->assertSame($expects, $result); | ||||
| 		$this->assertSame($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -1296,12 +1332,12 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->Tree->id = $data[$modelClass]['id']; | ||||
| 
 | ||||
| 		$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)), | ||||
| 		$expected = 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))); | ||||
| 		$this->assertEquals($direct, $expects); | ||||
| 		$this->assertEquals($expected, $direct); | ||||
| 
 | ||||
| 		$total = $this->Tree->children(null, null, array('id', 'name', $parentField, $leftField, $rightField)); | ||||
| 		$expects = array( | ||||
| 		$expected = 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)), | ||||
|  | @ -1309,7 +1345,7 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 			array($modelClass => array('id' => 6, 'name' => '1.2.1', $parentField => 5, $leftField => 9, $rightField => 10)), | ||||
| 			array($modelClass => array('id' => 7, 'name' => '1.2.2', $parentField => 5, $leftField => 11, $rightField => 12)) | ||||
| 		); | ||||
| 		$this->assertEquals($total, $expects); | ||||
| 		$this->assertEquals($expected, $total); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -1397,6 +1433,29 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		$this->assertEquals('__3 - 1.1.1', $result[3]); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test the formatting options of formatTreeList() | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testFormatTreeList() { | ||||
| 		extract($this->settings); | ||||
| 		$this->Tree = new $modelClass(); | ||||
| 		$this->Tree->initialize(2, 2); | ||||
| 
 | ||||
| 		$options = array('order' => array('lft' => 'asc')); | ||||
| 		$records = $this->Tree->find('all', $options); | ||||
| 
 | ||||
| 		$options = array( | ||||
| 			'keyPath' => "{n}.$modelClass.id", | ||||
| 			'valuePath' => array('%s - %s', "{n}.$modelClass.id", "{n}.$modelClass.name"), | ||||
| 			'spacer' => '--'); | ||||
| 		$result = $this->Tree->formatTreeList($records, $options); | ||||
| 		$this->assertEquals('1 - 1. Root', $result[1]); | ||||
| 		$this->assertEquals('--2 - 1.1', $result[2]); | ||||
| 		$this->assertEquals('----3 - 1.1.1', $result[3]); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testArraySyntax method | ||||
|  * | ||||
|  | @ -1419,7 +1478,7 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 	public function testFindThreaded() { | ||||
| 		$Model = new Person(); | ||||
| 		$Model->recursive = -1; | ||||
| 		$Model->Behaviors->attach('Tree', array('parent' => 'mother_id')); | ||||
| 		$Model->Behaviors->load('Tree', array('parent' => 'mother_id')); | ||||
| 
 | ||||
| 		$result = $Model->find('threaded'); | ||||
| 		$expected = array( | ||||
|  | @ -1492,4 +1551,61 @@ class TreeBehaviorNumberTest extends CakeTestCase { | |||
| 		); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| 	public function testLevel() { | ||||
| 		extract($this->settings); | ||||
| 		$this->Tree = new $modelClass(); | ||||
| 		$this->Tree->Behaviors->attach('Tree', array('level' => 'level')); | ||||
| 		$this->Tree->initialize(2, 2); | ||||
| 
 | ||||
| 		$result = $this->Tree->findByName('1. Root'); | ||||
| 		$this->assertEquals(0, $result[$modelClass][$level]); | ||||
| 
 | ||||
| 		$result = $this->Tree->findByName('1.1'); | ||||
| 		$this->assertEquals(1, $result[$modelClass][$level]); | ||||
| 
 | ||||
| 		$result = $this->Tree->findByName('1.2.2'); | ||||
| 		$this->assertEquals(2, $result[$modelClass][$level]); | ||||
| 
 | ||||
| 		$result = $this->Tree->findByName('1.2.1'); | ||||
| 		$this->assertEquals(2, $result[$modelClass][$level]); | ||||
| 
 | ||||
| 		// Save with parent_id not set
 | ||||
| 		$this->Tree->save(array('id' => $result[$modelClass]['id'], 'name' => 'foo')); | ||||
| 		$result = $this->Tree->findByName('foo'); | ||||
| 		$this->assertEquals(2, $result[$modelClass][$level]); | ||||
| 
 | ||||
| 		// Save with parent_id not changed
 | ||||
| 		$this->Tree->save(array( | ||||
| 			'id' => $result[$modelClass]['id'], | ||||
| 			'parent_id' => $result[$modelClass]['parent_id'], | ||||
| 			'name' => 'foo2' | ||||
| 		)); | ||||
| 		$result = $this->Tree->findByName('foo2'); | ||||
| 		$this->assertEquals(2, $result[$modelClass][$level]); | ||||
| 
 | ||||
| 		// Save with parent_id changed
 | ||||
| 		$result = $this->Tree->findByName('1.1'); | ||||
| 		$this->Tree->save(array( | ||||
| 			'id' => $result[$modelClass]['id'], | ||||
| 			'parent_id' => '' | ||||
| 		)); | ||||
| 		$result = $this->Tree->findByName('1.1'); | ||||
| 		$this->assertEquals(0, $result[$modelClass][$level]); | ||||
| 
 | ||||
| 		$result = $this->Tree->findByName('1.1.2'); | ||||
| 		$this->assertEquals(1, $result[$modelClass][$level]); | ||||
| 
 | ||||
| 		$parent = $this->Tree->findByName('1.1.2'); | ||||
| 		$result = $this->Tree->findByName('1.2'); | ||||
| 		$this->Tree->save(array( | ||||
| 			'id' => $result[$modelClass]['id'], | ||||
| 			'parent_id' => $parent[$modelClass]['id'] | ||||
| 		)); | ||||
| 		$result = $this->Tree->findByName('1.2'); | ||||
| 		$this->assertEquals(2, $result[$modelClass][$level]); | ||||
| 
 | ||||
| 		$result = $this->Tree->findByName('1.2.2'); | ||||
| 		$this->assertEquals(3, $result[$modelClass][$level]); | ||||
| 	} | ||||
| } | ||||
|  |  | |||
|  | @ -4,23 +4,23 @@ | |||
|  * | ||||
|  * A tree test using scope | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html> | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests | ||||
|  * @package       Cake.Test.Case.Model.Behavior | ||||
|  * @since         CakePHP(tm) v 1.2.0.5330 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('Model', 'Model'); | ||||
| App::uses('AppModel', 'Model'); | ||||
| 
 | ||||
| require_once dirname(dirname(__FILE__)) . DS . 'models.php'; | ||||
| 
 | ||||
| /** | ||||
|  | @ -33,7 +33,7 @@ class TreeBehaviorScopedTest extends CakeTestCase { | |||
| /** | ||||
|  * Whether backup global state for each test method or not | ||||
|  * | ||||
|  * @var bool false | ||||
|  * @var bool | ||||
|  */ | ||||
| 	public $backupGlobals = false; | ||||
| 
 | ||||
|  | @ -63,6 +63,7 @@ class TreeBehaviorScopedTest extends CakeTestCase { | |||
|  */ | ||||
| 	public function testStringScope() { | ||||
| 		$this->Tree = new FlagTree(); | ||||
| 		$this->Tree->order = null; | ||||
| 		$this->Tree->initialize(2, 3); | ||||
| 
 | ||||
| 		$this->Tree->id = 1; | ||||
|  | @ -78,11 +79,11 @@ class TreeBehaviorScopedTest extends CakeTestCase { | |||
| 		); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 
 | ||||
| 		$this->Tree->Behaviors->attach('Tree', array('scope' => 'FlagTree.flag = 1')); | ||||
| 		$this->Tree->Behaviors->load('Tree', array('scope' => 'FlagTree.flag = 1')); | ||||
| 		$this->assertEquals(array(), $this->Tree->children()); | ||||
| 
 | ||||
| 		$this->Tree->id = 1; | ||||
| 		$this->Tree->Behaviors->attach('Tree', array('scope' => 'FlagTree.flag = 1')); | ||||
| 		$this->Tree->Behaviors->load('Tree', array('scope' => 'FlagTree.flag = 1')); | ||||
| 
 | ||||
| 		$result = $this->Tree->children(); | ||||
| 		$expected = array(array('FlagTree' => array('id' => '2', 'name' => '1.1', 'parent_id' => '1', 'lft' => '2', 'rght' => '9', 'flag' => '1'))); | ||||
|  | @ -99,6 +100,7 @@ class TreeBehaviorScopedTest extends CakeTestCase { | |||
|  */ | ||||
| 	public function testArrayScope() { | ||||
| 		$this->Tree = new FlagTree(); | ||||
| 		$this->Tree->order = null; | ||||
| 		$this->Tree->initialize(2, 3); | ||||
| 
 | ||||
| 		$this->Tree->id = 1; | ||||
|  | @ -114,11 +116,11 @@ class TreeBehaviorScopedTest extends CakeTestCase { | |||
| 		); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 
 | ||||
| 		$this->Tree->Behaviors->attach('Tree', array('scope' => array('FlagTree.flag' => 1))); | ||||
| 		$this->Tree->Behaviors->load('Tree', array('scope' => array('FlagTree.flag' => 1))); | ||||
| 		$this->assertEquals(array(), $this->Tree->children()); | ||||
| 
 | ||||
| 		$this->Tree->id = 1; | ||||
| 		$this->Tree->Behaviors->attach('Tree', array('scope' => array('FlagTree.flag' => 1))); | ||||
| 		$this->Tree->Behaviors->load('Tree', array('scope' => array('FlagTree.flag' => 1))); | ||||
| 
 | ||||
| 		$result = $this->Tree->children(); | ||||
| 		$expected = array(array('FlagTree' => array('id' => '2', 'name' => '1.1', 'parent_id' => '1', 'lft' => '2', 'rght' => '9', 'flag' => '1'))); | ||||
|  | @ -128,6 +130,29 @@ class TreeBehaviorScopedTest extends CakeTestCase { | |||
| 		$this->assertEquals(11, $this->Tree->find('count')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testSaveWithParentAndInvalidScope method | ||||
|  * | ||||
|  * Attempting to save an invalid data should not trigger an `Undefined offset` | ||||
|  * error | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testSaveWithParentAndInvalidScope() { | ||||
| 		$this->Tree = new FlagTree(); | ||||
| 		$this->Tree->order = null; | ||||
| 		$data = $this->Tree->create(array( | ||||
| 			'name' => 'Flag', | ||||
| 		)); | ||||
| 		$tree = $this->Tree->save($data); | ||||
| 		$this->Tree->Behaviors->load('Tree', array( | ||||
| 			'scope' => array('FlagTree.flag' => 100) | ||||
| 		)); | ||||
| 		$tree['FlagTree']['parent_id'] = 1; | ||||
| 		$result = $this->Tree->save($tree); | ||||
| 		$this->assertFalse($result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testMoveUpWithScope method | ||||
|  * | ||||
|  | @ -135,7 +160,8 @@ class TreeBehaviorScopedTest extends CakeTestCase { | |||
|  */ | ||||
| 	public function testMoveUpWithScope() { | ||||
| 		$this->Ad = new Ad(); | ||||
| 		$this->Ad->Behaviors->attach('Tree', array('scope' => 'Campaign')); | ||||
| 		$this->Ad->order = null; | ||||
| 		$this->Ad->Behaviors->load('Tree', array('scope' => 'Campaign')); | ||||
| 		$this->Ad->moveUp(6); | ||||
| 
 | ||||
| 		$this->Ad->id = 4; | ||||
|  | @ -151,7 +177,8 @@ class TreeBehaviorScopedTest extends CakeTestCase { | |||
|  */ | ||||
| 	public function testMoveDownWithScope() { | ||||
| 		$this->Ad = new Ad(); | ||||
| 		$this->Ad->Behaviors->attach('Tree', array('scope' => 'Campaign')); | ||||
| 		$this->Ad->order = null; | ||||
| 		$this->Ad->Behaviors->load('Tree', array('scope' => 'Campaign')); | ||||
| 		$this->Ad->moveDown(6); | ||||
| 
 | ||||
| 		$this->Ad->id = 4; | ||||
|  | @ -168,10 +195,12 @@ class TreeBehaviorScopedTest extends CakeTestCase { | |||
|  */ | ||||
| 	public function testTranslatingTree() { | ||||
| 		$this->Tree = new FlagTree(); | ||||
| 		$this->Tree->order = null; | ||||
| 		$this->Tree->cacheQueries = false; | ||||
| 		$this->Tree->Behaviors->attach('Translate', array('title')); | ||||
| 		$this->Tree->Behaviors->load('Translate', array('title')); | ||||
| 
 | ||||
| 		//Save
 | ||||
| 		$this->Tree->create(); | ||||
| 		$this->Tree->locale = 'eng'; | ||||
| 		$data = array('FlagTree' => array( | ||||
| 			'title' => 'name #1', | ||||
|  | @ -285,9 +314,11 @@ class TreeBehaviorScopedTest extends CakeTestCase { | |||
| 	public function testAliasesWithScopeInTwoTreeAssociations() { | ||||
| 		extract($this->settings); | ||||
| 		$this->Tree = new $modelClass(); | ||||
| 		$this->Tree->order = null; | ||||
| 		$this->Tree->initialize(2, 2); | ||||
| 
 | ||||
| 		$this->TreeTwo = new NumberTreeTwo(); | ||||
| 		$this->TreeTwo->order = null; | ||||
| 
 | ||||
| 		$record = $this->Tree->find('first'); | ||||
| 
 | ||||
|  | @ -307,7 +338,7 @@ class TreeBehaviorScopedTest extends CakeTestCase { | |||
| 				) | ||||
| 			) | ||||
| 		)); | ||||
| 		$this->TreeTwo->Behaviors->attach('Tree', array( | ||||
| 		$this->TreeTwo->Behaviors->load('Tree', array( | ||||
| 			'scope' => 'FirstTree' | ||||
| 		)); | ||||
| 
 | ||||
|  | @ -332,4 +363,229 @@ class TreeBehaviorScopedTest extends CakeTestCase { | |||
| 		)); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testGenerateTreeListWithScope method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testGenerateTreeListWithScope() { | ||||
| 		extract($this->settings); | ||||
| 		$this->Tree = new $modelClass(); | ||||
| 		$this->Tree->order = null; | ||||
| 		$this->Tree->initialize(2, 3); | ||||
| 
 | ||||
| 		$this->Tree->id = 1; | ||||
| 		$this->Tree->saveField('flag', 1); | ||||
| 		$this->Tree->id = 2; | ||||
| 		$this->Tree->saveField('flag', 1); | ||||
| 
 | ||||
| 		$this->Tree->Behaviors->load('Tree', array('scope' => array('FlagTree.flag' => 1))); | ||||
| 
 | ||||
| 		$result = $this->Tree->generateTreeList(); | ||||
| 		$expected = array( | ||||
| 			1 => '1. Root', | ||||
| 			2 => '_1.1' | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 
 | ||||
| 		// As string.
 | ||||
| 		$this->Tree->Behaviors->load('Tree', array('scope' => 'FlagTree.flag = 1')); | ||||
| 
 | ||||
| 		$result = $this->Tree->generateTreeList(); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 
 | ||||
| 		// Merging conditions.
 | ||||
| 		$result = $this->Tree->generateTreeList(array('FlagTree.id >' => 1)); | ||||
| 		$expected = array( | ||||
| 			2 => '1.1' | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testRecoverUsingParentMode method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testRecoverUsingParentMode() { | ||||
| 		extract($this->settings); | ||||
| 		$this->Tree = new $modelClass(); | ||||
| 		$this->Tree->order = null; | ||||
| 		$this->Tree->initialize(2, 3); | ||||
| 
 | ||||
| 		$this->Tree->Behaviors->load('Tree', array('scope' => 'FlagTree.flag = 1')); | ||||
| 		$this->Tree->Behaviors->disable('Tree'); | ||||
| 
 | ||||
| 		$this->Tree->create(); | ||||
| 		$this->Tree->save(array('name' => 'Main', $parentField => null, $leftField => 0, $rightField => 0, 'flag' => 1)); | ||||
| 		$node1 = $this->Tree->id; | ||||
| 
 | ||||
| 		$this->Tree->create(); | ||||
| 		$this->Tree->save(array('name' => 'About Us', $parentField => $node1, $leftField => 0, $rightField => 0, 'flag' => 1)); | ||||
| 		$node11 = $this->Tree->id; | ||||
| 
 | ||||
| 		$this->Tree->create(); | ||||
| 		$this->Tree->save(array('name' => 'Programs', $parentField => $node1, $leftField => 0, $rightField => 0, 'flag' => 1)); | ||||
| 		$node12 = $this->Tree->id; | ||||
| 
 | ||||
| 		$this->Tree->create(); | ||||
| 		$this->Tree->save(array('name' => 'Mission and History', $parentField => $node11, $leftField => 0, $rightField => 0, 'flag' => 1)); | ||||
| 
 | ||||
| 		$this->Tree->create(); | ||||
| 		$this->Tree->save(array('name' => 'Overview', $parentField => $node12, $leftField => 0, $rightField => 0, 'flag' => 1)); | ||||
| 
 | ||||
| 		$this->Tree->Behaviors->enable('Tree'); | ||||
| 
 | ||||
| 		$result = $this->Tree->verify(); | ||||
| 		$this->assertNotSame(true, $result); | ||||
| 
 | ||||
| 		$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, 'flag'), | ||||
| 			'conditions' => array('name' => 'Main'), | ||||
| 			'recursive' => -1 | ||||
| 		)); | ||||
| 		$expected = array( | ||||
| 			$modelClass => array( | ||||
| 				'name' => 'Main', | ||||
| 				$parentField => null, | ||||
| 				$leftField => 1, | ||||
| 				$rightField => 10, | ||||
| 				'flag' => 1 | ||||
| 			) | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testRecoverFromMissingParent method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testRecoverFromMissingParent() { | ||||
| 		extract($this->settings); | ||||
| 		$this->Tree = new $modelClass(); | ||||
| 		$this->Tree->order = null; | ||||
| 		$this->Tree->initialize(2, 2); | ||||
| 
 | ||||
| 		$this->Tree->id = 1; | ||||
| 		$this->Tree->saveField('flag', 1); | ||||
| 		$this->Tree->id = 2; | ||||
| 		$this->Tree->saveField('flag', 1); | ||||
| 
 | ||||
| 		$this->Tree->Behaviors->load('Tree', array('scope' => array('FlagTree.flag' => 1))); | ||||
| 
 | ||||
| 		$result = $this->Tree->findByName('1.1'); | ||||
| 		$this->Tree->updateAll(array($parentField => 999999), array('id' => $result[$modelClass]['id'])); | ||||
| 
 | ||||
| 		$result = $this->Tree->verify(); | ||||
| 		$this->assertNotSame(true, $result); | ||||
| 
 | ||||
| 		$result = $this->Tree->recover(); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = $this->Tree->verify(); | ||||
| 		$this->assertTrue($result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testDetectInvalidParents method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testDetectInvalidParents() { | ||||
| 		extract($this->settings); | ||||
| 		$this->Tree = new $modelClass(); | ||||
| 		$this->Tree->order = null; | ||||
| 		$this->Tree->initialize(2, 2); | ||||
| 
 | ||||
| 		$this->Tree->id = 1; | ||||
| 		$this->Tree->saveField('flag', 1); | ||||
| 		$this->Tree->id = 2; | ||||
| 		$this->Tree->saveField('flag', 1); | ||||
| 
 | ||||
| 		$this->Tree->Behaviors->load('Tree', array('scope' => array('FlagTree.flag' => 1))); | ||||
| 
 | ||||
| 		$this->Tree->updateAll(array($parentField => null)); | ||||
| 
 | ||||
| 		$result = $this->Tree->verify(); | ||||
| 		$this->assertNotSame(true, $result); | ||||
| 
 | ||||
| 		$result = $this->Tree->recover(); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = $this->Tree->verify(); | ||||
| 		$this->assertTrue($result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testDetectInvalidLftsRghts method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testDetectInvalidLftsRghts() { | ||||
| 		extract($this->settings); | ||||
| 		$this->Tree = new $modelClass(); | ||||
| 		$this->Tree->order = null; | ||||
| 		$this->Tree->initialize(2, 2); | ||||
| 
 | ||||
| 		$this->Tree->id = 1; | ||||
| 		$this->Tree->saveField('flag', 1); | ||||
| 		$this->Tree->id = 2; | ||||
| 		$this->Tree->saveField('flag', 1); | ||||
| 
 | ||||
| 		$this->Tree->Behaviors->load('Tree', array('scope' => array('FlagTree.flag' => 1))); | ||||
| 
 | ||||
| 		$this->Tree->updateAll(array($leftField => 0, $rightField => 0)); | ||||
| 
 | ||||
| 		$result = $this->Tree->verify(); | ||||
| 		$this->assertNotSame(true, $result); | ||||
| 
 | ||||
| 		$this->Tree->recover(); | ||||
| 
 | ||||
| 		$result = $this->Tree->verify(); | ||||
| 		$this->assertTrue($result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Reproduces a situation where a single node has lft= rght, and all other lft and rght fields follow sequentially | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testDetectEqualLftsRghts() { | ||||
| 		extract($this->settings); | ||||
| 		$this->Tree = new $modelClass(); | ||||
| 		$this->Tree->order = null; | ||||
| 		$this->Tree->initialize(1, 3); | ||||
| 
 | ||||
| 		$this->Tree->id = 1; | ||||
| 		$this->Tree->saveField('flag', 1); | ||||
| 		$this->Tree->id = 2; | ||||
| 		$this->Tree->saveField('flag', 1); | ||||
| 
 | ||||
| 		$this->Tree->Behaviors->load('Tree', array('scope' => array('FlagTree.flag' => 1))); | ||||
| 
 | ||||
| 		$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(); | ||||
| 		$this->assertNotSame(true, $result); | ||||
| 
 | ||||
| 		$result = $this->Tree->recover(); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = $this->Tree->verify(); | ||||
| 		$this->assertTrue($result); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -2,19 +2,18 @@ | |||
| /** | ||||
|  * Tree Behavior test file - runs all the tree behavior tests | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice. | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://cakephp.org CakePHP(tm) Project | ||||
|  * @package       Cake.Test.Case.Model.Behavior | ||||
|  * @since         CakePHP(tm) v 2.0 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| /** | ||||
|  |  | |||
|  | @ -4,24 +4,24 @@ | |||
|  * | ||||
|  * Tree test using UUIDs | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html> | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests | ||||
|  * @package       Cake.Test.Case.Model.Behavior | ||||
|  * @since         CakePHP(tm) v 1.2.0.5330 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('Model', 'Model'); | ||||
| App::uses('AppModel', 'Model'); | ||||
| App::uses('String', 'Utility'); | ||||
| App::uses('CakeText', 'Utility'); | ||||
| 
 | ||||
| require_once dirname(dirname(__FILE__)) . DS . 'models.php'; | ||||
| 
 | ||||
| /** | ||||
|  | @ -34,7 +34,7 @@ class TreeBehaviorUuidTest extends CakeTestCase { | |||
| /** | ||||
|  * Whether backup global state for each test method or not | ||||
|  * | ||||
|  * @var bool false | ||||
|  * @var bool | ||||
|  */ | ||||
| 	public $backupGlobals = false; | ||||
| 
 | ||||
|  | @ -65,6 +65,7 @@ class TreeBehaviorUuidTest extends CakeTestCase { | |||
| 	public function testAddWithPreSpecifiedId() { | ||||
| 		extract($this->settings); | ||||
| 		$this->Tree = new $modelClass(); | ||||
| 		$this->Tree->order = null; | ||||
| 		$this->Tree->initialize(2, 2); | ||||
| 
 | ||||
| 		$data = $this->Tree->find('first', array( | ||||
|  | @ -72,7 +73,7 @@ class TreeBehaviorUuidTest extends CakeTestCase { | |||
| 			'conditions' => array($modelClass . '.name' => '1.1') | ||||
| 		)); | ||||
| 
 | ||||
| 		$id = String::uuid(); | ||||
| 		$id = CakeText::uuid(); | ||||
| 		$this->Tree->create(); | ||||
| 		$result = $this->Tree->save(array($modelClass => array( | ||||
| 			'id' => $id, | ||||
|  | @ -96,6 +97,7 @@ class TreeBehaviorUuidTest extends CakeTestCase { | |||
| 	public function testMovePromote() { | ||||
| 		extract($this->settings); | ||||
| 		$this->Tree = new $modelClass(); | ||||
| 		$this->Tree->order = null; | ||||
| 		$this->Tree->initialize(2, 2); | ||||
| 		$this->Tree->id = null; | ||||
| 
 | ||||
|  | @ -106,12 +108,12 @@ class TreeBehaviorUuidTest extends CakeTestCase { | |||
| 		$this->Tree->id = $data[$modelClass]['id']; | ||||
| 		$this->Tree->saveField($parentField, $parentId); | ||||
| 		$direct = $this->Tree->children($parentId, true, array('name', $leftField, $rightField)); | ||||
| 		$expects = array(array($modelClass => array('name' => '1.1', $leftField => 2, $rightField => 5)), | ||||
| 		$expected = array(array($modelClass => array('name' => '1.1', $leftField => 2, $rightField => 5)), | ||||
| 			array($modelClass => array('name' => '1.2', $leftField => 6, $rightField => 11)), | ||||
| 			array($modelClass => array('name' => '1.1.1', $leftField => 12, $rightField => 13))); | ||||
| 		$this->assertEquals($direct, $expects); | ||||
| 		$this->assertEquals($expected, $direct); | ||||
| 		$validTree = $this->Tree->verify(); | ||||
| 		$this->assertSame($validTree, true); | ||||
| 		$this->assertTrue($validTree); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -122,6 +124,7 @@ class TreeBehaviorUuidTest extends CakeTestCase { | |||
| 	public function testMoveWithWhitelist() { | ||||
| 		extract($this->settings); | ||||
| 		$this->Tree = new $modelClass(); | ||||
| 		$this->Tree->order = null; | ||||
| 		$this->Tree->initialize(2, 2); | ||||
| 		$this->Tree->id = null; | ||||
| 
 | ||||
|  | @ -149,6 +152,7 @@ class TreeBehaviorUuidTest extends CakeTestCase { | |||
| 	public function testRemoveNoChildren() { | ||||
| 		extract($this->settings); | ||||
| 		$this->Tree = new $modelClass(); | ||||
| 		$this->Tree->order = null; | ||||
| 		$this->Tree->initialize(2, 2); | ||||
| 		$initialCount = $this->Tree->find('count'); | ||||
| 
 | ||||
|  | @ -159,7 +163,7 @@ class TreeBehaviorUuidTest extends CakeTestCase { | |||
| 		$this->assertEquals($initialCount, $laterCount); | ||||
| 
 | ||||
| 		$nodes = $this->Tree->find('list', array('order' => $leftField)); | ||||
| 		$expects = array( | ||||
| 		$expected = array( | ||||
| 			'1. Root', | ||||
| 			'1.1', | ||||
| 			'1.1.2', | ||||
|  | @ -169,10 +173,10 @@ class TreeBehaviorUuidTest extends CakeTestCase { | |||
| 			'1.1.1', | ||||
| 		); | ||||
| 
 | ||||
| 		$this->assertEquals(array_values($nodes), $expects); | ||||
| 		$this->assertEquals($expected, array_values($nodes)); | ||||
| 
 | ||||
| 		$validTree = $this->Tree->verify(); | ||||
| 		$this->assertSame($validTree, true); | ||||
| 		$this->assertTrue($validTree); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -183,6 +187,7 @@ class TreeBehaviorUuidTest extends CakeTestCase { | |||
| 	public function testRemoveAndDeleteNoChildren() { | ||||
| 		extract($this->settings); | ||||
| 		$this->Tree = new $modelClass(); | ||||
| 		$this->Tree->order = null; | ||||
| 		$this->Tree->initialize(2, 2); | ||||
| 		$initialCount = $this->Tree->find('count'); | ||||
| 
 | ||||
|  | @ -193,7 +198,7 @@ class TreeBehaviorUuidTest extends CakeTestCase { | |||
| 		$this->assertEquals($initialCount - 1, $laterCount); | ||||
| 
 | ||||
| 		$nodes = $this->Tree->find('list', array('order' => $leftField)); | ||||
| 		$expects = array( | ||||
| 		$expected = array( | ||||
| 			'1. Root', | ||||
| 			'1.1', | ||||
| 			'1.1.2', | ||||
|  | @ -201,10 +206,10 @@ class TreeBehaviorUuidTest extends CakeTestCase { | |||
| 			'1.2.1', | ||||
| 			'1.2.2', | ||||
| 		); | ||||
| 		$this->assertEquals(array_values($nodes), $expects); | ||||
| 		$this->assertEquals($expected, array_values($nodes)); | ||||
| 
 | ||||
| 		$validTree = $this->Tree->verify(); | ||||
| 		$this->assertSame($validTree, true); | ||||
| 		$this->assertTrue($validTree); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -215,24 +220,25 @@ class TreeBehaviorUuidTest extends CakeTestCase { | |||
| 	public function testChildren() { | ||||
| 		extract($this->settings); | ||||
| 		$this->Tree = new $modelClass(); | ||||
| 		$this->Tree->order = null; | ||||
| 		$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->children(null, true, array('name', $leftField, $rightField)); | ||||
| 		$expects = array(array($modelClass => array('name' => '1.1', $leftField => 2, $rightField => 7)), | ||||
| 		$expected = array(array($modelClass => array('name' => '1.1', $leftField => 2, $rightField => 7)), | ||||
| 			array($modelClass => array('name' => '1.2', $leftField => 8, $rightField => 13))); | ||||
| 		$this->assertEquals($direct, $expects); | ||||
| 		$this->assertEquals($expected, $direct); | ||||
| 
 | ||||
| 		$total = $this->Tree->children(null, null, array('name', $leftField, $rightField)); | ||||
| 		$expects = array(array($modelClass => array('name' => '1.1', $leftField => 2, $rightField => 7)), | ||||
| 		$expected = array(array($modelClass => array('name' => '1.1', $leftField => 2, $rightField => 7)), | ||||
| 			array($modelClass => array('name' => '1.1.1', $leftField => 3, $rightField => 4)), | ||||
| 			array($modelClass => array('name' => '1.1.2', $leftField => 5, $rightField => 6)), | ||||
| 			array($modelClass => array('name' => '1.2', $leftField => 8, $rightField => 13)), | ||||
| 			array($modelClass => array('name' => '1.2.1', $leftField => 9, $rightField => 10)), | ||||
| 			array($modelClass => array('name' => '1.2.2', $leftField => 11, $rightField => 12))); | ||||
| 		$this->assertEquals($total, $expects); | ||||
| 		$this->assertEquals($expected, $total); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -243,6 +249,7 @@ class TreeBehaviorUuidTest extends CakeTestCase { | |||
| 	public function testNoAmbiguousColumn() { | ||||
| 		extract($this->settings); | ||||
| 		$this->Tree = new $modelClass(); | ||||
| 		$this->Tree->order = null; | ||||
| 		$this->Tree->initialize(2, 2); | ||||
| 
 | ||||
| 		$this->Tree->bindModel(array('belongsTo' => array('Dummy' => | ||||
|  | @ -255,12 +262,12 @@ class TreeBehaviorUuidTest extends CakeTestCase { | |||
| 		$this->Tree->id = $data[$modelClass]['id']; | ||||
| 
 | ||||
| 		$direct = $this->Tree->children(null, true, array('name', $leftField, $rightField)); | ||||
| 		$expects = array(array($modelClass => array('name' => '1.1', $leftField => 2, $rightField => 7)), | ||||
| 		$expected = array(array($modelClass => array('name' => '1.1', $leftField => 2, $rightField => 7)), | ||||
| 			array($modelClass => array('name' => '1.2', $leftField => 8, $rightField => 13))); | ||||
| 		$this->assertEquals($direct, $expects); | ||||
| 		$this->assertEquals($expected, $direct); | ||||
| 
 | ||||
| 		$total = $this->Tree->children(null, null, array('name', $leftField, $rightField)); | ||||
| 		$expects = array( | ||||
| 		$expected = array( | ||||
| 			array($modelClass => array('name' => '1.1', $leftField => 2, $rightField => 7)), | ||||
| 			array($modelClass => array('name' => '1.1.1', $leftField => 3, $rightField => 4)), | ||||
| 			array($modelClass => array('name' => '1.1.2', $leftField => 5, $rightField => 6)), | ||||
|  | @ -268,7 +275,7 @@ class TreeBehaviorUuidTest extends CakeTestCase { | |||
| 			array($modelClass => array('name' => '1.2.1', $leftField => 9, $rightField => 10)), | ||||
| 			array($modelClass => array('name' => '1.2.2', $leftField => 11, $rightField => 12)) | ||||
| 		); | ||||
| 		$this->assertEquals($total, $expects); | ||||
| 		$this->assertEquals($expected, $total); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -279,12 +286,13 @@ class TreeBehaviorUuidTest extends CakeTestCase { | |||
| 	public function testGenerateTreeListWithSelfJoin() { | ||||
| 		extract($this->settings); | ||||
| 		$this->Tree = new $modelClass(); | ||||
| 		$this->Tree->order = null; | ||||
| 		$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. Root', '_1.1', '__1.1.1', '__1.1.2', '_1.2', '__1.2.1', '__1.2.2'); | ||||
| 		$this->assertSame(array_values($result), $expected); | ||||
| 		$this->assertSame($expected, array_values($result)); | ||||
| 	} | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Brm Ko
						Brm Ko