Browse files

Updating PluginTask to filter out paths that don't exist, and not offer

them as options for baking plugins into.  Fixes #1723
  • Loading branch information...
1 parent 68482be commit 87bccdafe60c8623c471bfa6cba59e4b96e9393f @markstory markstory committed May 22, 2011
View
6 lib/Cake/Console/Command/Task/PluginTask.php
@@ -90,7 +90,6 @@ protected function _interactive($plugin = null) {
public function bake($plugin) {
$pluginPath = Inflector::camelize($plugin);
$pathOptions = App::path('plugins');
- var_dump($pathOptions);
if (count($pathOptions) > 1) {
$this->findPath($pathOptions);
}
@@ -164,6 +163,11 @@ public function bake($plugin) {
*/
public function findPath($pathOptions) {
$valid = false;
+ foreach ($pathOptions as $i =>$path) {
+ if(!is_dir($path)) {
+ array_splice($pathOptions, $i, 1);
+ }
+ }
$max = count($pathOptions);
while (!$valid) {
foreach ($pathOptions as $i => $option) {
View
37 lib/Cake/Test/Case/Console/Command/Task/PluginTaskTest.php
@@ -42,16 +42,21 @@ class PluginTaskTest extends CakeTestCase {
*/
public function setUp() {
parent::setUp();
- $out = $this->getMock('ConsoleOutput', array(), array(), '', false);
- $in = $this->getMock('ConsoleInput', array(), array(), '', false);
+ $this->out = $this->getMock('ConsoleOutput', array(), array(), '', false);
+ $this->in = $this->getMock('ConsoleInput', array(), array(), '', false);
$this->Task = $this->getMock('PluginTask',
array('in', 'err', 'createFile', '_stop', 'clear'),
- array($out, $out, $in)
+ array($this->out, $this->out, $this->in)
);
$this->Task->path = TMP . 'tests' . DS;
$this->_paths = $paths = App::path('plugins');
+ foreach ($paths as $i => $p) {
+ if (!is_dir($p)) {
+ array_splice($paths, $i, 1);
+ }
+ }
$this->_testPath = array_push($paths, TMP . 'tests' . DS);
App::build(array('plugins' => $paths));
}
@@ -159,4 +164,30 @@ public function testExecuteWithOneArg() {
$Folder->delete();
}
+/**
+ * Test that findPath ignores paths that don't exist.
+ *
+ * @return void
+ */
+ public function testFindPathNonExistant() {
+ $paths = App::path('plugins');
+ $last = count($paths);
+ $paths[] = '/fake/path';
+
+ $this->Task = $this->getMock('PluginTask',
+ array('in', 'out', 'err', 'createFile', '_stop'),
+ array($this->out, $this->out, $this->in)
+ );
+ $this->Task->path = TMP . 'tests' . DS;
+
+ // Make sure the added path is filtered out.
+ $this->Task->expects($this->exactly($last))
+ ->method('out');
+
+ $this->Task->expects($this->once())
+ ->method('in')
+ ->will($this->returnValue($last));
+
+ $this->Task->findPath($paths);
+ }
}

0 comments on commit 87bccda

Please sign in to comment.