mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Fixing persitModel and plugin Behaviors. Closes #192
This commit is contained in:
parent
5149d65c7e
commit
4e3aedecde
6 changed files with 100 additions and 6 deletions
|
@ -286,6 +286,9 @@ class BehaviorCollection extends Object {
|
||||||
$this->{$name} =& new $class;
|
$this->{$name} =& new $class;
|
||||||
}
|
}
|
||||||
ClassRegistry::addObject($class, $this->{$name});
|
ClassRegistry::addObject($class, $this->{$name});
|
||||||
|
if (!empty($plugin)) {
|
||||||
|
ClassRegistry::addObject($plugin.'.'.$class, $clas);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} elseif (isset($this->{$name}->settings) && isset($this->{$name}->settings[$this->modelName])) {
|
} elseif (isset($this->{$name}->settings) && isset($this->{$name}->settings[$this->modelName])) {
|
||||||
if ($config !== null && $config !== false) {
|
if ($config !== null && $config !== false) {
|
||||||
|
|
|
@ -425,10 +425,12 @@ class ObjectTest extends CakeTestCase {
|
||||||
Configure::write('Cache.disable', false);
|
Configure::write('Cache.disable', false);
|
||||||
|
|
||||||
Configure::write('modelPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models'. DS));
|
Configure::write('modelPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models'. DS));
|
||||||
|
Configure::write('pluginPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins'. DS));
|
||||||
Configure::write('behaviorPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models'. DS . 'behaviors' . DS));
|
Configure::write('behaviorPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models'. DS . 'behaviors' . DS));
|
||||||
|
|
||||||
$this->assertFalse(class_exists('PersisterOneBehaviorBehavior'));
|
$this->assertFalse(class_exists('PersisterOneBehaviorBehavior'));
|
||||||
$this->assertFalse(class_exists('PersisterTwoBehaviorBehavior'));
|
$this->assertFalse(class_exists('PersisterTwoBehaviorBehavior'));
|
||||||
|
$this->assertFalse(class_exists('TestPluginPersisterBehavior'));
|
||||||
|
|
||||||
$Controller = new RequestActionPersistentController();
|
$Controller = new RequestActionPersistentController();
|
||||||
$Controller->persistModel = true;
|
$Controller->persistModel = true;
|
||||||
|
@ -439,11 +441,11 @@ class ObjectTest extends CakeTestCase {
|
||||||
|
|
||||||
$contents = str_replace('"PersisterOne"', '"PersisterTwo"', file_get_contents(CACHE . 'persistent' . DS . 'persisteroneregistry.php'));
|
$contents = str_replace('"PersisterOne"', '"PersisterTwo"', file_get_contents(CACHE . 'persistent' . DS . 'persisteroneregistry.php'));
|
||||||
$contents = str_replace('persister_one_', 'persister_two_', file_get_contents(CACHE . 'persistent' . DS . 'persisteroneregistry.php'));
|
$contents = str_replace('persister_one_', 'persister_two_', file_get_contents(CACHE . 'persistent' . DS . 'persisteroneregistry.php'));
|
||||||
|
|
||||||
$result = file_put_contents(CACHE . 'persistent' . DS . 'persisteroneregistry.php', $contents);
|
$result = file_put_contents(CACHE . 'persistent' . DS . 'persisteroneregistry.php', $contents);
|
||||||
|
|
||||||
$this->assertTrue(class_exists('PersisterOneBehaviorBehavior'));
|
$this->assertTrue(class_exists('PersisterOneBehaviorBehavior'));
|
||||||
$this->assertFalse(class_exists('PersisterTwoBehaviorBehavior'));
|
$this->assertFalse(class_exists('PersisterTwoBehaviorBehavior'));
|
||||||
|
$this->assertFalse(class_exists('TestPluginPersisterTwoBehavior'));
|
||||||
|
|
||||||
$Controller = new RequestActionPersistentController();
|
$Controller = new RequestActionPersistentController();
|
||||||
$Controller->persistModel = true;
|
$Controller->persistModel = true;
|
||||||
|
@ -451,6 +453,7 @@ class ObjectTest extends CakeTestCase {
|
||||||
|
|
||||||
$this->assertTrue(class_exists('PersisterOneBehaviorBehavior'));
|
$this->assertTrue(class_exists('PersisterOneBehaviorBehavior'));
|
||||||
$this->assertTrue(class_exists('PersisterTwoBehaviorBehavior'));
|
$this->assertTrue(class_exists('PersisterTwoBehaviorBehavior'));
|
||||||
|
$this->assertTrue(class_exists('TestPluginPersisterTwoBehavior'));
|
||||||
|
|
||||||
@unlink(CACHE . 'persistent' . DS . 'persisterone.php');
|
@unlink(CACHE . 'persistent' . DS . 'persisterone.php');
|
||||||
@unlink(CACHE . 'persistent' . DS . 'persisteroneregistry.php');
|
@unlink(CACHE . 'persistent' . DS . 'persisteroneregistry.php');
|
||||||
|
@ -484,7 +487,13 @@ class ObjectTest extends CakeTestCase {
|
||||||
$this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'persisteroneregistry.php'));
|
$this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'persisteroneregistry.php'));
|
||||||
|
|
||||||
$keys = ClassRegistry::keys();
|
$keys = ClassRegistry::keys();
|
||||||
$this->assertEqual($keys, array('persister_one', 'comment', 'persister_one_behavior_behavior'));
|
$this->assertEqual($keys, array(
|
||||||
|
'persister_one',
|
||||||
|
'comment',
|
||||||
|
'persister_one_behavior_behavior',
|
||||||
|
'test_plugin_persister_one_behavior',
|
||||||
|
'test_plugin.test_plugin_persister_one_behavior'
|
||||||
|
));
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
$Controller->set('content_for_layout', 'cool');
|
$Controller->set('content_for_layout', 'cool');
|
||||||
|
@ -492,8 +501,14 @@ class ObjectTest extends CakeTestCase {
|
||||||
$result = ob_get_clean();
|
$result = ob_get_clean();
|
||||||
|
|
||||||
$keys = ClassRegistry::keys();
|
$keys = ClassRegistry::keys();
|
||||||
$this->assertEqual($keys, array('persister_one', 'comment', 'persister_one_behavior_behavior', 'view'));
|
$this->assertEqual($keys, array(
|
||||||
|
'persister_one',
|
||||||
|
'comment',
|
||||||
|
'persister_one_behavior_behavior',
|
||||||
|
'test_plugin_persister_one_behavior',
|
||||||
|
'test_plugin.test_plugin_persister_one_behavior',
|
||||||
|
'view'
|
||||||
|
));
|
||||||
$result = $this->object->requestAction('/request_action_persistent/index');
|
$result = $this->object->requestAction('/request_action_persistent/index');
|
||||||
$expected = 'This is a test';
|
$expected = 'This is a test';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
|
@ -28,7 +28,7 @@ class PersisterOne extends AppModel {
|
||||||
var $useTable = 'posts';
|
var $useTable = 'posts';
|
||||||
var $name = 'PersisterOne';
|
var $name = 'PersisterOne';
|
||||||
|
|
||||||
var $actsAs = array('PersisterOneBehavior');
|
var $actsAs = array('PersisterOneBehavior','TestPlugin.TestPluginPersisterOne');
|
||||||
|
|
||||||
var $hasMany = array('Comment');
|
var $hasMany = array('Comment');
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ class PersisterTwo extends AppModel {
|
||||||
var $useTable = 'posts';
|
var $useTable = 'posts';
|
||||||
var $name = 'PersisterTwo';
|
var $name = 'PersisterTwo';
|
||||||
|
|
||||||
var $actsAs = array('PersisterOneBehavior');
|
var $actsAs = array('PersisterOneBehavior','TestPlugin.TestPluginPersisterOne');
|
||||||
|
|
||||||
var $hasMany = array('Comment');
|
var $hasMany = array('Comment');
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
<?php
|
||||||
|
/* SVN FILE: $Id$ */
|
||||||
|
/**
|
||||||
|
* Behavior for binding management.
|
||||||
|
*
|
||||||
|
* Behavior to simplify manipulating a model's bindings when doing a find operation
|
||||||
|
*
|
||||||
|
* PHP versions 4 and 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
|
||||||
|
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @filesource
|
||||||
|
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
||||||
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.test_app.models
|
||||||
|
* @since CakePHP(tm) v 1.2.0.5669
|
||||||
|
* @version $Revision$
|
||||||
|
* @modifiedby $LastChangedBy$
|
||||||
|
* @lastmodified $Date$
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Behavior to allow for dynamic and atomic manipulation of a Model's associations used for a find call. Most useful for limiting
|
||||||
|
* the amount of associations and data returned.
|
||||||
|
*
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.cake.console.libs
|
||||||
|
*/
|
||||||
|
class TestPluginPersisterOneBehavior extends ModelBehavior {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
|
@ -0,0 +1,38 @@
|
||||||
|
<?php
|
||||||
|
/* SVN FILE: $Id$ */
|
||||||
|
/**
|
||||||
|
* Behavior for binding management.
|
||||||
|
*
|
||||||
|
* Behavior to simplify manipulating a model's bindings when doing a find operation
|
||||||
|
*
|
||||||
|
* PHP versions 4 and 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
|
||||||
|
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @filesource
|
||||||
|
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
||||||
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.tests.test_app.models
|
||||||
|
* @since CakePHP(tm) v 1.2.0.5669
|
||||||
|
* @version $Revision$
|
||||||
|
* @modifiedby $LastChangedBy$
|
||||||
|
* @lastmodified $Date$
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Behavior to allow for dynamic and atomic manipulation of a Model's associations used for a find call. Most useful for limiting
|
||||||
|
* the amount of associations and data returned.
|
||||||
|
*
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.cake.console.libs
|
||||||
|
*/
|
||||||
|
class TestPluginPersisterTwoBehavior extends ModelBehavior {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
Loading…
Add table
Reference in a new issue