Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding test case for getName

  • Loading branch information...
commit 68a858b39a310afb1b73b7a48af19461056cdc15 1 parent 9b9b1fb
@markstory markstory authored
View
10 cake/console/libs/tasks/controller.php
@@ -536,16 +536,16 @@ 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));
@@ -553,8 +553,7 @@ function getName() {
}
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;
}
/**
View
27 cake/tests/cases/console/libs/tasks/controller.test.php
@@ -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');
+ }
}
?>
Please sign in to comment.
Something went wrong with that request. Please try again.