Skip to content
Permalink
Browse files

Creating confirmController and test case.

  • Loading branch information...
markstory committed May 17, 2009
1 parent 938ba84 commit 08394629c9f474dd154f7d50551693df88cbf97c
Showing with 64 additions and 37 deletions.
  1. +44 −36 cake/console/libs/tasks/controller.php
  2. +20 −1 cake/tests/cases/console/libs/tasks/controller.test.php
@@ -167,7 +167,9 @@ function __interactive() {
$components = $this->doComponents();
$uses = $this->doUses();
$wannaUseSession = $this->in(__("Would you like to use Sessions?", true), array('y','n'), 'y');
$wannaUseSession = $this->in(
__("Would you like to use Session flash messages?", true), array('y','n'), 'y'
);
} else {
$wannaBakeCrud = 'n';
}
@@ -184,41 +186,7 @@ function __interactive() {
}
if ($this->interactive === true) {
$this->out('');
$this->hr();
$this->out('The following controller will be created:');
$this->hr();
$this->out("Controller Name:\t$controllerName");
if (strtolower($useDynamicScaffold) == 'y') {
$this->out("\t\tvar \$scaffold;");
$actions = 'scaffold';
}
if (count($helpers)) {
$this->out("Helpers:", false);
foreach ($helpers as $help) {
if ($help != $helpers[count($helpers) - 1]) {
$this->out(ucfirst($help) . ", ", false);
} else {
$this->out(ucfirst($help));
}
}
}
if (count($components)) {
$this->out("Components:", false);
foreach ($components as $comp) {
if ($comp != $components[count($components) - 1]) {
$this->out(ucfirst($comp) . ", ", false);
} else {
$this->out(ucfirst($comp));
}
}
}
$this->hr();
$this->confirmController($controllerName, $useDynamicScaffold, $uses, $helpers, $components);
$looksGood = $this->in(__('Look okay?', true), array('y','n'), 'y');
if (strtolower($looksGood) == 'y') {
@@ -235,6 +203,46 @@ function __interactive() {
}
}
/**
* Confirm a to be baked controller with the user
*
* @return void
**/
function confirmController($controllerName, $useDynamicScaffold, $uses, $helpers, $components) {
$this->out('');
$this->hr();
$this->out('The following controller will be created:');
$this->hr();
$this->out("Controller Name:\n\t$controllerName");
if (strtolower($useDynamicScaffold) == 'y') {
$this->out("\t\tvar \$scaffold;");
$actions = 'scaffold';
}
$properties = array(
'helpers' => __("Helpers:", true),
'components' => __('Components:', true),
'uses' => __('Uses:', true)
);
foreach ($properties as $var => $title) {
if (count($$var)) {
$output = '';
$length = count($$var);
foreach ($$var as $i => $propElement) {
if ($i != $length -1) {
$output .= ucfirst($propElement) . ', ';
} else {
$output .= ucfirst($propElement);
}
}
$this->out($title . "\n\t" . $output);
}
}
$this->hr();
}
/**
* Interact with the user and ask about which methods (admin or regular they want to bake)
*
@@ -43,7 +43,7 @@
Mock::generatePartial(
'ControllerTask', 'MockControllerTask',
array('in', 'out', 'err', 'createFile', '_stop', '_checkUnitTest')
array('in', 'hr', 'out', 'err', 'createFile', '_stop', '_checkUnitTest')
);
Mock::generatePartial(
@@ -180,5 +180,24 @@ function testDoComponents() {
$expected = array('RequestHandler', 'Security');
$this->assertEqual($result, $expected);
}
/**
* test Confirming controller user interaction
*
* @return void
**/
function testConfirmController() {
$controller = 'Posts';
$scaffold = false;
$helpers = array('Ajax', 'Time');
$components = array('Acl', 'Auth');
$uses = array('Comment', 'User');
$this->Task->expectAt(2, 'out', array("Controller Name:\n\t$controller"));
$this->Task->expectAt(3, 'out', array("Helpers:\n\tAjax, Time"));
$this->Task->expectAt(4, 'out', array("Components:\n\tAcl, Auth"));
$this->Task->expectAt(5, 'out', array("Uses:\n\tComment, User"));
$this->Task->confirmController($controller, $scaffold, $uses, $helpers, $components);
}
}
?>

0 comments on commit 0839462

Please sign in to comment.
You can’t perform that action at this time.