mirror of
https://github.com/silverstripe/silverstripe-frameworktest
synced 2024-10-22 09:06:02 +00:00
More consistent field loading, using loadDataFrom() in react test admin
This commit is contained in:
parent
7137b456cf
commit
3eb6295f76
@ -43,6 +43,10 @@ class BasicFieldsTestPage extends TestPage
|
|||||||
'MyFieldGroup2' => 'Varchar',
|
'MyFieldGroup2' => 'Varchar',
|
||||||
'MyFieldGroup3' => 'Varchar',
|
'MyFieldGroup3' => 'Varchar',
|
||||||
'MyFieldGroupCheckbox' => 'Boolean',
|
'MyFieldGroupCheckbox' => 'Boolean',
|
||||||
|
'MyLabelledFieldGroup1' => 'Varchar',
|
||||||
|
'MyLabelledFieldGroup2' => 'Varchar',
|
||||||
|
'MyLabelledFieldGroup3' => 'Int',
|
||||||
|
'MyLabelledFieldGroupCheckbox' => 'Boolean',
|
||||||
'Number' => 'Int',
|
'Number' => 'Int',
|
||||||
'OptionSet' => 'Varchar',
|
'OptionSet' => 'Varchar',
|
||||||
'Password' => 'Varchar',
|
'Password' => 'Varchar',
|
||||||
@ -55,6 +59,8 @@ class BasicFieldsTestPage extends TestPage
|
|||||||
'Required' => 'Varchar',
|
'Required' => 'Varchar',
|
||||||
'Readonly' => 'Varchar',
|
'Readonly' => 'Varchar',
|
||||||
'Time' => 'Time',
|
'Time' => 'Time',
|
||||||
|
'ToggleCompositeTextField1' => 'Varchar',
|
||||||
|
'ToggleCompositeDropdownField' => 'Varchar',
|
||||||
'Validated' => 'Text',
|
'Validated' => 'Text',
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -87,6 +93,14 @@ class BasicFieldsTestPage extends TestPage
|
|||||||
$data = $this->getDefaultData();
|
$data = $this->getDefaultData();
|
||||||
$inst->update($data);
|
$inst->update($data);
|
||||||
$inst->write();
|
$inst->write();
|
||||||
|
|
||||||
|
TestCategory::create()->requireDefaultRecords();
|
||||||
|
$cats = TestCategory::get();
|
||||||
|
$firstCat = $cats->offsetGet(0);
|
||||||
|
$thirdCat = $cats->offsetGet(2);
|
||||||
|
$inst->MultipleListboxField()->add($firstCat);
|
||||||
|
$inst->MultipleListboxField()->add($thirdCat);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,7 +130,7 @@ class BasicFieldsTestPage extends TestPage
|
|||||||
'HTMLField' => 'My <strong>value</strong> (ä!)',
|
'HTMLField' => 'My <strong>value</strong> (ä!)',
|
||||||
'MoneyAmount' => 99.99,
|
'MoneyAmount' => 99.99,
|
||||||
'MoneyCurrency' => 'EUR',
|
'MoneyCurrency' => 'EUR',
|
||||||
'MultipleListboxFieldID' => join(',', array($thirdCat->ID, $firstCat->ID)),
|
// 'MultipleListboxFieldID' => null,
|
||||||
'MyCompositeField1' => 'My value (ä!)',
|
'MyCompositeField1' => 'My value (ä!)',
|
||||||
'MyCompositeField2' => 'My value (ä!)',
|
'MyCompositeField2' => 'My value (ä!)',
|
||||||
'MyCompositeField3' => 'My value (ä!)',
|
'MyCompositeField3' => 'My value (ä!)',
|
||||||
@ -125,6 +139,10 @@ class BasicFieldsTestPage extends TestPage
|
|||||||
'MyFieldGroup2' => 'My value (ä!)',
|
'MyFieldGroup2' => 'My value (ä!)',
|
||||||
'MyFieldGroup3' => 'My value (ä!)',
|
'MyFieldGroup3' => 'My value (ä!)',
|
||||||
'MyFieldGroupCheckbox' => true,
|
'MyFieldGroupCheckbox' => true,
|
||||||
|
'MyLabelledFieldGroup1' => 'My value (ä!)',
|
||||||
|
'MyLabelledFieldGroup2' => 'My value (ä!)',
|
||||||
|
'MyLabelledFieldGroup3' => 2,
|
||||||
|
'MyLabelledFieldGroupCheckbox' => true,
|
||||||
'Number' => 99,
|
'Number' => 99,
|
||||||
'OptionSet' => join(',', array($thirdCat->ID, $firstCat->ID)),
|
'OptionSet' => join(',', array($thirdCat->ID, $firstCat->ID)),
|
||||||
'Password' => 'My value (ä!)',
|
'Password' => 'My value (ä!)',
|
||||||
@ -135,6 +153,7 @@ class BasicFieldsTestPage extends TestPage
|
|||||||
'Text' => 'My value (ä!)',
|
'Text' => 'My value (ä!)',
|
||||||
'Textarea' => 'My value (ä!)',
|
'Textarea' => 'My value (ä!)',
|
||||||
'Time' => "23:59",
|
'Time' => "23:59",
|
||||||
|
'ToggleCompositeTextField1' => 'My value (ä!)',
|
||||||
'Validated' => '1',
|
'Validated' => '1',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -170,13 +189,13 @@ class BasicFieldsTestPage extends TestPage
|
|||||||
|
|
||||||
$fields->addFieldsToTab('Root.Option', array(
|
$fields->addFieldsToTab('Root.Option', array(
|
||||||
Object::create('SilverStripe\\Forms\\CheckboxField', 'Checkbox'),
|
Object::create('SilverStripe\\Forms\\CheckboxField', 'Checkbox'),
|
||||||
Object::create('SilverStripe\\Forms\\CheckboxSetField', 'CheckboxSet', 'CheckboxSet', TestCategory::map()),
|
Object::create('SilverStripe\\Forms\\CheckboxSetField', 'CheckboxSetID', 'CheckboxSet', TestCategory::map()),
|
||||||
Object::create('SilverStripe\\Forms\\DropdownField', 'DropdownID', 'DropdownField', TestCategory::map())
|
Object::create('SilverStripe\\Forms\\DropdownField', 'DropdownID', 'DropdownField', TestCategory::map())
|
||||||
->setHasEmptyDefault(true),
|
->setHasEmptyDefault(true),
|
||||||
Object::create('SilverStripe\\Forms\\GroupedDropdownField', 'GroupedDropdownID',
|
Object::create('SilverStripe\\Forms\\GroupedDropdownField', 'GroupedDropdownID',
|
||||||
'GroupedDropdown', array('Test Categories' => TestCategory::map())
|
'GroupedDropdown', array('Test Categories' => TestCategory::map())
|
||||||
),
|
),
|
||||||
Object::create('SilverStripe\\Forms\\ListboxField', 'MultipleListboxFieldID', 'ListboxField (multiple)', TestCategory::map())
|
Object::create('SilverStripe\\Forms\\ListboxField', 'MultipleListboxField', 'ListboxField (multiple)', TestCategory::map())
|
||||||
->setSize(3),
|
->setSize(3),
|
||||||
Object::create('SilverStripe\\Forms\\OptionsetField', 'OptionSet', 'OptionSetField', TestCategory::map()),
|
Object::create('SilverStripe\\Forms\\OptionsetField', 'OptionSet', 'OptionSetField', TestCategory::map()),
|
||||||
Object::create('SilverStripe\\Forms\\SelectionGroup', 'SelectionGroup', array(
|
Object::create('SilverStripe\\Forms\\SelectionGroup', 'SelectionGroup', array(
|
||||||
@ -193,9 +212,7 @@ class BasicFieldsTestPage extends TestPage
|
|||||||
)),
|
)),
|
||||||
Object::create('SilverStripe\\Forms\\ToggleCompositeField', 'ToggleCompositeField', 'ToggleCompositeField', new FieldList(
|
Object::create('SilverStripe\\Forms\\ToggleCompositeField', 'ToggleCompositeField', 'ToggleCompositeField', new FieldList(
|
||||||
Object::create('SilverStripe\\Forms\\TextField', 'ToggleCompositeTextField1'),
|
Object::create('SilverStripe\\Forms\\TextField', 'ToggleCompositeTextField1'),
|
||||||
Object::create('SilverStripe\\Forms\\TextField', 'ToggleCompositeTextField2'),
|
Object::create('SilverStripe\\Forms\\DropdownField', 'ToggleCompositeDropdownField', 'ToggleCompositeDropdownField', TestCategory::map())
|
||||||
Object::create('SilverStripe\\Forms\\DropdownField', 'ToggleCompositeDropdownField', 'ToggleCompositeDropdownField', TestCategory::map()),
|
|
||||||
Object::create('SilverStripe\\Forms\\TextField', 'ToggleCompositeTextField3')
|
|
||||||
))
|
))
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -236,14 +253,6 @@ class BasicFieldsTestPage extends TestPage
|
|||||||
->setRightTitle($rightTitle),
|
->setRightTitle($rightTitle),
|
||||||
));
|
));
|
||||||
|
|
||||||
$data = $this->getDefaultData();
|
|
||||||
foreach ($fields->dataFields() as $field) {
|
|
||||||
$name = $field->getName();
|
|
||||||
if (isset($data[$name])) {
|
|
||||||
$field->setValue($data[$name]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$blacklist = array(
|
$blacklist = array(
|
||||||
'DMYDate', 'Required', 'Validated', 'ToggleCompositeField', 'SelectionGroup'
|
'DMYDate', 'Required', 'Validated', 'ToggleCompositeField', 'SelectionGroup'
|
||||||
);
|
);
|
||||||
@ -264,13 +273,13 @@ class BasicFieldsTestPage extends TestPage
|
|||||||
$disabledField = $field->performDisabledTransformation();
|
$disabledField = $field->performDisabledTransformation();
|
||||||
$disabledField->setTitle($disabledField->Title() . ' (disabled)');
|
$disabledField->setTitle($disabledField->Title() . ' (disabled)');
|
||||||
$disabledField->setName($disabledField->getName() . '_disabled');
|
$disabledField->setName($disabledField->getName() . '_disabled');
|
||||||
$disabledField->setValue($field->Value());
|
$disabledField->setValue($this->getField($field->getName()));
|
||||||
$tabObj->insertAfter($disabledField, $field->getName());
|
$tabObj->insertAfter($disabledField, $field->getName());
|
||||||
|
|
||||||
$readonlyField = $field->performReadonlyTransformation();
|
$readonlyField = $field->performReadonlyTransformation();
|
||||||
$readonlyField->setTitle($readonlyField->Title() . ' (readonly)');
|
$readonlyField->setTitle($readonlyField->Title() . ' (readonly)');
|
||||||
$readonlyField->setName($readonlyField->getName() . '_readonly');
|
$readonlyField->setName($readonlyField->getName() . '_readonly');
|
||||||
$readonlyField->setValue($field->Value());
|
$readonlyField->setValue($this->getField($field->getName()));
|
||||||
$tabObj->insertAfter($readonlyField, $field->getName());
|
$tabObj->insertAfter($readonlyField, $field->getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,9 +24,10 @@ class TestReactFormBuilder extends LeftAndMain
|
|||||||
}
|
}
|
||||||
public function getTestEditForm($id = null) {
|
public function getTestEditForm($id = null) {
|
||||||
/* @var $page BasicFieldsTestPage */
|
/* @var $page BasicFieldsTestPage */
|
||||||
$page = BasicFieldsTestPage::create();
|
$page = BasicFieldsTestPage::get()->First();
|
||||||
|
|
||||||
$form = Form::create($this, 'TestEditForm', $page->getCMSFields(), FieldList::create([]));
|
$form = Form::create($this, 'TestEditForm', $page->getCMSFields(), FieldList::create([]));
|
||||||
|
$form->loadDataFrom($page);
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user