From 4e3aedecde62e30c726e2f60aba4d7b8f6b5030b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Lorenzo=20Rodr=C3=ADguez?= Date: Wed, 13 Jan 2010 09:21:36 -0430 Subject: [PATCH] Fixing persitModel and plugin Behaviors. Closes #192 --- cake/libs/model/behavior.php | 3 ++ cake/tests/cases/libs/object.test.php | 23 +++++++++-- cake/tests/test_app/models/persister_one.php | 2 +- cake/tests/test_app/models/persister_two.php | 2 +- .../behaviors/test_plugin_persister_one.php | 38 +++++++++++++++++++ .../behaviors/test_plugin_persister_two.php | 38 +++++++++++++++++++ 6 files changed, 100 insertions(+), 6 deletions(-) create mode 100644 cake/tests/test_app/plugins/test_plugin/models/behaviors/test_plugin_persister_one.php create mode 100644 cake/tests/test_app/plugins/test_plugin/models/behaviors/test_plugin_persister_two.php diff --git a/cake/libs/model/behavior.php b/cake/libs/model/behavior.php index fdbc64e30..0f994c2c9 100644 --- a/cake/libs/model/behavior.php +++ b/cake/libs/model/behavior.php @@ -286,6 +286,9 @@ class BehaviorCollection extends Object { $this->{$name} =& new $class; } ClassRegistry::addObject($class, $this->{$name}); + if (!empty($plugin)) { + ClassRegistry::addObject($plugin.'.'.$class, $clas); + } } } elseif (isset($this->{$name}->settings) && isset($this->{$name}->settings[$this->modelName])) { if ($config !== null && $config !== false) { diff --git a/cake/tests/cases/libs/object.test.php b/cake/tests/cases/libs/object.test.php index 743d88da1..3ce6fbbfd 100644 --- a/cake/tests/cases/libs/object.test.php +++ b/cake/tests/cases/libs/object.test.php @@ -425,10 +425,12 @@ class ObjectTest extends CakeTestCase { Configure::write('Cache.disable', false); 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)); $this->assertFalse(class_exists('PersisterOneBehaviorBehavior')); $this->assertFalse(class_exists('PersisterTwoBehaviorBehavior')); + $this->assertFalse(class_exists('TestPluginPersisterBehavior')); $Controller = new RequestActionPersistentController(); $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('persister_one_', 'persister_two_', file_get_contents(CACHE . 'persistent' . DS . 'persisteroneregistry.php')); - $result = file_put_contents(CACHE . 'persistent' . DS . 'persisteroneregistry.php', $contents); $this->assertTrue(class_exists('PersisterOneBehaviorBehavior')); $this->assertFalse(class_exists('PersisterTwoBehaviorBehavior')); + $this->assertFalse(class_exists('TestPluginPersisterTwoBehavior')); $Controller = new RequestActionPersistentController(); $Controller->persistModel = true; @@ -451,6 +453,7 @@ class ObjectTest extends CakeTestCase { $this->assertTrue(class_exists('PersisterOneBehaviorBehavior')); $this->assertTrue(class_exists('PersisterTwoBehaviorBehavior')); + $this->assertTrue(class_exists('TestPluginPersisterTwoBehavior')); @unlink(CACHE . 'persistent' . DS . 'persisterone.php'); @unlink(CACHE . 'persistent' . DS . 'persisteroneregistry.php'); @@ -484,7 +487,13 @@ class ObjectTest extends CakeTestCase { $this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'persisteroneregistry.php')); $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(); $Controller->set('content_for_layout', 'cool'); @@ -492,8 +501,14 @@ class ObjectTest extends CakeTestCase { $result = ob_get_clean(); $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'); $expected = 'This is a test'; $this->assertEqual($result, $expected); diff --git a/cake/tests/test_app/models/persister_one.php b/cake/tests/test_app/models/persister_one.php index 76222829f..37fd2b4ef 100644 --- a/cake/tests/test_app/models/persister_one.php +++ b/cake/tests/test_app/models/persister_one.php @@ -28,7 +28,7 @@ class PersisterOne extends AppModel { var $useTable = 'posts'; var $name = 'PersisterOne'; - var $actsAs = array('PersisterOneBehavior'); + var $actsAs = array('PersisterOneBehavior','TestPlugin.TestPluginPersisterOne'); var $hasMany = array('Comment'); } diff --git a/cake/tests/test_app/models/persister_two.php b/cake/tests/test_app/models/persister_two.php index 4596f9479..36d2423da 100644 --- a/cake/tests/test_app/models/persister_two.php +++ b/cake/tests/test_app/models/persister_two.php @@ -28,7 +28,7 @@ class PersisterTwo extends AppModel { var $useTable = 'posts'; var $name = 'PersisterTwo'; - var $actsAs = array('PersisterOneBehavior'); + var $actsAs = array('PersisterOneBehavior','TestPlugin.TestPluginPersisterOne'); var $hasMany = array('Comment'); } diff --git a/cake/tests/test_app/plugins/test_plugin/models/behaviors/test_plugin_persister_one.php b/cake/tests/test_app/plugins/test_plugin/models/behaviors/test_plugin_persister_one.php new file mode 100644 index 000000000..5530fd286 --- /dev/null +++ b/cake/tests/test_app/plugins/test_plugin/models/behaviors/test_plugin_persister_one.php @@ -0,0 +1,38 @@ + \ No newline at end of file diff --git a/cake/tests/test_app/plugins/test_plugin/models/behaviors/test_plugin_persister_two.php b/cake/tests/test_app/plugins/test_plugin/models/behaviors/test_plugin_persister_two.php new file mode 100644 index 000000000..89f2def32 --- /dev/null +++ b/cake/tests/test_app/plugins/test_plugin/models/behaviors/test_plugin_persister_two.php @@ -0,0 +1,38 @@ + \ No newline at end of file