Adding Test case for Shell

Adding Comment Model to test_app
Fixing Plugin model loading in Shells, fixes #5566

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7726 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mark_story 2008-10-10 02:14:57 +00:00
parent aa217716b9
commit f94bc3e4bc
3 changed files with 170 additions and 3 deletions

View file

@ -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;

View file

@ -0,0 +1,124 @@
<?php
/* SVN FILE: $Id$ */
/**
* Test Case for Shell
*
*
*
* 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.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() {
}
}
?>

View file

@ -0,0 +1,33 @@
<?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.
* 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';
}
?>