|
|
|
@ -81,4 +81,76 @@ class HtmlTest extends TestCase
|
|
|
|
|
{ |
|
|
|
|
$this->assertEquals($expectedHtml, Html::staticControl($value, $options)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testRadioList() |
|
|
|
|
{ |
|
|
|
|
$this->assertEquals('<div></div>', Html::radioList('test')); |
|
|
|
|
|
|
|
|
|
$dataItems = [ |
|
|
|
|
'value1' => 'text1', |
|
|
|
|
'value2' => 'text2', |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
$expected = <<<'EOD' |
|
|
|
|
<div><div class="radio"><label><input type="radio" name="test" value="value1"> text1</label></div> |
|
|
|
|
<div class="radio"><label><input type="radio" name="test" value="value2" checked> text2</label></div></div> |
|
|
|
|
EOD; |
|
|
|
|
$this->assertEqualsWithoutLE($expected, Html::radioList('test', ['value2'], $dataItems)); |
|
|
|
|
|
|
|
|
|
$expected = <<<'EOD' |
|
|
|
|
<div>0<label>text1 <input type="radio" name="test" value="value1"></label> |
|
|
|
|
1<label>text2 <input type="radio" name="test" value="value2" checked></label></div> |
|
|
|
|
EOD; |
|
|
|
|
$this->assertEqualsWithoutLE($expected, Html::radioList('test', ['value2'], $dataItems, [ |
|
|
|
|
'item' => function ($index, $label, $name, $checked, $value) { |
|
|
|
|
return $index . Html::label($label . ' ' . Html::radio($name, $checked, ['value' => $value])); |
|
|
|
|
}, |
|
|
|
|
])); |
|
|
|
|
|
|
|
|
|
$expected = <<<'EOD' |
|
|
|
|
<div><div class="radio"><label><input type="radio" name="test" value="value"> label&</label></div></div> |
|
|
|
|
EOD; |
|
|
|
|
$this->assertEqualsWithoutLE($expected, Html::radioList('test', [], ['value' => 'label&'])); |
|
|
|
|
|
|
|
|
|
$expected = <<<'EOD' |
|
|
|
|
<div><div class="radio"><label><input type="radio" name="test" value="value"> label&</label></div></div> |
|
|
|
|
EOD; |
|
|
|
|
$this->assertEqualsWithoutLE($expected, Html::radioList('test', [], ['value' => 'label&'], ['encode' => false])); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testCheckboxList() |
|
|
|
|
{ |
|
|
|
|
$this->assertEquals('<div></div>', Html::checkboxList('test')); |
|
|
|
|
|
|
|
|
|
$dataItems = [ |
|
|
|
|
'value1' => 'text1', |
|
|
|
|
'value2' => 'text2', |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
$expected = <<<'EOD' |
|
|
|
|
<div><div class="checkbox"><label><input type="checkbox" name="test[]" value="value1"> text1</label></div> |
|
|
|
|
<div class="checkbox"><label><input type="checkbox" name="test[]" value="value2" checked> text2</label></div></div> |
|
|
|
|
EOD; |
|
|
|
|
$this->assertEqualsWithoutLE($expected, Html::checkboxList('test', ['value2'], $dataItems)); |
|
|
|
|
|
|
|
|
|
$expected = <<<'EOD' |
|
|
|
|
<div>0<label>text1 <input type="checkbox" name="test[]" value="value1"></label> |
|
|
|
|
1<label>text2 <input type="checkbox" name="test[]" value="value2" checked></label></div> |
|
|
|
|
EOD; |
|
|
|
|
$this->assertEqualsWithoutLE($expected, Html::checkboxList('test', ['value2'], $dataItems, [ |
|
|
|
|
'item' => function ($index, $label, $name, $checked, $value) { |
|
|
|
|
return $index . Html::label($label . ' ' . Html::checkbox($name, $checked, ['value' => $value])); |
|
|
|
|
}, |
|
|
|
|
])); |
|
|
|
|
|
|
|
|
|
$expected = <<<'EOD' |
|
|
|
|
<div><div class="checkbox"><label><input type="checkbox" name="test[]" value="value" checked> label&</label></div></div> |
|
|
|
|
EOD; |
|
|
|
|
$this->assertEqualsWithoutLE($expected, Html::checkboxList('test', 'value', ['value' => 'label&'])); |
|
|
|
|
|
|
|
|
|
$expected = <<<'EOD' |
|
|
|
|
<div><div class="checkbox"><label><input type="checkbox" name="test[]" value="value" checked> label&</label></div></div> |
|
|
|
|
EOD; |
|
|
|
|
$this->assertEqualsWithoutLE($expected, Html::checkboxList('test', 'value', ['value' => 'label&'], ['encode' => false])); |
|
|
|
|
} |
|
|
|
|
} |