Added test for checking summary fields in subclasses of UserDefinedForm

This commit is contained in:
UndefinedOffset 2023-01-23 12:19:53 -04:00
parent 9536799145
commit 6db1ac9a72
No known key found for this signature in database
GPG Key ID: 59C4EE2B6468B796
3 changed files with 81 additions and 0 deletions

View File

@ -0,0 +1,53 @@
<?php
namespace SilverStripe\UserForms\Tests\Model;
use SilverStripe\Control\Email\Email;
use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldDataColumns;
use SilverStripe\UserForms\Extension\UserFormFieldEditorExtension;
use SilverStripe\UserForms\Model\UserDefinedForm;
use SilverStripe\UserForms\Tests\Model\SubClassFormTest\SubClassForm;
/**
* @package userforms
*/
class SubClassFormTest extends FunctionalTest
{
protected $usesTransactions = false;
protected static $fixture_file = 'SubClassFormTest.yml';
protected static $required_extensions = [
UserDefinedForm::class => [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');
}
}

View File

@ -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

View File

@ -0,0 +1,11 @@
<?php
namespace SilverStripe\UserForms\Tests\Model\SubClassFormTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\UserForms\Model\UserDefinedForm;
class SubClassForm extends UserDefinedForm implements TestOnly
{
private static $table_name = 'SubClassForm';
}