From 6db1ac9a7239db9e9fa0964da41bc71df7171360 Mon Sep 17 00:00:00 2001 From: UndefinedOffset Date: Mon, 23 Jan 2023 12:19:53 -0400 Subject: [PATCH] Added test for checking summary fields in subclasses of UserDefinedForm --- tests/php/Model/SubClassFormTest.php | 53 +++++++++++++++++++ tests/php/Model/SubClassFormTest.yml | 17 ++++++ .../Model/SubClassFormTest/SubClassForm.php | 11 ++++ 3 files changed, 81 insertions(+) create mode 100644 tests/php/Model/SubClassFormTest.php create mode 100644 tests/php/Model/SubClassFormTest.yml create mode 100644 tests/php/Model/SubClassFormTest/SubClassForm.php diff --git a/tests/php/Model/SubClassFormTest.php b/tests/php/Model/SubClassFormTest.php new file mode 100644 index 0000000..3007310 --- /dev/null +++ b/tests/php/Model/SubClassFormTest.php @@ -0,0 +1,53 @@ + [UserFormFieldEditorExtension::class], + ]; + + protected static $extra_dataobjects = [ + SubClassForm::class, + ]; + + protected function setUp(): void + { + parent::setUp(); + Email::config()->update('admin_email', 'no-reply@example.com'); + } + + public function testGetCMSFieldsShowInSummary() + { + $this->logInWithPermission('ADMIN'); + $form = $this->objFromFixture(SubClassForm::class, 'summary-rules-form'); + + $fields = $form->getCMSFields(); + + $this->assertInstanceOf(GridField::class, $fields->dataFieldByName('Submissions')); + + $submissionsgrid = $fields->dataFieldByName('Submissions'); + $gridFieldDataColumns = $submissionsgrid->getConfig()->getComponentByType(GridFieldDataColumns::class); + + $summaryFields = $gridFieldDataColumns->getDisplayFields($submissionsgrid); + + $this->assertContains('SummaryShow', array_keys($summaryFields ?? []), 'Summary field not showing displayed field'); + $this->assertNotContains('SummaryHide', array_keys($summaryFields ?? []), 'Summary field showing displayed field'); + } +} diff --git a/tests/php/Model/SubClassFormTest.yml b/tests/php/Model/SubClassFormTest.yml new file mode 100644 index 0000000..3cfbd9e --- /dev/null +++ b/tests/php/Model/SubClassFormTest.yml @@ -0,0 +1,17 @@ +SilverStripe\UserForms\Model\EditableFormField\EditableTextField: + summary-show: + Name: SummaryShow + Title: Summary Text Field + ShowInSummary: true + + summary-hide: + Name: SummaryHide + Title: Summary Text Field + ShowInSummary: false + +SilverStripe\UserForms\Tests\Model\SubClassFormTest\SubClassForm: + summary-rules-form: + Title: Summary Fields Form + Fields: + - =>SilverStripe\UserForms\Model\EditableFormField\EditableTextField.summary-show + - =>SilverStripe\UserForms\Model\EditableFormField\EditableTextField.summary-hide diff --git a/tests/php/Model/SubClassFormTest/SubClassForm.php b/tests/php/Model/SubClassFormTest/SubClassForm.php new file mode 100644 index 0000000..6c9034c --- /dev/null +++ b/tests/php/Model/SubClassFormTest/SubClassForm.php @@ -0,0 +1,11 @@ +