mirror of
				https://github.com/yiisoft/yii2.git
				synced 2025-11-04 06:37:55 +08:00 
			
		
		
		
	Fix #16145: Fix Html helper checkboxList(), radioList(), renderSelectOptions(), dropDownList(), listBox() methods to work properly with traversable selection
				
					
				
			This commit is contained in:
		@ -4,6 +4,7 @@ Yii Framework 2 Change Log
 | 
			
		||||
2.0.33 under development
 | 
			
		||||
------------------------
 | 
			
		||||
 | 
			
		||||
- Bug #16145: Fix `Html` helper `checkboxList()`, `radioList()`, `renderSelectOptions()`, `dropDownList()`, `listBox()` methods to work properly with traversable selection (samdark)
 | 
			
		||||
- Bug #17797: Fix for `activeListInput` options (alex-code)
 | 
			
		||||
- Bug #16092: Fix duplicate joins in usage of `joinWith` (germanow)
 | 
			
		||||
- Bug #17679: Fix Oracle exception "ORA-01461: can bind a LONG value only for insert into a LONG column" when inserting 4k+ string (vinpel, 243083df)
 | 
			
		||||
 | 
			
		||||
@ -954,7 +954,7 @@ class BaseHtml
 | 
			
		||||
            $name .= '[]';
 | 
			
		||||
        }
 | 
			
		||||
        if (ArrayHelper::isTraversable($selection)) {
 | 
			
		||||
            $selection = array_map('strval', (array)$selection);
 | 
			
		||||
            $selection = array_map('strval', ArrayHelper::toArray($selection));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $formatter = ArrayHelper::remove($options, 'item');
 | 
			
		||||
@ -1041,7 +1041,7 @@ class BaseHtml
 | 
			
		||||
    public static function radioList($name, $selection = null, $items = [], $options = [])
 | 
			
		||||
    {
 | 
			
		||||
        if (ArrayHelper::isTraversable($selection)) {
 | 
			
		||||
            $selection = array_map('strval', (array)$selection);
 | 
			
		||||
            $selection = array_map('strval', ArrayHelper::toArray($selection));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $formatter = ArrayHelper::remove($options, 'item');
 | 
			
		||||
@ -1854,7 +1854,7 @@ class BaseHtml
 | 
			
		||||
    public static function renderSelectOptions($selection, $items, &$tagOptions = [])
 | 
			
		||||
    {
 | 
			
		||||
        if (ArrayHelper::isTraversable($selection)) {
 | 
			
		||||
            $selection = array_map('strval', (array)$selection);
 | 
			
		||||
            $selection = array_map('strval', ArrayHelper::toArray($selection));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $lines = [];
 | 
			
		||||
 | 
			
		||||
@ -9,6 +9,7 @@ namespace yiiunit\framework\helpers;
 | 
			
		||||
 | 
			
		||||
use Yii;
 | 
			
		||||
use yii\base\DynamicModel;
 | 
			
		||||
use yii\db\ArrayExpression;
 | 
			
		||||
use yii\helpers\Html;
 | 
			
		||||
use yii\helpers\Url;
 | 
			
		||||
use yiiunit\TestCase;
 | 
			
		||||
@ -769,6 +770,56 @@ EOD;
 | 
			
		||||
        ]));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testRadioListWithArrayExpression()
 | 
			
		||||
    {
 | 
			
		||||
        $selection = new ArrayExpression(['first']);
 | 
			
		||||
 | 
			
		||||
        $output = Html::radioList(
 | 
			
		||||
            'test',
 | 
			
		||||
            $selection,
 | 
			
		||||
            [
 | 
			
		||||
                'first' => 'first',
 | 
			
		||||
                'second' => 'second'
 | 
			
		||||
            ]
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        $this->assertEqualsWithoutLE('<div><label><input type="radio" name="test" value="first" checked> first</label>
 | 
			
		||||
<label><input type="radio" name="test" value="second"> second</label></div>', $output);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testCheckboxListWithArrayExpression()
 | 
			
		||||
    {
 | 
			
		||||
        $selection = new ArrayExpression(['first']);
 | 
			
		||||
 | 
			
		||||
        $output = Html::checkboxList(
 | 
			
		||||
            'test',
 | 
			
		||||
            $selection,
 | 
			
		||||
            [
 | 
			
		||||
                'first' => 'first',
 | 
			
		||||
                'second' => 'second'
 | 
			
		||||
            ]
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        $this->assertEqualsWithoutLE('<div><label><input type="checkbox" name="test[]" value="first" checked> first</label>
 | 
			
		||||
<label><input type="checkbox" name="test[]" value="second"> second</label></div>', $output);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testRenderSelectOptionsWithArrayExpression()
 | 
			
		||||
    {
 | 
			
		||||
        $selection = new ArrayExpression(['first']);
 | 
			
		||||
 | 
			
		||||
        $output = Html::renderSelectOptions(
 | 
			
		||||
            $selection,
 | 
			
		||||
            [
 | 
			
		||||
                'first' => 'first',
 | 
			
		||||
                'second' => 'second'
 | 
			
		||||
            ]
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        $this->assertEqualsWithoutLE('<option value="first" selected>first</option>
 | 
			
		||||
<option value="second">second</option>', $output);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testRadioList()
 | 
			
		||||
    {
 | 
			
		||||
        $this->assertEquals('<div></div>', Html::radioList('test'));
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user