From 22749b0b81b2c7108347d34ee13132462b44043a Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Mon, 6 May 2024 12:37:33 -0400 Subject: [PATCH] Add test for checkbox field default values (#1119) --- .../tests/formwidgets/CheckboxTest.php | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 modules/backend/tests/formwidgets/CheckboxTest.php diff --git a/modules/backend/tests/formwidgets/CheckboxTest.php b/modules/backend/tests/formwidgets/CheckboxTest.php new file mode 100644 index 0000000000..14bda47af9 --- /dev/null +++ b/modules/backend/tests/formwidgets/CheckboxTest.php @@ -0,0 +1,52 @@ +form = new Form(null, [ + 'model' => new Model, + 'arrayName' => 'array', + 'fields' => [ + 'unchecked' => [ + 'type' => 'checkbox', + 'label' => 'My Test Checkbox unchecked', + ], + 'checkedForced' => [ + 'type' => 'checkbox', + 'label' => 'My Test Checkbox checked', + 'default' => true, + ], + 'uncheckedForced' => [ + 'type' => 'checkbox', + 'label' => 'My Test Checkbox unchecked', + 'default' => false, + ], + ], + ]); + + $this->form->render(); + } + + public function testConfigDefaultValue() + { + $unchecked = $this->form->getField('unchecked'); + $this->assertFalse($unchecked->isSelected()); + + $checkedForced = $this->form->getField('checkedForced'); + $this->assertTrue($checkedForced->isSelected()); + + $uncheckedForced = $this->form->getField('uncheckedForced'); + $this->assertFalse($uncheckedForced->isSelected()); + } +}