Fixing the CommandList shell, renaming the TestSuiteShell to TestsuiteShell for BC

This commit is contained in:
Jose Lorenzo Rodriguez 2011-03-08 14:15:44 -04:30
parent 0c9f4c1935
commit 48b3593a25
5 changed files with 22 additions and 27 deletions

View file

@ -16,6 +16,8 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Inflector', 'Utility');
/**
* Shows a list of commands available from the console.
*
@ -79,17 +81,18 @@ class CommandListShell extends Shell {
protected function _getShellList() {
$shellList = array();
$corePaths = App::core('shells');
$shellList = $this->_appendShells('CORE', $corePaths, $shellList);
$shells = App::objects('file', App::core('Console/Command'));
$shellList = $this->_appendShells('CORE', $shells, $shellList);
$appPaths = array_diff(App::path('shells'), $corePaths);
$shellList = $this->_appendShells('app', $appPaths, $shellList);
$appShells = App::objects('Console/Command', null, false);
$shellList = $this->_appendShells('app', $appShells, $shellList);
$plugins = App::objects('plugin');
foreach ($plugins as $plugin) {
$pluginPath = App::pluginPath($plugin) . 'console' . DS . 'shells' . DS;
$shellList = $this->_appendShells($plugin, array($pluginPath), $shellList);
$pluginShells = App::objects($plugin . '.Console/Command');
$shellList = $this->_appendShells($plugin, $pluginShells, $shellList);
}
return $shellList;
}
@ -98,20 +101,10 @@ class CommandListShell extends Shell {
*
* @return array
*/
protected function _appendShells($type, $paths, $shellList) {
foreach ($paths as $path) {
if (!is_dir($path)) {
continue;
}
$shells = App::objects('file', $path);
if (empty($shells)) {
continue;
}
foreach ($shells as $shell) {
$shell = str_replace('Shell.php', '', $shell);
$shellList[$shell][$type] = $type;
}
protected function _appendShells($type, $shells, $shellList) {
foreach ($shells as $shell) {
$shell = Inflector::underscore(str_replace('Shell', '', $shell));
$shellList[$shell][$type] = $type;
}
return $shellList;
}

View file

@ -454,7 +454,7 @@ class App {
if ($type === 'file' && !$path) {
return false;
} elseif ($type === 'file') {
$extension = '/.*/';
$extension = '/\.php$/';
$name = $type . str_replace(DS, '', $path);
}
@ -477,9 +477,10 @@ class App {
$files = new RegexIterator(new DirectoryIterator($dir), $extension);
foreach ($files as $file) {
if (!$file->isDot()) {
if ($file->isDir() && $includeDirectories) {
$isDir = $file->isDir() ;
if ($isDir && $includeDirectories) {
$objects[] = basename($file);
} elseif (!$includeDirectories) {
} elseif (!$includeDirectories && !$isDir) {
$objects[] = substr(basename($file), 0, -4);
}
}

View file

@ -18,6 +18,9 @@
*/
App::uses('CommandListShell', 'Console/Command');
App::uses('ConsoleOutput', 'Console');
App::uses('ConsoleInput', 'Console');
App::uses('Shell', 'Console');
class TestStringOutput extends ConsoleOutput {
@ -40,10 +43,7 @@ class CommandListTest extends CakeTestCase {
'plugins' => array(
LIBS . 'tests' . DS . 'test_app' . DS . 'plugins' . DS
),
'shells' => array(
CORE_PATH ?
CORE_PATH . CAKE . 'console' . DS . 'shells' . DS :
CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'console' . DS . 'shells' .DS,
'Console/Command' => array(
LIBS . 'tests' . DS . 'test_app' . DS . 'console' . DS . 'shells' . DS
)
), true);
@ -84,6 +84,7 @@ class CommandListTest extends CakeTestCase {
$expected = "/welcome \[.*TestPluginTwo.*\]/";
$this->assertPattern($expected, $output);
$expected = "/acl \[.*CORE.*\]/";
$this->assertPattern($expected, $output);