Commit 08be6964 by Alexander Makarov

fixed Html test under Windows (line endings)

parent 3e2e4afa
...@@ -22,6 +22,14 @@ class HtmlTest extends \yii\test\TestCase ...@@ -22,6 +22,14 @@ class HtmlTest extends \yii\test\TestCase
)); ));
} }
public function assertEqualsWithoutLE($expected, $actual)
{
$expected = str_replace("\r\n", "\n", $expected);
$actual = str_replace("\r\n", "\n", $actual);
$this->assertEquals($expected, $actual);
}
public function tearDown() public function tearDown()
{ {
Yii::$app = null; Yii::$app = null;
...@@ -240,21 +248,21 @@ class HtmlTest extends \yii\test\TestCase ...@@ -240,21 +248,21 @@ class HtmlTest extends \yii\test\TestCase
</select> </select>
EOD; EOD;
$this->assertEquals($expected, Html::dropDownList('test')); $this->assertEqualsWithoutLE($expected, Html::dropDownList('test'));
$expected = <<<EOD $expected = <<<EOD
<select name="test"> <select name="test">
<option value="value1">text1</option> <option value="value1">text1</option>
<option value="value2">text2</option> <option value="value2">text2</option>
</select> </select>
EOD; EOD;
$this->assertEquals($expected, Html::dropDownList('test', null, $this->getDataItems())); $this->assertEqualsWithoutLE($expected, Html::dropDownList('test', null, $this->getDataItems()));
$expected = <<<EOD $expected = <<<EOD
<select name="test"> <select name="test">
<option value="value1">text1</option> <option value="value1">text1</option>
<option value="value2" selected="selected">text2</option> <option value="value2" selected="selected">text2</option>
</select> </select>
EOD; EOD;
$this->assertEquals($expected, Html::dropDownList('test', 'value2', $this->getDataItems())); $this->assertEqualsWithoutLE($expected, Html::dropDownList('test', 'value2', $this->getDataItems()));
} }
public function testListBox() public function testListBox()
...@@ -264,48 +272,48 @@ EOD; ...@@ -264,48 +272,48 @@ EOD;
</select> </select>
EOD; EOD;
$this->assertEquals($expected, Html::listBox('test')); $this->assertEqualsWithoutLE($expected, Html::listBox('test'));
$expected = <<<EOD $expected = <<<EOD
<select name="test" size="5"> <select name="test" size="5">
<option value="value1">text1</option> <option value="value1">text1</option>
<option value="value2">text2</option> <option value="value2">text2</option>
</select> </select>
EOD; EOD;
$this->assertEquals($expected, Html::listBox('test', null, $this->getDataItems(), array('size' => 5))); $this->assertEqualsWithoutLE($expected, Html::listBox('test', null, $this->getDataItems(), array('size' => 5)));
$expected = <<<EOD $expected = <<<EOD
<select name="test" size="4"> <select name="test" size="4">
<option value="value1&lt;&gt;">text1&lt;&gt;</option> <option value="value1&lt;&gt;">text1&lt;&gt;</option>
<option value="value 2">text&nbsp;&nbsp;2</option> <option value="value 2">text&nbsp;&nbsp;2</option>
</select> </select>
EOD; EOD;
$this->assertEquals($expected, Html::listBox('test', null, $this->getDataItems2())); $this->assertEqualsWithoutLE($expected, Html::listBox('test', null, $this->getDataItems2()));
$expected = <<<EOD $expected = <<<EOD
<select name="test" size="4"> <select name="test" size="4">
<option value="value1">text1</option> <option value="value1">text1</option>
<option value="value2" selected="selected">text2</option> <option value="value2" selected="selected">text2</option>
</select> </select>
EOD; EOD;
$this->assertEquals($expected, Html::listBox('test', 'value2', $this->getDataItems())); $this->assertEqualsWithoutLE($expected, Html::listBox('test', 'value2', $this->getDataItems()));
$expected = <<<EOD $expected = <<<EOD
<select name="test" size="4"> <select name="test" size="4">
<option value="value1" selected="selected">text1</option> <option value="value1" selected="selected">text1</option>
<option value="value2" selected="selected">text2</option> <option value="value2" selected="selected">text2</option>
</select> </select>
EOD; EOD;
$this->assertEquals($expected, Html::listBox('test', array('value1', 'value2'), $this->getDataItems())); $this->assertEqualsWithoutLE($expected, Html::listBox('test', array('value1', 'value2'), $this->getDataItems()));
$expected = <<<EOD $expected = <<<EOD
<select name="test[]" multiple="multiple" size="4"> <select name="test[]" multiple="multiple" size="4">
</select> </select>
EOD; EOD;
$this->assertEquals($expected, Html::listBox('test', null, array(), array('multiple' => true))); $this->assertEqualsWithoutLE($expected, Html::listBox('test', null, array(), array('multiple' => true)));
$expected = <<<EOD $expected = <<<EOD
<input type="hidden" name="test" value="0" /><select name="test" size="4"> <input type="hidden" name="test" value="0" /><select name="test" size="4">
</select> </select>
EOD; EOD;
$this->assertEquals($expected, Html::listBox('test', '', array(), array('unselect' => '0'))); $this->assertEqualsWithoutLE($expected, Html::listBox('test', '', array(), array('unselect' => '0')));
} }
public function testCheckboxList() public function testCheckboxList()
...@@ -316,19 +324,19 @@ EOD; ...@@ -316,19 +324,19 @@ EOD;
<label><input type="checkbox" name="test[]" value="value1" /> text1</label> <label><input type="checkbox" name="test[]" value="value1" /> text1</label>
<label><input type="checkbox" name="test[]" value="value2" checked="checked" /> text2</label> <label><input type="checkbox" name="test[]" value="value2" checked="checked" /> text2</label>
EOD; EOD;
$this->assertEquals($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<></label> <label><input type="checkbox" name="test[]" value="value1&lt;&gt;" /> text1<></label>
<label><input type="checkbox" name="test[]" value="value 2" /> text 2</label> <label><input type="checkbox" name="test[]" value="value 2" /> text 2</label>
EOD; EOD;
$this->assertEquals($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 /> <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="checked" /> text2</label> <label><input type="checkbox" name="test[]" value="value2" checked="checked" /> text2</label>
EOD; EOD;
$this->assertEquals($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",
'unselect' => '0', 'unselect' => '0',
))); )));
...@@ -337,7 +345,7 @@ EOD; ...@@ -337,7 +345,7 @@ EOD;
0<label>text1 <input type="checkbox" name="test[]" value="value1" /></label> 0<label>text1 <input type="checkbox" name="test[]" value="value1" /></label>
1<label>text2 <input type="checkbox" name="test[]" value="value2" checked="checked" /></label> 1<label>text2 <input type="checkbox" name="test[]" value="value2" checked="checked" /></label>
EOD; EOD;
$this->assertEquals($expected, Html::checkboxList('test', array('value2'), $this->getDataItems(), array( $this->assertEqualsWithoutLE($expected, Html::checkboxList('test', array('value2'), $this->getDataItems(), array(
'item' => function ($index, $label, $name, $checked, $value) { 'item' => function ($index, $label, $name, $checked, $value) {
return $index . Html::label($label . ' ' . Html::checkbox($name, $checked, $value)); return $index . Html::label($label . ' ' . Html::checkbox($name, $checked, $value));
} }
...@@ -352,19 +360,19 @@ EOD; ...@@ -352,19 +360,19 @@ EOD;
<label><input type="radio" name="test" value="value1" /> text1</label> <label><input type="radio" name="test" value="value1" /> text1</label>
<label><input type="radio" name="test" value="value2" checked="checked" /> text2</label> <label><input type="radio" name="test" value="value2" checked="checked" /> text2</label>
EOD; EOD;
$this->assertEquals($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<></label> <label><input type="radio" name="test" value="value1&lt;&gt;" /> text1<></label>
<label><input type="radio" name="test" value="value 2" /> text 2</label> <label><input type="radio" name="test" value="value 2" /> text 2</label>
EOD; EOD;
$this->assertEquals($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 /> <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="checked" /> text2</label> <label><input type="radio" name="test" value="value2" checked="checked" /> text2</label>
EOD; EOD;
$this->assertEquals($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",
'unselect' => '0', 'unselect' => '0',
))); )));
...@@ -373,7 +381,7 @@ EOD; ...@@ -373,7 +381,7 @@ EOD;
0<label>text1 <input type="radio" name="test" value="value1" /></label> 0<label>text1 <input type="radio" name="test" value="value1" /></label>
1<label>text2 <input type="radio" name="test" value="value2" checked="checked" /></label> 1<label>text2 <input type="radio" name="test" value="value2" checked="checked" /></label>
EOD; EOD;
$this->assertEquals($expected, Html::radioList('test', array('value2'), $this->getDataItems(), array( $this->assertEqualsWithoutLE($expected, Html::radioList('test', array('value2'), $this->getDataItems(), array(
'item' => function ($index, $label, $name, $checked, $value) { 'item' => function ($index, $label, $name, $checked, $value) {
return $index . Html::label($label . ' ' . Html::radio($name, $checked, $value)); return $index . Html::label($label . ' ' . Html::radio($name, $checked, $value));
} }
...@@ -420,7 +428,7 @@ EOD; ...@@ -420,7 +428,7 @@ EOD;
'group12' => array('class' => 'group'), 'group12' => array('class' => 'group'),
), ),
); );
$this->assertEquals($expected, Html::renderSelectOptions(array('value111', 'value1'), $data, $attributes)); $this->assertEqualsWithoutLE($expected, Html::renderSelectOptions(array('value111', 'value1'), $data, $attributes));
} }
public function testRenderAttributes() public function testRenderAttributes()
......
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