mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
"Fixes #4408, Options for a Behavior are not being reset for associated models using the same behavior"
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6642 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
85f2946c36
commit
89c8467e89
3 changed files with 25 additions and 22 deletions
|
@ -270,25 +270,15 @@ class BehaviorCollection extends Object {
|
|||
$class = $name . 'Behavior';
|
||||
|
||||
if (!App::import('Behavior', $behavior)) {
|
||||
// Raise an error
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isset($this->{$name})) {
|
||||
if (ClassRegistry::isKeySet($class)) {
|
||||
if (PHP5) {
|
||||
$this->{$name} = ClassRegistry::getObject($class);
|
||||
} else {
|
||||
$this->{$name} =& ClassRegistry::getObject($class);
|
||||
}
|
||||
} else {
|
||||
if (PHP5) {
|
||||
$this->{$name} = new $class;
|
||||
} else {
|
||||
$this->{$name} =& new $class;
|
||||
}
|
||||
ClassRegistry::addObject($class, $this->{$name});
|
||||
}
|
||||
} elseif (isset($this->{$name}->settings) && isset($this->{$name}->settings[$this->modelName])) {
|
||||
$config = array_merge($this->{$name}->settings[$this->modelName], $config);
|
||||
}
|
||||
|
@ -297,7 +287,6 @@ class BehaviorCollection extends Object {
|
|||
foreach ($this->{$name}->mapMethods as $method => $alias) {
|
||||
$this->__mappedMethods[$method] = array($alias, $name);
|
||||
}
|
||||
|
||||
$methods = get_class_methods($this->{$name});
|
||||
$parentMethods = get_class_methods('ModelBehavior');
|
||||
$callbacks = array('setup', 'cleanup', 'beforeFind', 'afterFind', 'beforeSave', 'afterSave', 'beforeDelete', 'afterDelete', 'afterError');
|
||||
|
@ -478,5 +467,4 @@ class BehaviorCollection extends Object {
|
|||
return $this->_attached;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -123,14 +123,27 @@ class BehaviorTest extends CakeTestCase {
|
|||
$this->assertIdentical($this->model->Sample->Behaviors->attached(), array());
|
||||
$this->model->Sample->Behaviors->attach('Test', array('key2' => 'value2'));
|
||||
$this->assertIdentical($this->model->Sample->Behaviors->attached(), array('Test'));
|
||||
$this->assertEqual($this->model->Behaviors->Test->settings['Sample'], array('before' => 'on', 'after' => 'off', 'key2' => 'value2'));
|
||||
$this->assertEqual($this->model->Sample->Behaviors->Test->settings['Sample'], array('before' => 'on', 'after' => 'off', 'key2' => 'value2'));
|
||||
|
||||
$this->assertEqual(array_keys($this->model->Behaviors->Test->settings), array('Apple', 'Sample'));
|
||||
$this->assertIdentical($this->model->Behaviors->Test->settings, $this->model->Sample->Behaviors->Test->settings);
|
||||
$this->assertEqual(array_keys($this->model->Behaviors->Test->settings), array('Apple'));
|
||||
$this->assertEqual(array_keys($this->model->Sample->Behaviors->Test->settings), array('Sample'));
|
||||
$this->assertNotIdentical($this->model->Behaviors->Test->settings['Apple'], $this->model->Sample->Behaviors->Test->settings['Sample']);
|
||||
|
||||
$this->model->Behaviors->attach('Test', array('key3' => 'value3', 'before' => 'off'));
|
||||
$this->assertEqual($this->model->Behaviors->Test->settings['Apple'], array('before' => 'off', 'after' => 'off', 'key' => 'value', 'key3' => 'value3'));
|
||||
$this->assertIdentical($this->model->Behaviors->Test->settings, $this->model->Sample->Behaviors->Test->settings);
|
||||
$this->model->Behaviors->attach('Test', array('key2' => 'value2', 'key3' => 'value3', 'before' => 'off'));
|
||||
$this->model->Sample->Behaviors->attach('Test', array('key' => 'value', 'key3' => 'value3', 'before' => 'off'));
|
||||
$this->assertEqual($this->model->Behaviors->Test->settings['Apple'], array('before' => 'off', 'after' => 'off', 'key' => 'value', 'key2' => 'value2', 'key3' => 'value3'));
|
||||
$this->assertEqual($this->model->Behaviors->Test->settings['Apple'], $this->model->Sample->Behaviors->Test->settings['Sample']);
|
||||
|
||||
$this->assertFalse(isset($this->model->Child->Behaviors->Test));
|
||||
$this->model->Child->Behaviors->attach('Test', array('key' => 'value', 'key2' => 'value2', 'key3' => 'value3', 'before' => 'off'));
|
||||
$this->assertEqual($this->model->Child->Behaviors->Test->settings['Child'], $this->model->Sample->Behaviors->Test->settings['Sample']);
|
||||
|
||||
$this->assertFalse(isset($this->model->Parent->Behaviors->Test));
|
||||
$this->model->Parent->Behaviors->attach('Test', array('key' => 'value', 'key2' => 'value2', 'key3' => 'value3', 'before' => 'off'));
|
||||
$this->assertEqual($this->model->Parent->Behaviors->Test->settings['Parent'], $this->model->Sample->Behaviors->Test->settings['Sample']);
|
||||
|
||||
$this->model->Parent->Behaviors->attach('Test', array('key' => 'value', 'key2' => 'value', 'key3' => 'value', 'before' => 'off'));
|
||||
$this->assertNotEqual($this->model->Parent->Behaviors->Test->settings['Parent'], $this->model->Sample->Behaviors->Test->settings['Sample']);
|
||||
}
|
||||
|
||||
function testBehaviorToggling() {
|
||||
|
|
|
@ -445,7 +445,7 @@ class TranslateTest extends CakeTestCase {
|
|||
}
|
||||
|
||||
function testAttachDetach() {
|
||||
$Behavior =& $this->Model->Behaviors->Translate;
|
||||
$Behavior = $this->Model->Behaviors->Translate;
|
||||
|
||||
$this->Model->unbindTranslation();
|
||||
$translations = array('title' => 'Title', 'content' => 'Content');
|
||||
|
@ -478,6 +478,8 @@ class TranslateTest extends CakeTestCase {
|
|||
$result = isset($this->Model->Behaviors->Translate);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$Behavior = $this->Model->Behaviors->Translate;
|
||||
|
||||
$result = isset($Behavior->settings[$this->Model->alias]);
|
||||
$this->assertTrue($result);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue