Skip to content
Permalink
Browse files

Adding test case for getName

  • Loading branch information...
markstory committed May 15, 2009
1 parent 9b9b1fb commit 68a858b39a310afb1b73b7a48af19461056cdc15
Showing with 31 additions and 6 deletions.
  1. +4 −6 cake/console/libs/tasks/controller.php
  2. +27 −0 cake/tests/cases/console/libs/tasks/controller.test.php
@@ -536,25 +536,24 @@ function listAll($useDbConfig = null) {
/**
* Forces the user to specify the controller he wants to bake, and returns the selected controller name.
*
* @param string $useDbConfig Connection name to get a controller name for.
* @return string Controller name
* @access public
*/
function getName() {
$useDbConfig = 'default';
function getName($useDbConfig = null) {
$controllers = $this->listAll($useDbConfig);
$enteredController = '';
while ($enteredController == '') {
$enteredController = $this->in(__("Enter a number from the list above, type in the name of another controller, or 'q' to exit", true), null, 'q');
$enteredController = $this->in(__("Enter a number from the list above,\ntype in the name of another controller, or 'q' to exit", true), null, 'q');
if ($enteredController === 'q') {
$this->out(__("Exit", true));
$this->_stop();
}
if ($enteredController == '' || intval($enteredController) > count($controllers)) {
$this->out(__('Error:', true));
$this->out(__("The Controller name you supplied was empty, or the number \nyou selected was not an option. Please try again.", true));
$this->err(__("The Controller name you supplied was empty,\nor the number you selected was not an option. Please try again.", true));
$enteredController = '';
}
}
@@ -564,7 +563,6 @@ function getName() {
} else {
$controllerName = Inflector::camelize($enteredController);
}
return $controllerName;
}
/**
@@ -119,5 +119,32 @@ function testListAll() {
$expected = array('articles', 'articles_tags', 'comments', 'tags');
$this->assertEqual($result, $expected);
}
/**
* Test that getName interacts with the user and returns the controller name.
*
* @return void
**/
function testGetName() {
$this->Task->setReturnValue('in', 1);
$this->Task->setReturnValueAt(0, 'in', 'q');
$this->Task->expectOnce('_stop');
$this->Task->getName('test_suite');
$this->Task->setReturnValueAt(1, 'in', 1);
$result = $this->Task->getName('test_suite');
$expected = 'Articles';
$this->assertEqual($result, $expected);
$this->Task->setReturnValueAt(2, 'in', 3);
$result = $this->Task->getName('test_suite');
$expected = 'Comments';
$this->assertEqual($result, $expected);
$this->Task->setReturnValueAt(3, 'in', 10);
$result = $this->Task->getName('test_suite');
$this->Task->expectOnce('err');
}
}
?>

0 comments on commit 68a858b

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