helperModel = new DynamicModel(['attributeName']);
ob_start();
$this->helperForm = ActiveForm::begin(['action' => '/something']);
ActiveForm::end();
ob_end_clean();
$this->activeField = new ActiveField(['form' => $this->helperForm]);
$this->activeField->model = $this->helperModel;
$this->activeField->attribute = $this->attributeName;
}
public function testFileInput()
{
Html::$counter = 0;
$html = $this->activeField->fileInput()->render();
$expectedHtml = <<
HTML;
$this->assertEqualsWithoutLE($expectedHtml, $html);
}
// Tests :
public function testRadioList()
{
Html::$counter = 0;
$html = $this->activeField->radioList([1 => 'name1', 2 => 'name2'])->render();
$expectedHtml = <<
HTML;
$this->assertEqualsWithoutLE($expectedHtml, $html);
}
public function testRadioError()
{
Html::$counter = 0;
$this->helperModel->addError($this->attributeName, 'Test print error message');
$html = $this->activeField->radio()->render();
$expectedHtml = <<
HTML;
$this->assertEqualsWithoutLE($expectedHtml, $html);
}
public function testRadioListError()
{
Html::$counter = 0;
$this->helperModel->addError($this->attributeName, 'Test print error message');
$html = $this->activeField->radioList([1 => 'name1', 2 => 'name2'])->render();
$expectedHtml = <<
HTML;
$this->assertEqualsWithoutLE($expectedHtml, $html);
}
public function testCheckboxList()
{
Html::$counter = 0;
$html = $this->activeField->checkboxList([1 => 'name1', 2 => 'name2'])->render();
$expectedHtml = <<
HTML;
$this->assertEqualsWithoutLE($expectedHtml, $html);
}
public function testCheckboxError()
{
Html::$counter = 0;
$this->helperModel->addError($this->attributeName, 'Test print error message');
$html = $this->activeField->checkbox()->render();
$expectedHtml = <<
HTML;
$this->assertEqualsWithoutLE($expectedHtml, $html);
}
public function testCheckboxListError()
{
Html::$counter = 0;
$this->helperModel->addError($this->attributeName, 'Test print error message');
$html = $this->activeField->checkboxList([1 => 'name1', 2 => 'name2'])->render();
$expectedHtml = <<
HTML;
$this->assertEqualsWithoutLE($expectedHtml, $html);
}
public function testRadioListInline()
{
Html::$counter = 0;
$this->activeField->inline = true;
$html = $this->activeField->radioList([1 => 'name1', 2 => 'name2'])->render();
$expectedHtml = <<
HTML;
$this->assertEqualsWithoutLE($expectedHtml, $html);
}
public function testCheckboxListInline()
{
Html::$counter = 0;
$this->activeField->inline = true;
$html = $this->activeField->checkboxList([1 => 'name1', 2 => 'name2'])->render();
$expectedHtml = <<
HTML;
$this->assertEqualsWithoutLE($expectedHtml, $html);
}
/**
* @depends testRadioList
*
* @see https://github.com/yiisoft/yii2-bootstrap/issues/81
*/
public function testRadioListItemOptions()
{
Html::$counter = 0;
$content = $this->activeField->radioList([1 => 'name1', 2 => 'name2'], [
'itemOptions' => [
'data-attribute' => 'test'
]
])->render();
$this->assertContains('data-attribute="test"', $content);
}
/**
* @depends testCheckboxList
*
* @see https://github.com/yiisoft/yii2-bootstrap/issues/81
*/
public function testCheckboxListItemOptions()
{
Html::$counter = 0;
$content = $this->activeField->checkboxList([1 => 'name1', 2 => 'name2'], [
'itemOptions' => [
'data-attribute' => 'test'
]
])->render();
$this->assertContains('data-attribute="test"', $content);
}
/**
*
*/
public function testCustomRadio()
{
Html::$counter = 0;
$this->activeField->inline = true;
$html = $this->activeField->radio()->render();
$expectedHtml = <<
HTML;
$this->assertEqualsWithoutLE($expectedHtml, $html);
}
/**
*
*/
public function testCustomCheckbox()
{
Html::$counter = 0;
$this->activeField->inline = true;
$html = $this->activeField->checkbox()->render();
$expectedHtml = <<
HTML;
$this->assertEqualsWithoutLE($expectedHtml, $html);
}
}