Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding -plugin support to Controller Task

Test cases added.
  • Loading branch information...
commit 4d89086146e8635535f4a690dcefbae0b5f716b0 1 parent 375e175
@markstory markstory authored
View
6 cake/console/libs/tasks/controller.php
@@ -310,7 +310,11 @@ function bake($controllerName, $actions = '', $helpers = null, $components = nul
$this->Template->set(compact('controllerName', 'actions', 'helpers', 'components', 'isScaffold'));
$contents = $this->Template->generate('objects', 'controller');
- $filename = $this->path . $this->_controllerPath($controllerName) . '_controller.php';
+ $path = $this->path;
+ if (isset($this->plugin)) {
+ $path = $this->_pluginPath($this->plugin) . 'controllers' . DS;
+ }
+ $filename = $path . $this->_controllerPath($controllerName) . '_controller.php';
if ($this->createFile($filename, $contents)) {
return $contents;
}
View
40 cake/tests/cases/console/libs/tasks/controller.test.php
@@ -34,6 +34,7 @@
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'controller.php';
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'model.php';
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
+require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'test.php';
Mock::generatePartial(
@@ -51,6 +52,8 @@
array('in', 'out', 'err', 'createFile', '_stop', '_checkUnitTest')
);
+Mock::generate('TestTask', 'ControllerMockTestTask');
+
$imported = App::import('Model', 'Article');
$imported = $imported || App::import('Model', 'Comment');
$imported = $imported || App::import('Model', 'Tag');
@@ -223,16 +226,15 @@ function testConfirmController() {
function testBake() {
$helpers = array('Ajax', 'Time');
$components = array('Acl', 'Auth');
- $uses = array('Comment', 'User');
$this->Task->setReturnValue('createFile', true);
- $result = $this->Task->bake('Articles', '--actions--', $helpers, $components, $uses);
+ $result = $this->Task->bake('Articles', '--actions--', $helpers, $components);
$this->assertPattern('/class ArticlesController extends AppController/', $result);
$this->assertPattern('/\$components \= array\(\'Acl\', \'Auth\'\)/', $result);
$this->assertPattern('/\$helpers \= array\(\'Html\', \'Form\', \'Ajax\', \'Time\'\)/', $result);
$this->assertPattern('/\-\-actions\-\-/', $result);
- $result = $this->Task->bake('Articles', 'scaffold', $helpers, $components, $uses);
+ $result = $this->Task->bake('Articles', 'scaffold', $helpers, $components);
$this->assertPattern('/class ArticlesController extends AppController/', $result);
$this->assertPattern('/var \$scaffold/', $result);
$this->assertNoPattern('/helpers/', $result);
@@ -240,6 +242,21 @@ function testBake() {
}
/**
+ * test bake() with a -plugin param
+ *
+ * @return void
+ **/
+ function testBakeWithPlugin() {
+ $this->Task->plugin = 'ControllerTest';
+ $helpers = array('Ajax', 'Time');
+ $components = array('Acl', 'Auth');
+ $uses = array('Comment', 'User');
+
+ $path = APP . 'plugins' . DS . 'controller_test' . DS . 'controllers' . DS . 'articles_controller.php';
+ $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)
*
* @return void
@@ -318,6 +335,23 @@ function testBakeActionsWithNoSessions() {
}
/**
+ * test baking a test
+ *
+ * @return void
+ **/
+ function testBakeTest() {
+ $this->Task->plugin = 'ControllerTest';
+ $this->Task->connection = 'test_suite';
+ $this->Task->Test =& new ControllerMockTestTask();
+
+ $this->Task->Test->expectOnce('bake', array('Controller', 'Articles'));
+ $this->Task->bakeTest('Articles');
+
+ $this->assertEqual($this->Task->plugin, $this->Task->Test->plugin);
+ $this->assertEqual($this->Task->connection, $this->Task->Test->connection);
+ }
+
+/**
* test Interactive mode.
*
* @return void
Please sign in to comment.
Something went wrong with that request. Please try again.