diff --git a/cake/console/libs/shell.php b/cake/console/libs/shell.php index 180ffb0ad..596efb31e 100644 --- a/cake/console/libs/shell.php +++ b/cake/console/libs/shell.php @@ -222,13 +222,23 @@ class Shell extends Object { if ($this->uses !== true && !empty($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) { + $plugin = null; + if (strpos($modelClass, '.') !== false) { + list($plugin, $modelClass) = explode('.', $modelClass); + $plugin = $plugin . '.'; + } if (PHP5) { - $this->{$modelClass} = ClassRegistry::init($modelClass); + $this->{$modelClass} = ClassRegistry::init($plugin . $modelClass); } else { - $this->{$modelClass} =& ClassRegistry::init($modelClass); + $this->{$modelClass} =& ClassRegistry::init($plugin . $modelClass); } } return true; diff --git a/cake/tests/cases/console/shell.test.php b/cake/tests/cases/console/shell.test.php new file mode 100644 index 000000000..86b1f9921 --- /dev/null +++ b/cake/tests/cases/console/shell.test.php @@ -0,0 +1,124 @@ + + * 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.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 + */ +App::import('Core', 'Shell'); + +if (!defined('DISABLE_AUTO_DISPATCH')) { + define('DISABLE_AUTO_DISPATCH', true); +} + +if (!class_exists('ShellDispatcher')) { + ob_start(); + $argv = false; + require CAKE . 'console' . DS . 'cake.php'; + ob_end_clean(); +} + +/** + * Test Shell class + * + * @package cake.tests + * @subpackage cake.tests.cases.libs + */ +class TestShell extends Shell { + +} + +Mock::generate('ShellDispatcher'); + +/** + * Test case class for shell + * + * @package cake.tests + * @subpackage cake.tests.cases.libs + */ +class CakeShellTestCase extends CakeTestCase { + + var $fixtures = array('core.post', 'core.comment'); +/** + * setup + * + * @return void + **/ + function setUp() { + $this->Dispatcher =& new MockShellDispatcher(); + $this->Shell =& new TestShell($this->Dispatcher); + } + + function testInitialize() { + $_back = array( + 'modelPaths' => Configure::read('modelPaths'), + 'pluginPaths' => Configure::read('pluginPaths'), + 'viewPaths' => Configure::read('viewPaths'), + ); + Configure::write('pluginPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)); + Configure::write('modelPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS)); + $this->Shell->uses = array('TestPlugin.TestPluginPost'); + $this->Shell->initialize(); + + $this->assertTrue(isset($this->Shell->TestPluginPost)); + $this->assertTrue(is_a($this->Shell->TestPluginPost, 'TestPluginPost')); + $this->assertEqual($this->Shell->modelClass, 'TestPluginPost'); + + $this->Shell->uses = array('Comment'); + $this->Shell->initialize(); + $this->assertTrue(isset($this->Shell->Comment)); + $this->assertTrue(is_a($this->Shell->Comment, 'Comment')); + $this->assertEqual($this->Shell->modelClass, 'Comment'); + + Configure::write('pluginPaths', $_back['pluginPaths']); + Configure::write('modelPaths', $_back['modelPaths']); + } + +/** + * Test Loading of Tasks + * + * @return void + **/ + function testLoadTasks() { + + } +/** + * test ShortPath + * + * @return void + **/ + function testShortPath() { + + } +/** + * test File creation + * + * @return void + **/ + function createFile() { + + } +} + +?> \ No newline at end of file diff --git a/cake/tests/test_app/models/comment.php b/cake/tests/test_app/models/comment.php new file mode 100644 index 000000000..1cd694e1c --- /dev/null +++ b/cake/tests/test_app/models/comment.php @@ -0,0 +1,33 @@ + + * 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.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 Comment extends AppModel { + var $useTable = 'comments'; + var $name = 'Comment'; +} +?> \ No newline at end of file