Fixing modelClass when using plugin models.

Added TestPluginPost to test_app/test_plugin
Test case added.
Closes #5459

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7641 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mark_story 2008-09-22 04:10:49 +00:00
parent d9b357d05c
commit fafb01b09d
3 changed files with 63 additions and 1 deletions

View file

@ -394,7 +394,11 @@ class Controller extends Object {
$this->loadModel($this->modelClass, $id);
} elseif ($this->uses) {
$uses = is_array($this->uses) ? $this->uses : array($this->uses);
$this->modelClass = $uses[0];
$modelClassName = $uses[0];
if (strpos($uses[0], '.') !== false) {
list($plugin, $modelClassName) = explode('.', $uses[0]);
}
$this->modelClass = $modelClassName;
foreach ($uses as $modelClass) {
$this->loadModel($modelClass);
}

View file

@ -318,6 +318,22 @@ class ControllerTest extends CakeTestCase {
$this->assertEqual($Controller->ControllerComment->name, 'Comment');
unset($Controller);
$_back = array(
'pluginPaths' => Configure::read('pluginPaths'),
);
Configure::write('pluginPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS));
$Controller =& new Controller();
$Controller->uses = array('TestPlugin.TestPluginPost');
$Controller->constructClasses();
$this->assertEqual($Controller->modelClass, 'TestPluginPost');
$this->assertTrue(isset($Controller->TestPluginPost));
$this->assertTrue(is_a($Controller->TestPluginPost, 'TestPluginPost'));
Configure::write('pluginPaths', $_back['pluginPaths']);
unset($Controller);
}
function testAliasName() {

View file

@ -0,0 +1,42 @@
<?php
/* SVN FILE: $Id$ */
/**
* Test Plugin Post Model
*
*
*
* PHP versions 4 and 5
*
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
* Copyright 2006-2008, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
*
* 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.tests.test_app.plugins.test_plugin
* @since CakePHP v 1.2.0.4487
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
class TestPluginPost extends TestPluginAppModel {
/**
* Name property
*
* @var string
*/
var $name = 'Post';
/**
* useTable property
*
* @var string
*/
var $useTable = 'posts';
}