Skip to content

Commit

Permalink
Fix radio() being called incorrectly by input().
Browse files Browse the repository at this point in the history
Refs #3317
  • Loading branch information
markstory committed Apr 15, 2014
1 parent 31ddeb8 commit f7703db
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
7 changes: 6 additions & 1 deletion src/View/Helper/FormHelper.php
Expand Up @@ -873,6 +873,10 @@ protected function _getInput($fieldName, $options) {
$opts = (array)$options['options'];
unset($options['options']);
return $this->select($fieldName, $opts, $options);
case 'radio':
$opts = (array)$options['options'];
unset($options['options']);
return $this->radio($fieldName, $opts, $options);
case 'url':
$options = $this->_initInputField($fieldName, $options);
return $this->widget($options['type'], $options);
Expand Down Expand Up @@ -999,7 +1003,8 @@ protected function _magicOptions($fieldName, $options, $allowOverride) {
}

$typesWithOptions = ['text', 'number', 'radio', 'select'];
if ($allowOverride && in_array($options['type'], $typesWithOptions)) {
$magicOptions = (in_array($options['type'], ['radio', 'select']) || $allowOverride);
if ($magicOptions && in_array($options['type'], $typesWithOptions)) {
$options = $this->_optionsOptions($fieldName, $options);
}

Expand Down
19 changes: 12 additions & 7 deletions tests/TestCase/View/Helper/FormHelperTest.php
@@ -1,7 +1,5 @@
<?php
/**
* FormHelperTest file
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
Expand Down Expand Up @@ -2409,6 +2407,13 @@ public function testInputSelectType() {
);
$this->assertTags($result, $expected);

$result = $this->Form->input('email', [
'type' => 'select',
'options' => new \ArrayObject(['First', 'Second']),
'empty' => true
]);
$this->assertTags($result, $expected);

$this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
$this->Form->request->data = array('Model' => array('user_id' => 'value'));

Expand Down Expand Up @@ -2480,10 +2485,10 @@ public function testInputSelectType() {

$this->Form->data = array();
$result = $this->Form->input('Publisher.id', array(
'label' => 'Publisher',
'type' => 'select',
'multiple' => 'checkbox',
'options' => array('Value 1' => 'Label 1', 'Value 2' => 'Label 2')
'label' => 'Publisher',
'type' => 'select',
'multiple' => 'checkbox',
'options' => array('Value 1' => 'Label 1', 'Value 2' => 'Label 2')
));
$expected = array(
array('div' => array('class' => 'input select')),
Expand Down Expand Up @@ -2637,7 +2642,7 @@ public function testInputMagicSelectForTypeNumber() {
public function testInputMagicSelectChangeToRadio() {
$this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
$result = $this->Form->input('Model.user_id', array('type' => 'radio'));
$this->assertRegExp('/input type="radio"/', $result);
$this->assertContains('input type="radio"', $result);
}

/**
Expand Down

0 comments on commit f7703db

Please sign in to comment.