mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-10 05:22:41 +00:00
Creating confirmController and test case.
This commit is contained in:
parent
938ba849d2
commit
08394629c9
2 changed files with 64 additions and 37 deletions
|
@ -167,7 +167,9 @@ class ControllerTask extends Shell {
|
|||
$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 @@ class ControllerTask extends Shell {
|
|||
}
|
||||
|
||||
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 @@ class ControllerTask extends Shell {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(
|
|||
|
||||
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 @@ class ControllerTaskTest extends CakeTestCase {
|
|||
$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);
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue