mirror of
				https://github.com/brmlab/brmsklad.git
				synced 2025-10-31 16:23:59 +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,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); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Brm Ko
						Brm Ko