Commit 7aeb2fcf by Qiang Xue

Fixed test breaks.

parent 20727c8c
...@@ -761,9 +761,10 @@ class HtmlBase ...@@ -761,9 +761,10 @@ class HtmlBase
if ($formatter !== null) { if ($formatter !== null) {
$lines[] = call_user_func($formatter, $index, $label, $name, $checked, $value); $lines[] = call_user_func($formatter, $index, $label, $name, $checked, $value);
} else { } else {
$checkbox = static::checkbox($name, $checked, array('value' => $value)); $lines[] = static::checkbox($name, $checked, array(
$content = static::label($checkbox . ' ' . ($encode ? static::encode($label) : $label)); 'value' => $value,
$lines[] = static::tag('div', $content, array('class' => 'checkbox')); 'label' => $encode ? static::encode($label) : $label,
));
} }
$index++; $index++;
} }
...@@ -819,9 +820,10 @@ class HtmlBase ...@@ -819,9 +820,10 @@ class HtmlBase
if ($formatter !== null) { if ($formatter !== null) {
$lines[] = call_user_func($formatter, $index, $label, $name, $checked, $value); $lines[] = call_user_func($formatter, $index, $label, $name, $checked, $value);
} else { } else {
$radio = static::radio($name, $checked, array('value' => $value)); $lines[] = static::radio($name, $checked, array(
$content = static::label($radio . ' ' . ($encode ? static::encode($label) : $label)); 'value' => $value,
$lines[] = static::tag('div', $content, array('class' => 'radio')); 'label' => $encode ? static::encode($label) : $label,
));
} }
$index++; $index++;
} }
......
...@@ -210,6 +210,19 @@ class HtmlTest extends TestCase ...@@ -210,6 +210,19 @@ class HtmlTest extends TestCase
$this->assertEquals('<input type="radio" name="test" value="1">', Html::radio('test')); $this->assertEquals('<input type="radio" name="test" value="1">', Html::radio('test'));
$this->assertEquals('<input type="radio" class="a" name="test" checked>', Html::radio('test', true, array('class' => 'a', 'value' => null))); $this->assertEquals('<input type="radio" class="a" name="test" checked>', Html::radio('test', true, array('class' => 'a', 'value' => null)));
$this->assertEquals('<input type="hidden" name="test" value="0"><input type="radio" class="a" name="test" value="2" checked>', Html::radio('test', true, array('class' => 'a' , 'uncheck' => '0', 'value' => 2))); $this->assertEquals('<input type="hidden" name="test" value="0"><input type="radio" class="a" name="test" value="2" checked>', Html::radio('test', true, array('class' => 'a' , 'uncheck' => '0', 'value' => 2)));
$this->assertEquals('<div class="radio"><label class="bbb"><input type="checkbox" class="a" name="test" checked> ccc</label></div>', Html::radio('test', true, array(
'class' => 'a',
'value' => null,
'label' => 'ccc',
'labelOptions' => array('class' =>'bbb'),
)));
$this->assertEquals('<input type="hidden" name="test" value="0"><div class="radio"><label><input type="checkbox" class="a" name="test" value="2" checked></label></div>', Html::radio('test', true, array(
'class' => 'a',
'uncheck' => '0',
'label' => 'ccc',
'value' => 2,
)));
} }
public function testCheckbox() public function testCheckbox()
...@@ -217,6 +230,19 @@ class HtmlTest extends TestCase ...@@ -217,6 +230,19 @@ class HtmlTest extends TestCase
$this->assertEquals('<input type="checkbox" name="test" value="1">', Html::checkbox('test')); $this->assertEquals('<input type="checkbox" name="test" value="1">', Html::checkbox('test'));
$this->assertEquals('<input type="checkbox" class="a" name="test" checked>', Html::checkbox('test', true, array('class' => 'a', 'value' => null))); $this->assertEquals('<input type="checkbox" class="a" name="test" checked>', Html::checkbox('test', true, array('class' => 'a', 'value' => null)));
$this->assertEquals('<input type="hidden" name="test" value="0"><input type="checkbox" class="a" name="test" value="2" checked>', Html::checkbox('test', true, array('class' => 'a', 'uncheck' => '0', 'value' => 2))); $this->assertEquals('<input type="hidden" name="test" value="0"><input type="checkbox" class="a" name="test" value="2" checked>', Html::checkbox('test', true, array('class' => 'a', 'uncheck' => '0', 'value' => 2)));
$this->assertEquals('<div class="checkbox"><label class="bbb"><input type="checkbox" class="a" name="test" checked> ccc</label></div>', Html::checkbox('test', true, array(
'class' => 'a',
'value' => null,
'label' => 'ccc',
'labelOptions' => array('class' =>'bbb'),
)));
$this->assertEquals('<input type="hidden" name="test" value="0"><div class="checkbox"><label><input type="checkbox" class="a" name="test" value="2" checked></label></div>', Html::checkbox('test', true, array(
'class' => 'a',
'uncheck' => '0',
'label' => 'ccc',
'value' => 2,
)));
} }
public function testDropDownList() public function testDropDownList()
...@@ -299,20 +325,20 @@ EOD; ...@@ -299,20 +325,20 @@ EOD;
$this->assertEquals('', Html::checkboxList('test')); $this->assertEquals('', Html::checkboxList('test'));
$expected = <<<EOD $expected = <<<EOD
<label><input type="checkbox" name="test[]" value="value1"> text1</label> <div class="checkbox"><label><input type="checkbox" name="test[]" value="value1"> text1</label></div>
<label><input type="checkbox" name="test[]" value="value2" checked> text2</label> <div class="checkbox"><label><input type="checkbox" name="test[]" value="value2" checked> text2</label></div>
EOD; EOD;
$this->assertEqualsWithoutLE($expected, Html::checkboxList('test', array('value2'), $this->getDataItems())); $this->assertEqualsWithoutLE($expected, Html::checkboxList('test', array('value2'), $this->getDataItems()));
$expected = <<<EOD $expected = <<<EOD
<label><input type="checkbox" name="test[]" value="value1&lt;&gt;"> text1&lt;&gt;</label> <div class="checkbox"><label><input type="checkbox" name="test[]" value="value1&lt;&gt;"> text1&lt;&gt;</label></div>
<label><input type="checkbox" name="test[]" value="value 2"> text 2</label> <div class="checkbox"><label><input type="checkbox" name="test[]" value="value 2"> text 2</label></div>
EOD; EOD;
$this->assertEqualsWithoutLE($expected, Html::checkboxList('test', array('value2'), $this->getDataItems2())); $this->assertEqualsWithoutLE($expected, Html::checkboxList('test', array('value2'), $this->getDataItems2()));
$expected = <<<EOD $expected = <<<EOD
<input type="hidden" name="test" value="0"><label><input type="checkbox" name="test[]" value="value1"> text1</label><br> <div class="checkbox"><input type="hidden" name="test" value="0"><label><input type="checkbox" name="test[]" value="value1"> text1</label></div><br>
<label><input type="checkbox" name="test[]" value="value2" checked> text2</label> <div class="checkbox"><label><input type="checkbox" name="test[]" value="value2" checked> text2</label></div>
EOD; EOD;
$this->assertEqualsWithoutLE($expected, Html::checkboxList('test', array('value2'), $this->getDataItems(), array( $this->assertEqualsWithoutLE($expected, Html::checkboxList('test', array('value2'), $this->getDataItems(), array(
'separator' => "<br>\n", 'separator' => "<br>\n",
...@@ -335,20 +361,20 @@ EOD; ...@@ -335,20 +361,20 @@ EOD;
$this->assertEquals('', Html::radioList('test')); $this->assertEquals('', Html::radioList('test'));
$expected = <<<EOD $expected = <<<EOD
<label><input type="radio" name="test" value="value1"> text1</label> <div class="radio"><label><input type="radio" name="test" value="value1"> text1</label></div>
<label><input type="radio" name="test" value="value2" checked> text2</label> <div class="radio"><label><input type="radio" name="test" value="value2" checked> text2</label></div>
EOD; EOD;
$this->assertEqualsWithoutLE($expected, Html::radioList('test', array('value2'), $this->getDataItems())); $this->assertEqualsWithoutLE($expected, Html::radioList('test', array('value2'), $this->getDataItems()));
$expected = <<<EOD $expected = <<<EOD
<label><input type="radio" name="test" value="value1&lt;&gt;"> text1&lt;&gt;</label> <div class="radio"><label><input type="radio" name="test" value="value1&lt;&gt;"> text1&lt;&gt;</label></div>
<label><input type="radio" name="test" value="value 2"> text 2</label> <div class="radio"><label><input type="radio" name="test" value="value 2"> text 2</label></div>
EOD; EOD;
$this->assertEqualsWithoutLE($expected, Html::radioList('test', array('value2'), $this->getDataItems2())); $this->assertEqualsWithoutLE($expected, Html::radioList('test', array('value2'), $this->getDataItems2()));
$expected = <<<EOD $expected = <<<EOD
<input type="hidden" name="test" value="0"><label><input type="radio" name="test" value="value1"> text1</label><br> <div class="radio"><input type="hidden" name="test" value="0"><label><input type="radio" name="test" value="value1"> text1</label></div><br>
<label><input type="radio" name="test" value="value2" checked> text2</label> <div class="radio"><label><input type="radio" name="test" value="value2" checked> text2</label></div>
EOD; EOD;
$this->assertEqualsWithoutLE($expected, Html::radioList('test', array('value2'), $this->getDataItems(), array( $this->assertEqualsWithoutLE($expected, Html::radioList('test', array('value2'), $this->getDataItems(), array(
'separator' => "<br>\n", 'separator' => "<br>\n",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment