'/some-action', 'layout' => ActiveForm::LAYOUT_DEFAULT ]); echo $form->field($model, 'attributeName'); ActiveForm::end(); $out = ob_get_clean(); $expected = <<
HTML; $this->assertContainsWithoutLE($expected, $out); } 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(); 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); } /** * @depends testHorizontalLayout */ public function testHorizontalLayoutTemplateOverride() { ActiveForm::$counter = 0; ob_start(); $model = new DynamicModel(['checkboxName']); $form = ActiveForm::begin([ 'action' => '/some-action', 'layout' => ActiveForm::LAYOUT_HORIZONTAL ]); echo $form->field($model, 'checkboxName')->checkbox(['template' => "
\n{input}\n{label}\n
\n
{error}
"]); ActiveForm::end(); $out = ob_get_clean(); $expected = <<
HTML; $this->assertContainsWithoutLE($expected, $out); } public function testInlineLayout() { ActiveForm::$counter = 0; ob_start(); $model = new DynamicModel(['attributeName', 'selectName', 'checkboxName']); $form = ActiveForm::begin([ 'action' => '/some-action', 'layout' => ActiveForm::LAYOUT_INLINE ]); echo $form->field($model, 'attributeName'); echo $form->field($model, 'selectName')->listBox([ '1' => 'One', '2' => 'Two', '3' => 'Three' ]); echo $form->field($model, 'checkboxName')->checkbox(); ActiveForm::end(); $out = ob_get_clean(); $expected = << HTML; $expected2 = << HTML; $expected3 = <<
HTML; $this->assertContainsWithoutLE('
assertContainsWithoutLE($expected, $out); $this->assertContainsWithoutLE($expected2, $out); $this->assertContainsWithoutLE($expected3, $out); } public function testFloatingLayout() { ActiveForm::$counter = 0; ob_start(); $model = new DynamicModel(['attributeName', 'selectName', 'checkboxName']); $form = ActiveForm::begin([ 'action' => '/some-action', 'layout' => ActiveForm::LAYOUT_FLOATING ]); echo $form->field($model, 'attributeName'); echo $form->field($model, 'selectName')->listBox([ '1' => 'One', '2' => 'Two', '3' => 'Three' ]); echo $form->field($model, 'checkboxName')->checkbox(); ActiveForm::end(); $out = ob_get_clean(); $expected = <<
HTML; $expected2 = <<
HTML; $expected3 = <<
HTML; $this->assertContainsWithoutLE('assertContainsWithoutLE($expected, $out); $this->assertContainsWithoutLE($expected2, $out); $this->assertContainsWithoutLE($expected3, $out); } public function testHintRendering() { ActiveForm::$counter = 0; ob_start(); $model = new User(); $form = ActiveForm::begin([ 'action' => '/some-action', 'layout' => ActiveForm::LAYOUT_DEFAULT ]); echo $form->field($model, 'firstName'); echo $form->field($model, 'lastName'); echo $form->field($model, 'username'); echo $form->field($model, 'password')->passwordInput(); ActiveForm::end(); $out = ob_get_clean(); $expected = <<
HTML; $expected2 = <<
HTML; $expected3 = << Your username must be at least 4 characters long
HTML; $expected4 = << Your password must be 8-20 characters long, contain letters and numbers, and must not contain spaces, special characters, or emoji.
HTML; $this->assertContainsWithoutLE($expected, $out); $this->assertContainsWithoutLE($expected2, $out); $this->assertContainsWithoutLE($expected3, $out); $this->assertContainsWithoutLE($expected4, $out); } /** * Fixes #128 * @see https://github.com/yiisoft/yii2-bootstrap5/issues/128 */ public function testInputTemplate() { $model = new User(); $model->validate(); ActiveForm::$counter = 0; ob_start(); $form = ActiveForm::begin(); echo $form->field($model, 'username', ['inputTemplate' => '{input}']); ActiveForm::end(); $out = ob_get_clean(); $expected = << Your username must be at least 4 characters long
Username cannot be blank.
HTML; $this->assertContainsWithoutLE($expected, $out); } /** * Fixes #196 */ public function testFormNoRoleAttribute() { $form = ActiveForm::widget(); $this->assertNotContains('role="form"', $form); } public function testErrorSummaryRendering() { ActiveForm::$counter = 0; ob_start(); $model = new User(); $model->validate(); $form = ActiveForm::begin([ 'action' => '/some-action', 'layout' => ActiveForm::LAYOUT_DEFAULT ]); echo $form->errorSummary($model); ActiveForm::end(); $out = ob_get_clean(); $this->assertContainsWithoutLE('