Skip to content

Commit

Permalink
Adding support for -plugin parameter to TestTask
Browse files Browse the repository at this point in the history
Test cases for plugin path generation added.
  • Loading branch information
markstory committed Jun 7, 2009
1 parent 2181846 commit 44bffc5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
25 changes: 20 additions & 5 deletions cake/console/libs/tasks/test.php
Expand Up @@ -156,16 +156,13 @@ function bake($type, $className) {
$this->Template->set(compact('className', 'methods', 'type', 'fullClassName', 'mock', 'construction'));
$out = $this->Template->generate('objects', 'test');

if (strpos($this->path, $type) === false) {
$this->filePath = $this->path . 'cases' . DS . Inflector::tableize($type) . DS;
}
$made = $this->createFile($this->filePath . Inflector::underscore($fullClassName) . '.test.php', $out);
$filename = $this->testCaseFileName($type, $className);
$made = $this->createFile($filename, $out);
if ($made) {
return $out;
}
return false;
}

/**
* Interact with the user and get their chosen type. Can exit the script.
*
Expand Down Expand Up @@ -400,5 +397,23 @@ function generateConstructor($type, $fullClassName) {
}
return "new $fullClassName()\n";
}

/**
* make the filename for the test case. resolve the suffixes for controllers
* and get the plugin path if needed.
*
* @return string filename the test should be created on
**/
function testCaseFileName($type, $className) {
$path = $this->path;
if (isset($this->plugin)) {
$path = $this->_pluginPath($this->plugin) . 'tests' . DS;
}
$path .= 'cases' . DS . Inflector::tableize($type) . DS;
if (strtolower($type) == 'controller') {
$className = $this->getRealClassName($type, $className);
}
return $path . Inflector::underscore($className) . '.test.php';
}
}
?>
1 change: 1 addition & 0 deletions cake/tests/cases/console/libs/tasks/controller.test.php
Expand Up @@ -256,6 +256,7 @@ function testBakeWithPlugin() {
$this->Task->expectAt(0, 'createFile', array($path, '*'));
$this->Task->bake('Articles', '--actions--', array(), array(), array());
}

/**
* test that bakeActions is creating the correct controller Code. (Using sessions)
*
Expand Down
13 changes: 13 additions & 0 deletions cake/tests/cases/console/libs/tasks/test.test.php
Expand Up @@ -391,6 +391,19 @@ function testMockClassGeneration() {
$this->assertTrue($result);
}

/**
* test bake() with a -plugin param
*
* @return void
**/
function testBakeWithPlugin() {
$this->Task->plugin = 'TestTest';

$path = APP . 'plugins' . DS . 'test_test' . DS . 'tests' . DS . 'cases' . DS . 'helpers' . DS . 'form.test.php';
$this->Task->expectAt(0, 'createFile', array($path, '*'));
$this->Task->bake('Helper', 'Form');
}

/**
* test execute with a type defined
*
Expand Down

0 comments on commit 44bffc5

Please sign in to comment.