diff --git a/cake/console/libs/tasks/controller.php b/cake/console/libs/tasks/controller.php index 3248351c2..9ea0a81a4 100644 --- a/cake/console/libs/tasks/controller.php +++ b/cake/console/libs/tasks/controller.php @@ -536,16 +536,16 @@ class ControllerTask extends Shell { /** * 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)); @@ -553,8 +553,7 @@ class ControllerTask extends Shell { } 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 @@ class ControllerTask extends Shell { } else { $controllerName = Inflector::camelize($enteredController); } - return $controllerName; } /** diff --git a/cake/tests/cases/console/libs/tasks/controller.test.php b/cake/tests/cases/console/libs/tasks/controller.test.php index dccddc275..47fda0d66 100644 --- a/cake/tests/cases/console/libs/tasks/controller.test.php +++ b/cake/tests/cases/console/libs/tasks/controller.test.php @@ -119,5 +119,32 @@ class ControllerTaskTest extends CakeTestCase { $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'); + } } ?> \ No newline at end of file