- Added calls to Object#extend in EditableFormField's getFieldConfiguration and getFieldValidationOptions

- Added tests for extensions on EditableFormField
This commit is contained in:
Nik Rolls 2013-12-05 07:06:34 +13:00 committed by Nik
parent 79682e7627
commit da6a624b6c
3 changed files with 89 additions and 6 deletions

View File

@ -415,11 +415,14 @@ class EditableFormField extends DataObject {
_t('EditableFormField.RIGHTTITLE', 'Right Title'),
$this->getSetting('RightTitle')
);
return new FieldList(
$ec,
$right
);
$fields = FieldList::create(
$ec,
$right
);
$this->extend('updateFieldConfiguration', $fields);
return $fields;
}
/**
@ -439,6 +442,8 @@ class EditableFormField extends DataObject {
$field->performReadonlyTransformation();
}
}
$this->extend('updateFieldValidationOptions', $fields);
return $fields;
}

View File

@ -7,6 +7,11 @@
class EditableFormFieldTest extends FunctionalTest {
static $fixture_file = 'userforms/tests/UserDefinedFormTest.yml';
protected $extraDataObjects = array(
'ExtendedEditableFormField',
'EditableFormFieldExtension'
);
function testFormFieldPermissions() {
$text = $this->objFromFixture('EditableTextField', 'basic-text');
@ -301,4 +306,70 @@ class EditableFormFieldTest extends FunctionalTest {
// $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)
));
}
}

View File

@ -103,6 +103,14 @@ EditableRadioField:
Options: =>EditableOption.option-5, =>EditableOption.option-6
ExtendedEditableFormField:
extended-field:
Name: extended-field
Title: Extended Field
TestExtraField: Extra Field
TestValidationField: Extra Validation Field
UserDefinedForm:
basic-form-page:
Title: User Defined Form
@ -125,4 +133,3 @@ UserDefinedForm:
Title: Empty Form