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

View file

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

View file

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