Browse Source

Fixed test breaks.

tags/2.0.0-beta
Qiang Xue 11 years ago
parent
commit
7aeb2fcf4f
  1. 14
      framework/yii/helpers/HtmlBase.php
  2. 50
      tests/unit/framework/helpers/HtmlTest.php

14
framework/yii/helpers/HtmlBase.php

@ -761,9 +761,10 @@ class HtmlBase
if ($formatter !== null) {
$lines[] = call_user_func($formatter, $index, $label, $name, $checked, $value);
} else {
$checkbox = static::checkbox($name, $checked, array('value' => $value));
$content = static::label($checkbox . ' ' . ($encode ? static::encode($label) : $label));
$lines[] = static::tag('div', $content, array('class' => 'checkbox'));
$lines[] = static::checkbox($name, $checked, array(
'value' => $value,
'label' => $encode ? static::encode($label) : $label,
));
}
$index++;
}
@ -819,9 +820,10 @@ class HtmlBase
if ($formatter !== null) {
$lines[] = call_user_func($formatter, $index, $label, $name, $checked, $value);
} else {
$radio = static::radio($name, $checked, array('value' => $value));
$content = static::label($radio . ' ' . ($encode ? static::encode($label) : $label));
$lines[] = static::tag('div', $content, array('class' => 'radio'));
$lines[] = static::radio($name, $checked, array(
'value' => $value,
'label' => $encode ? static::encode($label) : $label,
));
}
$index++;
}

50
tests/unit/framework/helpers/HtmlTest.php

@ -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" 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('<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()
@ -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" 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('<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()
@ -299,20 +325,20 @@ EOD;
$this->assertEquals('', Html::checkboxList('test'));
$expected = <<<EOD
<label><input type="checkbox" name="test[]" value="value1"> text1</label>
<label><input type="checkbox" name="test[]" value="value2" checked> text2</label>
<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>
EOD;
$this->assertEqualsWithoutLE($expected, Html::checkboxList('test', array('value2'), $this->getDataItems()));
$expected = <<<EOD
<label><input type="checkbox" name="test[]" value="value1&lt;&gt;"> text1&lt;&gt;</label>
<label><input type="checkbox" name="test[]" value="value 2"> text 2</label>
<div class="checkbox"><label><input type="checkbox" name="test[]" value="value1&lt;&gt;"> text1&lt;&gt;</label></div>
<div class="checkbox"><label><input type="checkbox" name="test[]" value="value 2"> text 2</label></div>
EOD;
$this->assertEqualsWithoutLE($expected, Html::checkboxList('test', array('value2'), $this->getDataItems2()));
$expected = <<<EOD
<input type="hidden" name="test" value="0"><label><input type="checkbox" name="test[]" value="value1"> text1</label><br>
<label><input type="checkbox" name="test[]" value="value2" checked> text2</label>
<div class="checkbox"><input type="hidden" name="test" value="0"><label><input type="checkbox" name="test[]" value="value1"> text1</label></div><br>
<div class="checkbox"><label><input type="checkbox" name="test[]" value="value2" checked> text2</label></div>
EOD;
$this->assertEqualsWithoutLE($expected, Html::checkboxList('test', array('value2'), $this->getDataItems(), array(
'separator' => "<br>\n",
@ -335,20 +361,20 @@ EOD;
$this->assertEquals('', Html::radioList('test'));
$expected = <<<EOD
<label><input type="radio" name="test" value="value1"> text1</label>
<label><input type="radio" name="test" value="value2" checked> text2</label>
<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>
EOD;
$this->assertEqualsWithoutLE($expected, Html::radioList('test', array('value2'), $this->getDataItems()));
$expected = <<<EOD
<label><input type="radio" name="test" value="value1&lt;&gt;"> text1&lt;&gt;</label>
<label><input type="radio" name="test" value="value 2"> text 2</label>
<div class="radio"><label><input type="radio" name="test" value="value1&lt;&gt;"> text1&lt;&gt;</label></div>
<div class="radio"><label><input type="radio" name="test" value="value 2"> text 2</label></div>
EOD;
$this->assertEqualsWithoutLE($expected, Html::radioList('test', array('value2'), $this->getDataItems2()));
$expected = <<<EOD
<input type="hidden" name="test" value="0"><label><input type="radio" name="test" value="value1"> text1</label><br>
<label><input type="radio" name="test" value="value2" checked> text2</label>
<div class="radio"><input type="hidden" name="test" value="0"><label><input type="radio" name="test" value="value1"> text1</label></div><br>
<div class="radio"><label><input type="radio" name="test" value="value2" checked> text2</label></div>
EOD;
$this->assertEqualsWithoutLE($expected, Html::radioList('test', array('value2'), $this->getDataItems(), array(
'separator' => "<br>\n",

Loading…
Cancel
Save