mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
- Added calls to Object#extend in EditableFormField's getFieldConfiguration and getFieldValidationOptions
- Added tests for extensions on EditableFormField
This commit is contained in:
parent
79682e7627
commit
da6a624b6c
@ -416,10 +416,13 @@ class EditableFormField extends DataObject {
|
|||||||
$this->getSetting('RightTitle')
|
$this->getSetting('RightTitle')
|
||||||
);
|
);
|
||||||
|
|
||||||
return new FieldList(
|
$fields = FieldList::create(
|
||||||
$ec,
|
$ec,
|
||||||
$right
|
$right
|
||||||
);
|
);
|
||||||
|
$this->extend('updateFieldConfiguration', $fields);
|
||||||
|
|
||||||
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -440,6 +443,8 @@ class EditableFormField extends DataObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->extend('updateFieldValidationOptions', $fields);
|
||||||
|
|
||||||
return $fields;
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,11 @@ class EditableFormFieldTest extends FunctionalTest {
|
|||||||
|
|
||||||
static $fixture_file = 'userforms/tests/UserDefinedFormTest.yml';
|
static $fixture_file = 'userforms/tests/UserDefinedFormTest.yml';
|
||||||
|
|
||||||
|
protected $extraDataObjects = array(
|
||||||
|
'ExtendedEditableFormField',
|
||||||
|
'EditableFormFieldExtension'
|
||||||
|
);
|
||||||
|
|
||||||
function testFormFieldPermissions() {
|
function testFormFieldPermissions() {
|
||||||
$text = $this->objFromFixture('EditableTextField', 'basic-text');
|
$text = $this->objFromFixture('EditableTextField', 'basic-text');
|
||||||
|
|
||||||
@ -301,4 +306,70 @@ class EditableFormFieldTest extends FunctionalTest {
|
|||||||
// $configuration = $text->getFieldConfiguration();
|
// $configuration = $text->getFieldConfiguration();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testExtendedEditableFormField() {
|
||||||
|
/** @var ExtendedEditableFormField $field */
|
||||||
|
$field = $this->objFromFixture('ExtendedEditableFormField', 'extended-field');
|
||||||
|
|
||||||
|
// Check db fields
|
||||||
|
$dbFields = $field->stat('db');
|
||||||
|
$this->assertTrue(array_key_exists('TestExtraField', $dbFields));
|
||||||
|
$this->assertTrue(array_key_exists('TestValidationField', $dbFields));
|
||||||
|
|
||||||
|
// Check Field Configuration
|
||||||
|
$fieldConfiguration = $field->getFieldConfiguration();
|
||||||
|
$extraField = $fieldConfiguration->dataFieldByName($field->getSettingName('TestExtraField'));
|
||||||
|
$this->assertNotNull($extraField);
|
||||||
|
|
||||||
|
// Check Validation Fields
|
||||||
|
$fieldValidation = $field->getFieldValidationOptions();
|
||||||
|
$validationField = $fieldValidation->dataFieldByName($field->getSettingName('TestValidationField'));
|
||||||
|
$this->assertNotNull($validationField);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ExtendedEditableFormField
|
||||||
|
* A base EditableFormFieldClass that will be extended with {@link EditableFormFieldExtension}
|
||||||
|
* @mixin EditableFormFieldExtension
|
||||||
|
*/
|
||||||
|
class ExtendedEditableFormField extends EditableFormField implements TestOnly
|
||||||
|
{
|
||||||
|
private static $extensions = array(
|
||||||
|
'EditableFormFieldExtension'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class EditableFormFieldExtension
|
||||||
|
* Used for testing extensions to EditableFormField and the extended Fields methods
|
||||||
|
* @property EditableFormField owner
|
||||||
|
*/
|
||||||
|
class EditableFormFieldExtension extends DataExtension implements TestOnly
|
||||||
|
{
|
||||||
|
private static $db = array(
|
||||||
|
'TestExtraField' => 'Varchar',
|
||||||
|
'TestValidationField' => 'Boolean'
|
||||||
|
);
|
||||||
|
|
||||||
|
public function updateFieldConfiguration(FieldList $fields)
|
||||||
|
{
|
||||||
|
$extraField = 'TestExtraField';
|
||||||
|
$fields->push(TextField::create(
|
||||||
|
$this->owner->getSettingName($extraField),
|
||||||
|
'Test extra field',
|
||||||
|
$this->owner->getSetting($extraField)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateFieldValidationOptions(FieldList $fields)
|
||||||
|
{
|
||||||
|
$extraField = 'TestValidationField';
|
||||||
|
$fields->push(CheckboxField::create(
|
||||||
|
$this->owner->getSettingName($extraField),
|
||||||
|
'Test validation field',
|
||||||
|
$this->owner->getSetting($extraField)
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,6 +103,14 @@ EditableRadioField:
|
|||||||
Options: =>EditableOption.option-5, =>EditableOption.option-6
|
Options: =>EditableOption.option-5, =>EditableOption.option-6
|
||||||
|
|
||||||
|
|
||||||
|
ExtendedEditableFormField:
|
||||||
|
extended-field:
|
||||||
|
Name: extended-field
|
||||||
|
Title: Extended Field
|
||||||
|
TestExtraField: Extra Field
|
||||||
|
TestValidationField: Extra Validation Field
|
||||||
|
|
||||||
|
|
||||||
UserDefinedForm:
|
UserDefinedForm:
|
||||||
basic-form-page:
|
basic-form-page:
|
||||||
Title: User Defined Form
|
Title: User Defined Form
|
||||||
@ -125,4 +133,3 @@ UserDefinedForm:
|
|||||||
Title: Empty Form
|
Title: Empty Form
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user