From d13bf1e0bcc2ddb187ae16c0c317d67bf5619878 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Fri, 23 Mar 2018 16:18:32 +1300 Subject: [PATCH] Add tests to ensure that editable form fields allow nullable titles --- .../EditableCheckboxGroupFieldTest.php | 8 +++++++ .../EditableCheckboxTest.php | 17 +++++++++++++++ .../EditableCountryDropdownFieldTest.php | 8 +++++++ .../EditableDateFieldTest.php | 17 +++++++++++++++ .../EditableDropdownTest.php | 8 +++++++ .../EditableEmailFieldTest.php | 17 +++++++++++++++ .../EditableFieldGroupTest.php | 17 +++++++++++++++ .../EditableFileFieldTest.php | 8 +++++++ .../EditableFormHeadingTest.php | 17 +++++++++++++++ .../EditableFormStepTest.php | 17 +++++++++++++++ .../EditableLiteralFieldTest.php | 8 +++++++ .../EditableMemberListFieldTest.php | 21 +++++++++++++++++++ .../EditableMemberListFieldTest.yml | 3 +++ .../EditableNumericFieldTest.php | 17 +++++++++++++++ .../EditableRadioFieldTest.php | 10 +++++++-- .../EditableTextFieldTest.php | 8 +++++++ 16 files changed, 199 insertions(+), 2 deletions(-) create mode 100644 tests/Model/EditableFormField/EditableCheckboxTest.php create mode 100644 tests/Model/EditableFormField/EditableDateFieldTest.php create mode 100644 tests/Model/EditableFormField/EditableEmailFieldTest.php create mode 100644 tests/Model/EditableFormField/EditableFieldGroupTest.php create mode 100644 tests/Model/EditableFormField/EditableFormHeadingTest.php create mode 100644 tests/Model/EditableFormField/EditableFormStepTest.php create mode 100644 tests/Model/EditableFormField/EditableMemberListFieldTest.php create mode 100644 tests/Model/EditableFormField/EditableMemberListFieldTest.yml create mode 100644 tests/Model/EditableFormField/EditableNumericFieldTest.php diff --git a/tests/Model/EditableFormField/EditableCheckboxGroupFieldTest.php b/tests/Model/EditableFormField/EditableCheckboxGroupFieldTest.php index cc25b05..00e0380 100644 --- a/tests/Model/EditableFormField/EditableCheckboxGroupFieldTest.php +++ b/tests/Model/EditableFormField/EditableCheckboxGroupFieldTest.php @@ -18,4 +18,12 @@ class EditableCheckboxGroupFieldTest extends SapphireTest $checkboxGroup = $this->objFromFixture(EditableCheckboxGroupField::class, 'checkbox-group'); $this->assertSame(UserFormsCheckboxSetField::class, $checkboxGroup->getFormField()->getTemplate()); } + + public function testAllowEmptyTitle() + { + /** @var EditableCheckboxGroupField $field */ + $field = EditableCheckboxGroupField::create(); + $field->Name = 'EditableFormField_123456'; + $this->assertEmpty($field->getFormField()->Title()); + } } diff --git a/tests/Model/EditableFormField/EditableCheckboxTest.php b/tests/Model/EditableFormField/EditableCheckboxTest.php new file mode 100644 index 0000000..1c8816d --- /dev/null +++ b/tests/Model/EditableFormField/EditableCheckboxTest.php @@ -0,0 +1,17 @@ +Name = 'EditableFormField_123456'; + $this->assertEmpty($field->getFormField()->Title()); + } +} diff --git a/tests/Model/EditableFormField/EditableCountryDropdownFieldTest.php b/tests/Model/EditableFormField/EditableCountryDropdownFieldTest.php index dff76c1..cfff955 100644 --- a/tests/Model/EditableFormField/EditableCountryDropdownFieldTest.php +++ b/tests/Model/EditableFormField/EditableCountryDropdownFieldTest.php @@ -13,4 +13,12 @@ class EditableCountryDropdownFieldTest extends SapphireTest $this->assertContains('/images/editabledropdown.png', $field->getIcon()); } + + public function testAllowEmptyTitle() + { + /** @var EditableCountryDropdownField $field */ + $field = EditableCountryDropdownField::create(); + $field->Name = 'EditableFormField_123456'; + $this->assertEmpty($field->getFormField()->Title()); + } } diff --git a/tests/Model/EditableFormField/EditableDateFieldTest.php b/tests/Model/EditableFormField/EditableDateFieldTest.php new file mode 100644 index 0000000..580bc1d --- /dev/null +++ b/tests/Model/EditableFormField/EditableDateFieldTest.php @@ -0,0 +1,17 @@ +Name = 'EditableFormField_123456'; + $this->assertEmpty($field->getFormField()->Title()); + } +} diff --git a/tests/Model/EditableFormField/EditableDropdownTest.php b/tests/Model/EditableFormField/EditableDropdownTest.php index 844a7bd..3545ed7 100644 --- a/tests/Model/EditableFormField/EditableDropdownTest.php +++ b/tests/Model/EditableFormField/EditableDropdownTest.php @@ -36,4 +36,12 @@ class EditableDropdownTest extends SapphireTest $alternateDropdown->write(); $this->assertEquals($formField->getEmptyString(), ''); } + + public function testAllowEmptyTitle() + { + /** @var EditableDropdown $field */ + $field = EditableDropdown::create(); + $field->Name = 'EditableFormField_123456'; + $this->assertEmpty($field->getFormField()->Title()); + } } diff --git a/tests/Model/EditableFormField/EditableEmailFieldTest.php b/tests/Model/EditableFormField/EditableEmailFieldTest.php new file mode 100644 index 0000000..6d07ba3 --- /dev/null +++ b/tests/Model/EditableFormField/EditableEmailFieldTest.php @@ -0,0 +1,17 @@ +Name = 'EditableFormField_123456'; + $this->assertEmpty($field->getFormField()->Title()); + } +} diff --git a/tests/Model/EditableFormField/EditableFieldGroupTest.php b/tests/Model/EditableFormField/EditableFieldGroupTest.php new file mode 100644 index 0000000..03f932d --- /dev/null +++ b/tests/Model/EditableFormField/EditableFieldGroupTest.php @@ -0,0 +1,17 @@ +Name = 'EditableFormField_123456'; + $this->assertEmpty($field->getFormField()->Title()); + } +} diff --git a/tests/Model/EditableFormField/EditableFileFieldTest.php b/tests/Model/EditableFormField/EditableFileFieldTest.php index 16bae3e..12de5b9 100644 --- a/tests/Model/EditableFormField/EditableFileFieldTest.php +++ b/tests/Model/EditableFormField/EditableFileFieldTest.php @@ -64,4 +64,12 @@ class EditableFileFieldTest extends SapphireTest $formField = $fileField->getFormField(); $this->assertEquals($formField->getValidator()->getAllowedMaxFileSize(), 262144); } + + public function testAllowEmptyTitle() + { + /** @var EditableFileField $field */ + $field = EditableFileField::create(); + $field->Name = 'EditableFormField_123456'; + $this->assertEmpty($field->getFormField()->Title()); + } } diff --git a/tests/Model/EditableFormField/EditableFormHeadingTest.php b/tests/Model/EditableFormField/EditableFormHeadingTest.php new file mode 100644 index 0000000..2299422 --- /dev/null +++ b/tests/Model/EditableFormField/EditableFormHeadingTest.php @@ -0,0 +1,17 @@ +Name = 'EditableFormField_123456'; + $this->assertEmpty($field->getFormField()->Title()); + } +} diff --git a/tests/Model/EditableFormField/EditableFormStepTest.php b/tests/Model/EditableFormField/EditableFormStepTest.php new file mode 100644 index 0000000..13e16b7 --- /dev/null +++ b/tests/Model/EditableFormField/EditableFormStepTest.php @@ -0,0 +1,17 @@ +Name = 'EditableFormField_123456'; + $this->assertEmpty($field->getFormField()->Title()); + } +} diff --git a/tests/Model/EditableFormField/EditableLiteralFieldTest.php b/tests/Model/EditableFormField/EditableLiteralFieldTest.php index c12f77f..6d9e291 100644 --- a/tests/Model/EditableFormField/EditableLiteralFieldTest.php +++ b/tests/Model/EditableFormField/EditableLiteralFieldTest.php @@ -87,4 +87,12 @@ class EditableLiteralFieldTest extends SapphireTest 'Actual literal field exists in composite field children' ); } + + public function testAllowEmptyTitle() + { + /** @var EditableLiteralField $field */ + $field = EditableLiteralField::create(); + $field->Name = 'EditableFormField_123456'; + $this->assertEmpty($field->getFormField()->Title()); + } } diff --git a/tests/Model/EditableFormField/EditableMemberListFieldTest.php b/tests/Model/EditableFormField/EditableMemberListFieldTest.php new file mode 100644 index 0000000..c602e4a --- /dev/null +++ b/tests/Model/EditableFormField/EditableMemberListFieldTest.php @@ -0,0 +1,21 @@ +GroupID = $this->idFromFixture(Group::class, 'a_group'); + $field->Name = 'EditableFormField_123456'; + $this->assertEmpty($field->getFormField()->Title()); + } +} diff --git a/tests/Model/EditableFormField/EditableMemberListFieldTest.yml b/tests/Model/EditableFormField/EditableMemberListFieldTest.yml new file mode 100644 index 0000000..42b9821 --- /dev/null +++ b/tests/Model/EditableFormField/EditableMemberListFieldTest.yml @@ -0,0 +1,3 @@ +SilverStripe\Security\Group: + a_group: + Title: A security group diff --git a/tests/Model/EditableFormField/EditableNumericFieldTest.php b/tests/Model/EditableFormField/EditableNumericFieldTest.php new file mode 100644 index 0000000..9b7b8e9 --- /dev/null +++ b/tests/Model/EditableFormField/EditableNumericFieldTest.php @@ -0,0 +1,17 @@ +Name = 'EditableFormField_123456'; + $this->assertEmpty($field->getFormField()->Title()); + } +} diff --git a/tests/Model/EditableFormField/EditableRadioFieldTest.php b/tests/Model/EditableFormField/EditableRadioFieldTest.php index c1faefc..b82265f 100644 --- a/tests/Model/EditableFormField/EditableRadioFieldTest.php +++ b/tests/Model/EditableFormField/EditableRadioFieldTest.php @@ -3,8 +3,6 @@ namespace SilverStripe\UserForms\Tests\Model\EditableFormField; use SilverStripe\Dev\SapphireTest; -use SilverStripe\UserForms\FormField\UserFormsCheckboxSetField; -use SilverStripe\UserForms\Model\EditableFormField\EditableCheckboxGroupField; use SilverStripe\UserForms\Model\EditableFormField\EditableRadioField; class EditableRadioFieldTest extends SapphireTest @@ -22,4 +20,12 @@ class EditableRadioFieldTest extends SapphireTest $radio->getFormField()->getTemplate() ); } + + public function testAllowEmptyTitle() + { + /** @var EditableRadioField $field */ + $field = EditableRadioField::create(); + $field->Name = 'EditableFormField_123456'; + $this->assertEmpty($field->getFormField()->Title()); + } } diff --git a/tests/Model/EditableFormField/EditableTextFieldTest.php b/tests/Model/EditableFormField/EditableTextFieldTest.php index 1a994d5..9bd947b 100644 --- a/tests/Model/EditableFormField/EditableTextFieldTest.php +++ b/tests/Model/EditableFormField/EditableTextFieldTest.php @@ -20,4 +20,12 @@ class EditableTextFieldTest extends SapphireTest $this->assertInstanceOf(DropdownField::class, $autocompleteField); $this->assertEquals(['foo' => 'foo'], $autocompleteField->getSource()); } + + public function testAllowEmptyTitle() + { + /** @var EditableTextField $field */ + $field = EditableTextField::create(); + $field->Name = 'EditableFormField_123456'; + $this->assertEmpty($field->getFormField()->Title()); + } }