Skip to content
Permalink
Browse files

Fixing issue with persistModels and plugin models, closes #192 and #198

  • Loading branch information...
lorenzo committed Jan 18, 2010
1 parent 8f2a4a1 commit cb4a1f07e5e0c2e7feb90e18b6faa2130f84d3ca
@@ -667,6 +667,9 @@ function __constructLinkedModel($assoc, $className = null) {
} else {
$this->{$assoc} =& ClassRegistry::init($model);
}
if (strpos($className, '.') !== false) {
ClassRegistry::addObject($className, $this->{$assoc});
}
if ($assoc) {
$this->tableToModel[$this->{$assoc}->table] = $assoc;
}
@@ -275,7 +275,7 @@ function __openPersistent($name, $type = null) {
if (strpos($key, '_behavior') !== false) {
App::import('Behavior', Inflector::classify(substr($key, 0, -9)));
} else {
App::import('Model', Inflector::classify($key));
App::import('Model', Inflector::camelize($key));
}
unset ($value);
}
@@ -431,6 +431,7 @@ function testPersistWithBehavior() {
$this->assertFalse(class_exists('PersisterOneBehaviorBehavior'));
$this->assertFalse(class_exists('PersisterTwoBehaviorBehavior'));
$this->assertFalse(class_exists('TestPluginPersisterBehavior'));
$this->assertFalse(class_exists('TestPluginAuthors'));
$Controller = new RequestActionPersistentController();
$Controller->persistModel = true;
@@ -439,13 +440,18 @@ function testPersistWithBehavior() {
$this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'persisterone.php'));
$this->assertTrue(file_exists(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 = file_get_contents(CACHE . 'persistent' . DS . 'persisteroneregistry.php');
$contents = str_replace('"PersisterOne"', '"PersisterTwo"', $contents);
$contents = str_replace('persister_one', 'persister_two', $contents);
$contents = str_replace('test_plugin_comment', 'test_plugin_authors', $contents);
$result = file_put_contents(CACHE . 'persistent' . DS . 'persisteroneregistry.php', $contents);
$this->assertTrue(class_exists('PersisterOneBehaviorBehavior'));
$this->assertTrue(class_exists('TestPluginPersisterOneBehavior'));
$this->assertTrue(class_exists('TestPluginComment'));
$this->assertFalse(class_exists('PersisterTwoBehaviorBehavior'));
$this->assertFalse(class_exists('TestPluginPersisterTwoBehavior'));
$this->assertFalse(class_exists('TestPluginAuthors'));
$Controller = new RequestActionPersistentController();
$Controller->persistModel = true;
@@ -454,6 +460,7 @@ function testPersistWithBehavior() {
$this->assertTrue(class_exists('PersisterOneBehaviorBehavior'));
$this->assertTrue(class_exists('PersisterTwoBehaviorBehavior'));
$this->assertTrue(class_exists('TestPluginPersisterTwoBehavior'));
$this->assertTrue(class_exists('TestPluginAuthors'));
@unlink(CACHE . 'persistent' . DS . 'persisterone.php');
@unlink(CACHE . 'persistent' . DS . 'persisteroneregistry.php');
@@ -490,6 +497,8 @@ function testPersistWithBehaviorAndRequestAction() {
$this->assertEqual($keys, array(
'persister_one',
'comment',
'test_plugin_comment',
'test_plugin.test_plugin_comment',
'persister_one_behavior_behavior',
'test_plugin_persister_one_behavior',
'test_plugin.test_plugin_persister_one_behavior'
@@ -504,6 +513,8 @@ function testPersistWithBehaviorAndRequestAction() {
$this->assertEqual($keys, array(
'persister_one',
'comment',
'test_plugin_comment',
'test_plugin.test_plugin_comment',
'persister_one_behavior_behavior',
'test_plugin_persister_one_behavior',
'test_plugin.test_plugin_persister_one_behavior',
@@ -28,8 +28,8 @@ class PersisterOne extends AppModel {
var $useTable = 'posts';
var $name = 'PersisterOne';
var $actsAs = array('PersisterOneBehavior','TestPlugin.TestPluginPersisterOne');
var $actsAs = array('PersisterOneBehavior', 'TestPlugin.TestPluginPersisterOne');
var $hasMany = array('Comment');
var $hasMany = array('Comment', 'TestPlugin.TestPluginComment');
}
?>
@@ -28,8 +28,8 @@ class PersisterTwo extends AppModel {
var $useTable = 'posts';
var $name = 'PersisterTwo';
var $actsAs = array('PersisterOneBehavior','TestPlugin.TestPluginPersisterOne');
var $actsAs = array('PersisterOneBehavior', 'TestPlugin.TestPluginPersisterOne');
var $hasMany = array('Comment');
var $hasMany = array('Comment', 'TestPlugin.TestPluginComment');
}
?>
@@ -0,0 +1,31 @@
<?php
/* SVN FILE: $Id$ */
/**
* Test App Comment Model
*
*
*
* PHP versions 4 and 5
*
* CakePHP : Rapid Development Framework (http://www.cakephp.org)
* Copyright 2006-2008, Cake Software Foundation, Inc.
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
* @package cake
* @subpackage cake.cake.libs.
* @since CakePHP v 1.2.0.7726
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
class TestPluginAuthors extends TestPluginAppModel {
var $useTable = 'authors';
var $name = 'TestPluginAuthors';
}
?>
@@ -0,0 +1,31 @@
<?php
/* SVN FILE: $Id$ */
/**
* Test App Comment Model
*
*
*
* PHP versions 4 and 5
*
* CakePHP : Rapid Development Framework (http://www.cakephp.org)
* Copyright 2006-2008, Cake Software Foundation, Inc.
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
* @package cake
* @subpackage cake.cake.libs.
* @since CakePHP v 1.2.0.7726
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
class TestPluginComment extends TestPluginAppModel {
var $useTable = 'comments';
var $name = 'TestPluginComment';
}
?>

0 comments on commit cb4a1f0

Please sign in to comment.
You can’t perform that action at this time.