helperModel = new DynamicModel(['attributeName']); ob_start(); $this->helperForm = ActiveForm::begin(['action' => '/something', 'enableClientScript' => false]); ActiveForm::end(); ob_end_clean(); $this->activeField = new ActiveField(['form' => $this->helperForm]); $this->activeField->model = $this->helperModel; $this->activeField->attribute = $this->attributeName; } // Tests : public function testRadioList() { $html = $this->activeField->radioList([1 => 'name1', 2 => 'name2'])->render(); $expectedHtml = <<

HTML; $this->assertEqualsWithoutLE($expectedHtml, $html); } public function testCheckboxList() { $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() { $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() { $content = $this->activeField->checkboxList([1 => 'name1', 2 => 'name2'], [ 'itemOptions' => [ 'data-attribute' => 'test' ] ])->render(); $this->assertContains('data-attribute="test"', $content); } public function testHorizontalCssClasses() { $this->helperForm->layout = 'horizontal'; $activeField = new ActiveField(['form' => $this->helperForm]); $activeField->model = $this->helperModel; $activeField->attribute = $this->attributeName; $html = $activeField->render(); $expectedHtml = <<

EXPECTED; $this->assertEqualsWithoutLE($expectedHtml, $html); } /** * @depends testHorizontalCssClasses */ public function testHorizontalCssClassesOverride() { $this->helperForm->layout = 'horizontal'; $activeField = new ExtendedActiveField(['form' => $this->helperForm]); $activeField->model = $this->helperModel; $activeField->attribute = $this->attributeName; $html = $activeField->render(); $expectedHtml = <<

EXPECTED; $this->assertEqualsWithoutLE($expectedHtml, $html); } }