Skip to content

Commit

Permalink
Fixing how scaffold arg works, now generates scaffolds.
Browse files Browse the repository at this point in the history
Making admin arg only make admin methods and new both arg make both admin and non admin methods.
Adding test cases.
Adding new line to template.
  • Loading branch information
markstory committed Jul 29, 2009
1 parent 8ae8a08 commit 9092b25
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 25 deletions.
39 changes: 20 additions & 19 deletions cake/console/libs/tasks/controller.php
Expand Up @@ -81,19 +81,20 @@ function execute() {
$controller = Inflector::camelize($this->args[0]);
$actions = null;
if (isset($this->args[1]) && $this->args[1] == 'scaffold') {
$this->out(__('Baking scaffold for ', true) . $controller);
$actions = $this->bakeActions($controller);
} else {
$actions = 'scaffold';
} else {
$this->out(__('Baking basic crud methods for ', true) . $controller);
$actions = $this->bakeActions($controller);
}
if ((isset($this->args[1]) && $this->args[1] == 'admin') || (isset($this->args[2]) && $this->args[2] == 'admin')) {
if ($admin = $this->Project->getAdmin()) {
if (isset($this->args[1]) && ($this->args[1] == 'admin' || $this->args[1] == 'both')) {
$admin = $this->Project->getAdmin();
if ($admin) {
$this->out('Adding ' . Configure::read('Routing.admin') .' methods');
if ($actions == 'scaffold') {
$actions = $this->bakeActions($controller, $admin);
} else {
$actions .= $this->bakeActions($controller, $admin);
}
$adminActions = $this->bakeActions($controller, $admin);
}
$actions .= "\n" . $adminActions;
if ($this->args[1] == 'admin') {
$actions = $adminActions;
}
}
if ($this->bake($controller, $actions)) {
Expand Down Expand Up @@ -454,19 +455,19 @@ function help() {
$this->out('Commands:');
$this->out('');
$this->out("controller <name>");
$this->out("\tbakes controller with var \$scaffold");
$this->out('');
$this->out("controller <name> scaffold");
$this->out("\tbakes controller with scaffold actions.");
$this->out("\tbakes controller with basic crud actions");
$this->out("\t(index, view, add, edit, delete)");
$this->out('');
$this->out("controller <name> scaffold admin");
$this->out("\tbakes a controller with scaffold actions for both public");
$this->out("\tand Configure::read('Routing.admin')");
$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 scaffold actions only for");
$this->out("\tConfigure::read('Routing.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("\tbakes a controller with basic crud actions for");
$this->out("\tConfigure::read('Routing.admin') and non admin methods.");
$this->out('');
$this->out("controller all");
$this->out("\tbakes all controllers with CRUD methods.");
Expand Down
1 change: 1 addition & 0 deletions cake/console/templates/default/classes/controller.ctp
Expand Up @@ -53,5 +53,6 @@ endif;
echo $actions;

endif; ?>

}
<?php echo "?>"; ?>
59 changes: 53 additions & 6 deletions cake/tests/cases/console/libs/tasks/controller.test.php
Expand Up @@ -445,30 +445,77 @@ function testExecuteWithScaffoldParam() {

$filename = '/my/path/articles_controller.php';
$this->Task->expectAt(0, 'createFile', array(
$filename, new NoPatternExpectation('/admin_index/')
$filename, new PatternExpectation('/var \$scaffold/')
));

$this->Task->execute();
}

/**
* test that `cake bake controller foo scaffold admin` works
* test that `cake bake controller foos` works.
*
* @return void
**/
function testExecuteWithAdminScaffoldParams() {
function testExecuteWithController() {
$skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'),
'Execute with scaffold admin param requires no Article, Tag or Comment model to be defined. %s');
'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');

$filename = '/my/path/articles_controller.php';
$this->Task->expectAt(0, 'createFile', array(
$filename, new NoPatternExpectation('/admin/')
));

$this->Task->execute();
}

/**
* test that `cake bake controller foos both` works.
*
* @return void
**/
function testExecuteWithControllerAndBoth() {
$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->Project->setReturnValue('getAdmin', 'admin_');
$this->Task->connection = 'test_suite';
$this->Task->path = '/my/path/';
$this->Task->args = array('Articles', 'both');

$filename = '/my/path/articles_controller.php';
$this->Task->expectAt(0, 'createFile', array(
$filename, new PatternExpectation('/admin_index/')
));

$this->Task->execute();
}

/**
* test that `cake bake controller foos admin` works.
*
* @return void
**/
function testExecuteWithControllerAndAdmin() {
$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->Project->setReturnValue('getAdmin', 'admin_');
$this->Task->connection = 'test_suite';
$this->Task->path = '/my/path/';
$this->Task->args = array('Articles', 'scaffold', 'admin');
$this->Task->args = array('Articles', 'admin');

$filename = '/my/path/articles_controller.php';
$this->Task->expect('createFile', array(
$this->Task->expectAt(0, 'createFile', array(
$filename, new PatternExpectation('/admin_index/')
));

Expand Down

0 comments on commit 9092b25

Please sign in to comment.