_activeField->inline = true;
$html = $this->_activeField->checkbox()->render();
$expectedHtml = <<
HTML;
$this->assertEqualsWithoutLE($expectedHtml, $html);
}
public function testDefaultRadioByConfig()
{
Html::$counter = 0;
$this->_activeField->inline = true;
$html = $this->_activeField->radio()->render();
$expectedHtml = <<
HTML;
$this->assertEqualsWithoutLE($expectedHtml, $html);
}
public function testDefaultCheckboxListByConfig()
{
Html::$counter = 0;
$html = $this->_activeField->checkboxList([1 => 'name1', 2 => 'name2'])->render();
$expectedHtml = <<
HTML;
$this->assertEqualsWithoutLE($expectedHtml, $html);
}
public function testDefaultRadioListByConfig()
{
Html::$counter = 0;
$html = $this->_activeField->radioList([1 => 'name1', 2 => 'name2'])->render();
$expectedHtml = <<
HTML;
$this->assertEqualsWithoutLE($expectedHtml, $html);
}
public function testHorizontalLayout()
{
Html::$counter = 0;
ActiveForm::$counter = 0;
ob_start();
$model = new DynamicModel(['attributeName', 'checkbox', 'gridRadios']);
$form = ActiveForm::begin([
'action' => '/some-action',
'layout' => ActiveForm::LAYOUT_HORIZONTAL
]);
echo $form->field($model, 'attributeName');
echo $form->field($model, 'checkbox')->checkbox(['wrapperOptions' => ['class' => ['widget' => new UnsetArrayValue()]]]);
echo $form->field($model, 'gridRadios')->radioList([
'option1' => 'First radio',
'option2' => 'Second radio',
'option3' => 'Third radio'
]);
ActiveForm::end();
$out = ob_get_clean();
$expected = <<
HTML;
$expected2 = <<
HTML;
$expected3 = <<
HTML;
$this->assertContainsWithoutLE($expected, $out);
$this->assertContainsWithoutLE($expected2, $out);
$this->assertContainsWithoutLE($expected3, $out);
}
protected function setUp()
{
// dirty way to have Request object not throwing exception when running testHomeLinkNull()
$_SERVER['SCRIPT_FILENAME'] = 'index.php';
$_SERVER['SCRIPT_NAME'] = 'index.php';
$this->mockWebApplication([
'container' => [
'definitions' => [
'yii\bootstrap5\ActiveField' => [
'checkTemplate' => "\n{input}\n{label}\n{error}\n{hint}\n
",
'radioTemplate' => "\n{input}\n{label}\n{error}\n{hint}\n
",
'checkHorizontalTemplate' => "{beginWrapper}\n\n{input}\n{label}\n{error}\n{hint}\n
\n{endWrapper}",
'radioHorizontalTemplate' => "{beginWrapper}\n\n{input}\n{label}\n{error}\n{hint}\n
\n{endWrapper}",
'checkOptions' => [
'class' => ['widget' => 'form-check-input'],
'labelOptions' => [
'class' => ['widget' => 'form-check-label']
],
'wrapperOptions' => [
'class' => ['widget' => 'form-check']
]
],
'radioOptions' => [
'class' => ['widget' => 'form-check-input'],
'labelOptions' => [
'class' => ['widget' => 'form-check-label']
],
'wrapperOptions' => [
'class' => ['widget' => 'form-check']
]
]
]
]
]
]);
$this->_helperModel = new DynamicModel(['attributeName']);
ob_start();
$this->_helperForm = ActiveForm::begin(['action' => '/something']);
ActiveForm::end();
ob_end_clean();
$this->_activeField = Yii::createObject([
'class' => 'yii\bootstrap5\ActiveField',
'form' => $this->_helperForm
]);
$this->_activeField->model = $this->_helperModel;
$this->_activeField->attribute = $this->_attributeName;
}
}