Permalink
Browse files

Fixing persitModel and plugin Behaviors. Closes #192

  • Loading branch information...
1 parent 5149d65 commit 4e3aedecde62e30c726e2f60aba4d7b8f6b5030b @lorenzo lorenzo committed Jan 13, 2010
@@ -286,6 +286,9 @@ function attach($behavior, $config = array()) {
$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) {
@@ -425,10 +425,12 @@ function testPersistWithBehavior() {
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,18 +441,19 @@ function testPersistWithBehavior() {
$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;
$Controller->constructClasses();
$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,16 +487,28 @@ function testPersistWithBehaviorAndRequestAction() {
$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');
$Controller->render('index', 'ajax', '/layouts/ajax');
$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);
@@ -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');
}
@@ -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');
}
@@ -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 {
+
+
+}
+?>

0 comments on commit 4e3aede

Please sign in to comment.