Permalink
Browse files

Correcting parameter names for ControllerTask. Updating tests in Cont…

…roller and ViewTask.
  • Loading branch information...
1 parent a87b6cd commit 189480e49951197310312de81c37ce61ca9fd858 @markstory markstory committed Jul 29, 2009
@@ -78,25 +78,33 @@ function execute() {
if (strtolower($this->args[0]) == 'all') {
return $this->all();
}
+
$controller = Inflector::camelize($this->args[0]);
$actions = null;
- if (isset($this->args[1]) && $this->args[1] == 'scaffold') {
+ if (!isset($this->args[1])) {
$actions = 'scaffold';
- } else {
+ }
+
+
+ if (!empty($this->args[1]) && ($this->args[1] == 'public' || $this->args[1] == 'scaffold')) {
$this->out(__('Baking basic crud methods for ', true) . $controller);
$actions = $this->bakeActions($controller);
- }
- if (isset($this->args[1]) && ($this->args[1] == 'admin' || $this->args[1] == 'both')) {
+ } elseif (!empty($this->args[1]) && $this->args[1] == 'admin') {
$admin = $this->Project->getAdmin();
if ($admin) {
$this->out('Adding ' . Configure::read('Routing.admin') .' methods');
- $adminActions = $this->bakeActions($controller, $admin);
+ $actions= $this->bakeActions($controller, $admin);
}
- $actions .= "\n" . $adminActions;
- if ($this->args[1] == 'admin') {
- $actions = $adminActions;
+ }
+
+ if (!empty($this->args[2]) && $this->args[2] == 'admin') {
+ $admin = $this->Project->getAdmin();
+ if ($admin) {
+ $this->out('Adding ' . Configure::read('Routing.admin') .' methods');
+ $actions .= "\n" . $this->bakeActions($controller, $admin);
}
}
+
if ($this->bake($controller, $actions)) {
if ($this->_checkUnitTest()) {
$this->bakeTest($controller);
@@ -455,19 +463,21 @@ function help() {
$this->out('Commands:');
$this->out('');
$this->out("controller <name>");
+ $this->out("\tbakes controller with var \$scaffold");
+ $this->out('');
+ $this->out("controller <name> public");
$this->out("\tbakes controller with basic crud actions");
$this->out("\t(index, view, add, edit, delete)");
$this->out('');
- $this->out("controller <name> scaffold");
- $this->out("\tbakes controller with var \$scaffold.");
- $this->out('');
$this->out("controller <name> admin");
$this->out("\tbakes a controller with basic crud actions for");
$this->out("\tConfigure::read('Routing.admin') methods.");
$this->out('');
- $this->out("controller <name> both");
+ $this->out("controller <name> public admin");
$this->out("\tbakes a controller with basic crud actions for");
$this->out("\tConfigure::read('Routing.admin') and non admin methods.");
+ $this->out("\t(index, view, add, edit, delete,");
+ $this->out("\tadmin_index, admin_view, admin_edit, admin_add, admin_delete)");
$this->out('');
$this->out("controller all");
$this->out("\tbakes all controllers with CRUD methods.");
@@ -429,46 +429,46 @@ function testExecuteIntoAll() {
}
/**
- * test that `cake bake controller foo scaffold` works.
+ * test that `cake bake controller foos` works.
*
* @return void
**/
- function testExecuteWithScaffoldParam() {
+ function testExecuteWithController() {
$skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'),
'Execute with scaffold param requires no Article, Tag or Comment model to be defined. %s');
if ($skip) {
return;
}
$this->Task->connection = 'test_suite';
$this->Task->path = '/my/path/';
- $this->Task->args = array('Articles', 'scaffold');
+ $this->Task->args = array('Articles');
$filename = '/my/path/articles_controller.php';
$this->Task->expectAt(0, 'createFile', array(
- $filename, new PatternExpectation('/var \$scaffold/')
+ $filename, new PatternExpectation('/\$scaffold/')
));
$this->Task->execute();
}
/**
- * test that `cake bake controller foos` works.
+ * test that `cake bake controller foo scaffold` works.
*
* @return void
**/
- function testExecuteWithController() {
+ function testExecuteWithPublicParam() {
$skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'),
'Execute with scaffold param requires no Article, Tag or Comment model to be defined. %s');
if ($skip) {
return;
}
$this->Task->connection = 'test_suite';
$this->Task->path = '/my/path/';
- $this->Task->args = array('Articles');
+ $this->Task->args = array('Articles', 'public');
$filename = '/my/path/articles_controller.php';
$this->Task->expectAt(0, 'createFile', array(
- $filename, new NoPatternExpectation('/admin/')
+ $filename, new NoPatternExpectation('/var \$scaffold/')
));
$this->Task->execute();
@@ -488,7 +488,7 @@ function testExecuteWithControllerAndBoth() {
$this->Task->Project->setReturnValue('getAdmin', 'admin_');
$this->Task->connection = 'test_suite';
$this->Task->path = '/my/path/';
- $this->Task->args = array('Articles', 'both');
+ $this->Task->args = array('Articles', 'public', 'admin');
$filename = '/my/path/articles_controller.php';
$this->Task->expectAt(0, 'createFile', array(
@@ -302,11 +302,9 @@ function testExecuteIntoAll() {
$this->Task->Controller->setReturnValue('listAll', array('view_task_comments'));
$this->Task->Controller->expectOnce('listAll');
- $this->Task->expectCallCount('createFile', 4);
+ $this->Task->expectCallCount('createFile', 2);
$this->Task->expectAt(0, 'createFile', array(TMP . 'view_task_comments' . DS . 'index.ctp', '*'));
- $this->Task->expectAt(1, 'createFile', array(TMP . 'view_task_comments' . DS . 'view.ctp', '*'));
- $this->Task->expectAt(2, 'createFile', array(TMP . 'view_task_comments' . DS . 'add.ctp', '*'));
- $this->Task->expectAt(3, 'createFile', array(TMP . 'view_task_comments' . DS . 'edit.ctp', '*'));
+ $this->Task->expectAt(1, 'createFile', array(TMP . 'view_task_comments' . DS . 'add.ctp', '*'));
$this->Task->execute();
}

0 comments on commit 189480e

Please sign in to comment.