mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
Added test for checking summary fields in subclasses of UserDefinedForm
This commit is contained in:
parent
9536799145
commit
6db1ac9a72
53
tests/php/Model/SubClassFormTest.php
Normal file
53
tests/php/Model/SubClassFormTest.php
Normal 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');
|
||||
}
|
||||
}
|
17
tests/php/Model/SubClassFormTest.yml
Normal file
17
tests/php/Model/SubClassFormTest.yml
Normal 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
|
11
tests/php/Model/SubClassFormTest/SubClassForm.php
Normal file
11
tests/php/Model/SubClassFormTest/SubClassForm.php
Normal 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';
|
||||
}
|
Loading…
Reference in New Issue
Block a user