Skip to content

Commit 77e0bfa

Browse files
committed
Move error to case switch.
Move the error closer to the happy paths, and remove a test that is redundant. Refs #9189
1 parent 5902079 commit 77e0bfa

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

src/View/Helper/FormHelper.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,10 +1024,6 @@ public function input($fieldName, array $options = [])
10241024
$options = $this->_parseOptions($fieldName, $options);
10251025
$options += ['id' => $this->_domId($fieldName)];
10261026

1027-
if (strtolower($options['type']) === 'input') {
1028-
throw new RuntimeException(sprintf('Invalid type "input" used for field "%s"', $fieldName));
1029-
}
1030-
10311027
$templater = $this->templater();
10321028
$newTemplates = $options['templates'];
10331029

@@ -1140,7 +1136,7 @@ protected function _inputContainerTemplate($options)
11401136
*/
11411137
protected function _getInput($fieldName, $options)
11421138
{
1143-
switch ($options['type']) {
1139+
switch (strtolower($options['type'])) {
11441140
case 'select':
11451141
$opts = $options['options'];
11461142
unset($options['options']);
@@ -1156,6 +1152,9 @@ protected function _getInput($fieldName, $options)
11561152
unset($options['options']);
11571153

11581154
return $this->multiCheckbox($fieldName, $opts, $options);
1155+
case 'input':
1156+
throw new RuntimeException("Invalid type 'input' used for field '$fieldName'");
1157+
11591158
default:
11601159
return $this->{$options['type']}($fieldName, $options);
11611160
}

tests/TestCase/View/Helper/FormHelperTest.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3683,24 +3683,14 @@ public function testInputMagicSelectForTypeNumber()
36833683
* Test invalid 'input' type option to input() function.
36843684
*
36853685
* @expectedException \RuntimeException
3686+
* @expectedExceptionMessage Invalid type 'input' used for field 'text'
36863687
* @return void
36873688
*/
3688-
public function testInvalidInputTypeOptionLowercase()
3689+
public function testInvalidInputTypeOption()
36893690
{
36903691
$this->Form->input('text', ['type' => 'input']);
36913692
}
36923693

3693-
/**
3694-
* Test invalid 'Input' type option to input() function.
3695-
*
3696-
* @expectedException \RuntimeException
3697-
* @return void
3698-
*/
3699-
public function testInvalidInputTypeOptionUppercase()
3700-
{
3701-
$this->Form->input('text', ['type' => 'Input']);
3702-
}
3703-
37043694
/**
37053695
* Test that magic input() selects can easily be converted into radio types without error.
37063696
*

0 commit comments

Comments
 (0)