Adding tests and starting clean up of __interactive.

This commit is contained in:
mark_story 2009-05-15 00:04:57 -04:00
parent d609a62dc5
commit 9eb27f14d7
2 changed files with 90 additions and 34 deletions

View file

@ -44,7 +44,7 @@ class ControllerTask extends Shell {
* @var array * @var array
* @access public * @access public
*/ */
var $tasks = array('Model', 'Project', 'Template'); var $tasks = array('Model', 'Project', 'Template', 'DbConfig');
/** /**
* path to CONTROLLERS directory * path to CONTROLLERS directory
* *
@ -70,6 +70,9 @@ class ControllerTask extends Shell {
} }
if (isset($this->args[0])) { if (isset($this->args[0])) {
if (!isset($this->connection)) {
$this->connection = 'default';
}
if (strtolower($this->args[0]) == 'all') { if (strtolower($this->args[0]) == 'all') {
return $this->all(); return $this->all();
} }
@ -121,33 +124,34 @@ class ControllerTask extends Shell {
* *
* @access private * @access private
*/ */
function __interactive($controllerName = false) { function __interactive() {
if (!$controllerName) { $this->interactive = true;
$this->interactive = true; $this->hr();
$this->hr(); $this->out(sprintf("Bake Controller\nPath: %s", $this->path));
$this->out(sprintf("Bake Controller\nPath: %s", $this->path)); $this->hr();
$this->hr();
$actions = ''; if (empty($this->connection)) {
$uses = array(); $this->connection = $this->DbConfig->getConfig();
$helpers = array();
$components = array();
$wannaUseSession = 'y';
$wannaDoAdmin = 'n';
$wannaUseScaffold = 'n';
$wannaDoScaffolding = 'y';
$controllerName = $this->getName();
} }
$controllerName = $this->getName();
$this->hr(); $this->hr();
$this->out("Baking {$controllerName}Controller"); $this->out("Baking {$controllerName}Controller");
$this->hr(); $this->hr();
$actions = '';
$wannaUseSession = 'y';
$wannaDoAdmin = 'n';
$wannaUseScaffold = 'n';
$wannaDoScaffolding = 'y';
$controllerFile = low(Inflector::underscore($controllerName)); $controllerFile = low(Inflector::underscore($controllerName));
$question[] = __("Would you like to build your controller interactively?", true); $question[] = __("Would you like to build your controller interactively?", true);
if (file_exists($this->path . $controllerFile .'_controller.php')) { if (file_exists($this->path . $controllerFile .'_controller.php')) {
$question[] = sprintf(__("Warning: Choosing no will overwrite the %sController.", true), $controllerName); $question[] = sprintf(__("Warning: Choosing no will overwrite the %sController.", true), $controllerName);
} }
$doItInteractive = $this->in(join("\n", $question), array('y','n'), 'y'); $doItInteractive = $this->in(join("\n", $question), array('y', 'n'), 'y');
if (strtolower($doItInteractive) == 'y') { if (strtolower($doItInteractive) == 'y') {
$this->interactive = true; $this->interactive = true;
@ -161,21 +165,8 @@ class ControllerTask extends Shell {
if (strtolower($wannaDoScaffolding) == 'y') { if (strtolower($wannaDoScaffolding) == 'y') {
$wannaDoAdmin = $this->in(__("Would you like to create the methods for admin routing?", true), array('y','n'), 'n'); $wannaDoAdmin = $this->in(__("Would you like to create the methods for admin routing?", true), array('y','n'), 'n');
} }
$helpers = $this->doHelpers();
$wannaDoHelpers = $this->in(__("Would you like this controller to use other helpers besides HtmlHelper and FormHelper?", true), array('y','n'), 'n'); $components = $this->doComponents();
if (strtolower($wannaDoHelpers) == 'y') {
$helpersList = $this->in(__("Please provide a comma separated list of the other helper names you'd like to use.\nExample: 'Ajax, Javascript, Time'", true));
$helpersListTrimmed = str_replace(' ', '', $helpersList);
$helpers = explode(',', $helpersListTrimmed);
}
$wannaDoComponents = $this->in(__("Would you like this controller to use any components?", true), array('y','n'), 'n');
if (strtolower($wannaDoComponents) == 'y') {
$componentsList = $this->in(__("Please provide a comma separated list of the component names you'd like to use.\nExample: 'Acl, Security, RequestHandler'", true));
$componentsListTrimmed = str_replace(' ', '', $componentsList);
$components = explode(',', $componentsListTrimmed);
}
$wannaUseSession = $this->in(__("Would you like to use Sessions?", true), array('y','n'), 'y'); $wannaUseSession = $this->in(__("Would you like to use Sessions?", true), array('y','n'), 'y');
} else { } else {
@ -244,8 +235,6 @@ class ControllerTask extends Shell {
if ($baked && $this->_checkUnitTest()) { if ($baked && $this->_checkUnitTest()) {
$this->bakeTest($controllerName); $this->bakeTest($controllerName);
} }
} else {
$this->__interactive($controllerName);
} }
} else { } else {
$baked = $this->bake($controllerName, $actions, $helpers, $components, $uses); $baked = $this->bake($controllerName, $actions, $helpers, $components, $uses);
@ -506,6 +495,38 @@ class ControllerTask extends Shell {
return $this->createFile($path . $filename, $content); return $this->createFile($path . $filename, $content);
} }
/**
* Interact with the user and get a list of additional helpers
*
* @return array Helpers that the user wants to use.
**/
function doHelpers() {
$wannaDoHelpers = $this->in(__("Would you like this controller to use other helpers\nbesides HtmlHelper and FormHelper?", true), array('y','n'), 'n');
$helpers = array();
if (strtolower($wannaDoHelpers) == 'y') {
$helpersList = $this->in(__("Please provide a comma separated list of the other\nhelper names you'd like to use.\nExample: 'Ajax, Javascript, Time'", true));
$helpersListTrimmed = str_replace(' ', '', $helpersList);
$helpers = explode(',', $helpersListTrimmed);
}
return $helpers;
}
/**
* Interact with the user and get a list of additional components
*
* @return array Components the user wants to use.
**/
function doComponents() {
$wannaDoComponents = $this->in(__("Would you like this controller to use any components?", true), array('y','n'), 'n');
$components = array();
if (strtolower($wannaDoComponents) == 'y') {
$componentsList = $this->in(__("Please provide a comma separated list of the component names you'd like to use.\nExample: 'Acl, Security, RequestHandler'", true));
$componentsListTrimmed = str_replace(' ', '', $componentsList);
$components = explode(',', $componentsListTrimmed);
}
return $components;
}
/** /**
* Outputs and gets the list of possible controllers from database * Outputs and gets the list of possible controllers from database
* *
@ -565,6 +586,7 @@ class ControllerTask extends Shell {
} }
return $controllerName; return $controllerName;
} }
/** /**
* Displays help contents * Displays help contents
* *

View file

@ -146,5 +146,39 @@ class ControllerTaskTest extends CakeTestCase {
$result = $this->Task->getName('test_suite'); $result = $this->Task->getName('test_suite');
$this->Task->expectOnce('err'); $this->Task->expectOnce('err');
} }
/**
* test helper interactions
*
* @return void
**/
function testDoHelpers() {
$this->Task->setReturnValueAt(0, 'in', 'n');
$result = $this->Task->doHelpers();
$this->assertEqual($result, array());
$this->Task->setReturnValueAt(1, 'in', 'y');
$this->Task->setReturnValueAt(2, 'in', ' Javascript, Ajax, CustomOne ');
$result = $this->Task->doHelpers();
$expected = array('Javascript', 'Ajax', 'CustomOne');
$this->assertEqual($result, $expected);
}
/**
* test component interactions
*
* @return void
**/
function testDoComponents() {
$this->Task->setReturnValueAt(0, 'in', 'n');
$result = $this->Task->doComponents();
$this->assertEqual($result, array());
$this->Task->setReturnValueAt(1, 'in', 'y');
$this->Task->setReturnValueAt(2, 'in', ' RequestHandler, Security ');
$result = $this->Task->doComponents();
$expected = array('RequestHandler', 'Security');
$this->assertEqual($result, $expected);
}
} }
?> ?>