diff --git a/tests/ActiveFieldTest.php b/tests/ActiveFieldTest.php new file mode 100644 index 0000000..5ef4480 --- /dev/null +++ b/tests/ActiveFieldTest.php @@ -0,0 +1,113 @@ +mockWebApplication(); + + $this->helperModel = new DynamicModel(['attributeName']); + ob_start(); + $this->helperForm = new ActiveForm(['action' => '/something']); + 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); + } +} \ No newline at end of file