mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 17:16:18 +00:00
Adding fix for Model::afterFind(); not having access to $this->data when using TreeBehavior
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7586 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
8e6a5a7214
commit
a6f19c8240
4 changed files with 117 additions and 2 deletions
|
@ -803,10 +803,11 @@ class TreeBehavior extends ModelBehavior {
|
|||
}
|
||||
if (empty ($node[$left]) && empty ($node[$right])) {
|
||||
$this->__sync($model, 2, '+', '>= ' . $parentNode[$right], $created);
|
||||
$model->save(
|
||||
$result = $model->save(
|
||||
array($left => $parentNode[$right], $right => $parentNode[$right] + 1, $parent => $parentId),
|
||||
array('validate' => false, 'callbacks' => false)
|
||||
);
|
||||
$model->data = $result;
|
||||
} else {
|
||||
$this->__sync($model, $edge - $node[$left] +1, '+', 'BETWEEN ' . $node[$left] . ' AND ' . $node[$right], $created);
|
||||
$diff = $node[$right] - $node[$left] + 1;
|
||||
|
|
|
@ -44,7 +44,7 @@ class NumberTreeCase extends CakeTestCase {
|
|||
* @access public
|
||||
*/
|
||||
var $fixtures = array(
|
||||
'core.number_tree', 'core.flag_tree', 'core.campaign', 'core.ad', 'core.translate'
|
||||
'core.number_tree', 'core.flag_tree', 'core.campaign', 'core.ad', 'core.translate', 'core.after_tree'
|
||||
);
|
||||
/**
|
||||
* testInitialize method
|
||||
|
@ -1344,5 +1344,22 @@ class NumberTreeCase extends CakeTestCase {
|
|||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
/**
|
||||
* Tests the afterSave callback in the model
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testAftersaveCallback() {
|
||||
$this->AfterTree =& new AfterTree();
|
||||
|
||||
$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->AfterTree->save(array('AfterTree' => array('name' => 'Six and One Half', 'parent_id' => 6)));
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$expected = array('AfterTree' => array('name' => 'Six and One Half', 'parent_id' => 6, 'lft' => 11, 'rght' => 12, 'id' => 8));
|
||||
$result = $this->AfterTree->findAll();
|
||||
$this->assertEqual($result[7], $expected);
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -2273,6 +2273,34 @@ class Ad extends CakeTestModel {
|
|||
*/
|
||||
var $belongsTo = array('Campaign');
|
||||
}
|
||||
/**
|
||||
* Ad class
|
||||
*
|
||||
* @package cake.tests
|
||||
* @subpackage cake.tests.cases.libs.model
|
||||
*/
|
||||
class AfterTree extends CakeTestModel {
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'AfterTree'
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'AfterTree';
|
||||
/**
|
||||
* actsAs property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $actsAs = array('Tree');
|
||||
|
||||
function afterSave($created) {
|
||||
if ($created && isset($this->data['AfterTree'])) {
|
||||
$this->data['AfterTree']['name'] = 'Six and One Half Changed in AfterTree::afterSave() but not in database';
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Nonconformant Content class
|
||||
*
|
||||
|
|
69
cake/tests/fixtures/after_tree_fixture.php
vendored
Normal file
69
cake/tests/fixtures/after_tree_fixture.php
vendored
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* Short description for after_tree_fixture.php
|
||||
*
|
||||
* Long description for after_tree_fixture.php
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* @link http://www.cakephp.org
|
||||
* @package cake
|
||||
* @subpackage cake.tests.fixtures
|
||||
* @since 1.2
|
||||
* @version $Revision$
|
||||
* @modifiedBy $LastChangedBy$
|
||||
* @lastModified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
/**
|
||||
* AdFixture class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.fixtures
|
||||
*/
|
||||
class AfterTreeFixture extends CakeTestFixture {
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'AfterTree'
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'AfterTree';
|
||||
/**
|
||||
* fields property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $fields = array(
|
||||
'id' => array('type' => 'integer', 'key' => 'primary'),
|
||||
'parent_id' => array('type' => 'integer'),
|
||||
'lft' => array('type' => 'integer'),
|
||||
'rght' => array('type' => 'integer'),
|
||||
'name' => array('type' => 'string', 'length' => 255, 'null' => false)
|
||||
);
|
||||
/**
|
||||
* records property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $records = array(
|
||||
array('parent_id' => null, 'lft' => 1, 'rght' => 2, 'name' => 'One'),
|
||||
array('parent_id' => null, 'lft' => 3, 'rght' => 4, 'name' => 'Two'),
|
||||
array('parent_id' => null, 'lft' => 5, 'rght' => 6, 'name' => 'Three'),
|
||||
array('parent_id' => null, 'lft' => 7, 'rght' => 12, 'name' => 'Four'),
|
||||
array('parent_id' => null, 'lft' => 8, 'rght' => 9, 'name' => 'Five'),
|
||||
array('parent_id' => null, 'lft' => 10, 'rght' => 11, 'name' => 'Six'),
|
||||
array('parent_id' => null, 'lft' => 13, 'rght' => 14, 'name' => 'Seven')
|
||||
);
|
||||
}
|
||||
?>
|
Loading…
Add table
Reference in a new issue