mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Adding test case for getName
This commit is contained in:
parent
9b9b1fbf21
commit
68a858b39a
2 changed files with 31 additions and 6 deletions
|
@ -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.
|
* 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
|
* @return string Controller name
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
function getName() {
|
function getName($useDbConfig = null) {
|
||||||
$useDbConfig = 'default';
|
|
||||||
$controllers = $this->listAll($useDbConfig);
|
$controllers = $this->listAll($useDbConfig);
|
||||||
$enteredController = '';
|
$enteredController = '';
|
||||||
|
|
||||||
while ($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') {
|
if ($enteredController === 'q') {
|
||||||
$this->out(__("Exit", true));
|
$this->out(__("Exit", true));
|
||||||
|
@ -553,8 +553,7 @@ class ControllerTask extends Shell {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($enteredController == '' || intval($enteredController) > count($controllers)) {
|
if ($enteredController == '' || intval($enteredController) > count($controllers)) {
|
||||||
$this->out(__('Error:', true));
|
$this->err(__("The Controller name you supplied was empty,\nor the number you selected was not an option. Please try again.", true));
|
||||||
$this->out(__("The Controller name you supplied was empty, or the number \nyou selected was not an option. Please try again.", true));
|
|
||||||
$enteredController = '';
|
$enteredController = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -564,7 +563,6 @@ class ControllerTask extends Shell {
|
||||||
} else {
|
} else {
|
||||||
$controllerName = Inflector::camelize($enteredController);
|
$controllerName = Inflector::camelize($enteredController);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $controllerName;
|
return $controllerName;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -119,5 +119,32 @@ class ControllerTaskTest extends CakeTestCase {
|
||||||
$expected = array('articles', 'articles_tags', 'comments', 'tags');
|
$expected = array('articles', 'articles_tags', 'comments', 'tags');
|
||||||
$this->assertEqual($result, $expected);
|
$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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
Loading…
Reference in a new issue