Skip to content
Permalink
Browse files

Adding tests and starting clean up of __interactive.

  • Loading branch information...
markstory committed May 15, 2009
1 parent d609a62 commit 9eb27f14d7e3b7ed33a051d3b7c72e317d03d88b
Showing with 90 additions and 34 deletions.
  1. +56 −34 cake/console/libs/tasks/controller.php
  2. +34 −0 cake/tests/cases/console/libs/tasks/controller.test.php
@@ -44,7 +44,7 @@ class ControllerTask extends Shell {
* @var array
* @access public
*/
var $tasks = array('Model', 'Project', 'Template');
var $tasks = array('Model', 'Project', 'Template', 'DbConfig');
/**
* path to CONTROLLERS directory
*
@@ -70,6 +70,9 @@ function execute() {
}
if (isset($this->args[0])) {
if (!isset($this->connection)) {
$this->connection = 'default';
}
if (strtolower($this->args[0]) == 'all') {
return $this->all();
}
@@ -121,33 +124,34 @@ function all() {
*
* @access private
*/
function __interactive($controllerName = false) {
if (!$controllerName) {
$this->interactive = true;
$this->hr();
$this->out(sprintf("Bake Controller\nPath: %s", $this->path));
$this->hr();
$actions = '';
$uses = array();
$helpers = array();
$components = array();
$wannaUseSession = 'y';
$wannaDoAdmin = 'n';
$wannaUseScaffold = 'n';
$wannaDoScaffolding = 'y';
$controllerName = $this->getName();
function __interactive() {
$this->interactive = true;
$this->hr();
$this->out(sprintf("Bake Controller\nPath: %s", $this->path));
$this->hr();
if (empty($this->connection)) {
$this->connection = $this->DbConfig->getConfig();
}
$controllerName = $this->getName();
$this->hr();
$this->out("Baking {$controllerName}Controller");
$this->hr();
$actions = '';
$wannaUseSession = 'y';
$wannaDoAdmin = 'n';
$wannaUseScaffold = 'n';
$wannaDoScaffolding = 'y';
$controllerFile = low(Inflector::underscore($controllerName));
$question[] = __("Would you like to build your controller interactively?", true);
if (file_exists($this->path . $controllerFile .'_controller.php')) {
$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') {
$this->interactive = true;
@@ -161,21 +165,8 @@ function __interactive($controllerName = false) {
if (strtolower($wannaDoScaffolding) == 'y') {
$wannaDoAdmin = $this->in(__("Would you like to create the methods for admin routing?", true), array('y','n'), 'n');
}
$wannaDoHelpers = $this->in(__("Would you like this controller to use other helpers besides HtmlHelper and FormHelper?", true), array('y','n'), 'n');
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);
}
$helpers = $this->doHelpers();
$components = $this->doComponents();
$wannaUseSession = $this->in(__("Would you like to use Sessions?", true), array('y','n'), 'y');
} else {
@@ -244,8 +235,6 @@ function __interactive($controllerName = false) {
if ($baked && $this->_checkUnitTest()) {
$this->bakeTest($controllerName);
}
} else {
$this->__interactive($controllerName);
}
} else {
$baked = $this->bake($controllerName, $actions, $helpers, $components, $uses);
@@ -506,6 +495,38 @@ function bakeTest($className) {
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
*
@@ -565,6 +586,7 @@ function getName($useDbConfig = null) {
}
return $controllerName;
}
/**
* Displays help contents
*
@@ -146,5 +146,39 @@ function testGetName() {
$result = $this->Task->getName('test_suite');
$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);
}
}
?>

0 comments on commit 9eb27f1

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