'
],
[
'',
[],
''
]
];
}
/**
* @dataProvider dataProviderStaticControl
*
* @param string $value
* @param array $options
* @param string $expectedHtml
*/
public function testStaticControl($value, array $options, $expectedHtml)
{
$this->assertEquals($expectedHtml, Html::staticControl($value, $options));
}
public function testRadioList()
{
$this->assertEquals('
', Html::radioList('test'));
$dataItems = [
'value1' => 'text1',
'value2' => 'text2',
];
Html::$counter = 0;
$expected = <<<'EOD'
EOD;
$this->assertEqualsWithoutLE($expected, Html::radioList('test', ['value2'], $dataItems));
Html::$counter = 0;
$expected = <<<'EOD'
0
1
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]));
},
]));
Html::$counter = 0;
$expected = <<<'EOD'
EOD;
$this->assertEqualsWithoutLE($expected, Html::radioList('test', [], ['value' => 'label&']));
Html::$counter = 0;
$expected = <<<'EOD'
EOD;
$this->assertEqualsWithoutLE($expected, Html::radioList('test', [], ['value' => 'label&'], ['encode' => false]));
}
public function testCheckboxList()
{
$this->assertEquals('', Html::checkboxList('test'));
$dataItems = [
'value1' => 'text1',
'value2' => 'text2',
];
Html::$counter = 0;
$expected = <<<'EOD'
EOD;
$this->assertEqualsWithoutLE($expected, Html::checkboxList('test', ['value2'], $dataItems));
Html::$counter = 0;
$expected = <<<'EOD'
0
1
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]));
},
]));
Html::$counter = 0;
$expected = <<<'EOD'
EOD;
$this->assertEqualsWithoutLE($expected, Html::checkboxList('test', 'value', ['value' => 'label&']));
Html::$counter = 0;
$expected = <<<'EOD'
EOD;
$this->assertEqualsWithoutLE($expected, Html::checkboxList('test', 'value', ['value' => 'label&'], ['encode' => false]));
}
public function testError()
{
$model = new DynamicModel();
$model->addError('foo', 'Some error message.');
$this->assertEquals('Some error message.
', Html::error($model, 'foo'));
$this->assertEquals('Some error message.
', Html::error($model, 'foo', ['class' => 'custom-class']));
$this->assertEquals('Some error message.
', Html::error($model, 'foo', ['class' => null]));
$this->assertEquals('Some error message.
', Html::error($model, 'foo', ['tag' => 'p']));
}
}