mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
Add tests for duplicating multiple option fields, which should duplicate the options too
This commit is contained in:
parent
8c4363d429
commit
3e71cf7840
@ -126,6 +126,7 @@ class EditableMultipleOptionField extends EditableFormField
|
|||||||
$clonedNode = parent::duplicate($doWrite, $manyMany);
|
$clonedNode = parent::duplicate($doWrite, $manyMany);
|
||||||
|
|
||||||
foreach ($this->Options() as $field) {
|
foreach ($this->Options() as $field) {
|
||||||
|
/** @var EditableOption $newField */
|
||||||
$newField = $field->duplicate(false);
|
$newField = $field->duplicate(false);
|
||||||
$newField->ParentID = $clonedNode->ID;
|
$newField->ParentID = $clonedNode->ID;
|
||||||
$newField->Version = 0;
|
$newField->Version = 0;
|
||||||
|
@ -44,4 +44,14 @@ class EditableDropdownTest extends SapphireTest
|
|||||||
$field->Name = 'EditableFormField_123456';
|
$field->Name = 'EditableFormField_123456';
|
||||||
$this->assertEmpty($field->getFormField()->Title());
|
$this->assertEmpty($field->getFormField()->Title());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDuplicate()
|
||||||
|
{
|
||||||
|
/** @var EditableDropdown $dropdown */
|
||||||
|
$dropdown = $this->objFromFixture(EditableDropdown::class, 'basic-dropdown');
|
||||||
|
$this->assertCount(2, $dropdown->Options());
|
||||||
|
|
||||||
|
$duplicatedDropdown = $dropdown->duplicate();
|
||||||
|
$this->assertSame($dropdown->Options()->count(), $duplicatedDropdown->Options()->count());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -375,6 +375,32 @@ class UserDefinedFormTest extends FunctionalTest
|
|||||||
$this->assertNotEquals($form2GroupEnd->ID, $form3GroupStart->EndID);
|
$this->assertNotEquals($form2GroupEnd->ID, $form3GroupStart->EndID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDuplicateFormDuplicatesRecursively()
|
||||||
|
{
|
||||||
|
$this->logInWithPermission('ADMIN');
|
||||||
|
/** @var UserDefinedForm $form */
|
||||||
|
$form = $this->objFromFixture(UserDefinedForm::class, 'form-with-multioptions');
|
||||||
|
|
||||||
|
$this->assertCount(2, $form->Fields(), 'Fixtured page has one field plus one form step');
|
||||||
|
$this->assertCount(
|
||||||
|
2,
|
||||||
|
$form->Fields()->Last()->Options(),
|
||||||
|
'Fixtured multiple option field has two options'
|
||||||
|
);
|
||||||
|
|
||||||
|
$newForm = $form->duplicate();
|
||||||
|
$this->assertEquals(
|
||||||
|
$form->Fields()->count(),
|
||||||
|
$newForm->Fields()->count(),
|
||||||
|
'Duplicated page has same number of fields'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$form->Fields()->Last()->Options()->count(),
|
||||||
|
$newForm->Fields()->Last()->Options()->count(),
|
||||||
|
'Duplicated dropdown field from duplicated form has duplicated options'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function testFormOptions()
|
public function testFormOptions()
|
||||||
{
|
{
|
||||||
$this->logInWithPermission('ADMIN');
|
$this->logInWithPermission('ADMIN');
|
||||||
|
@ -344,3 +344,8 @@ SilverStripe\UserForms\Model\UserDefinedForm:
|
|||||||
Fields:
|
Fields:
|
||||||
- =>SilverStripe\UserForms\Model\EditableFormField\EditableEmailField.another-email-field
|
- =>SilverStripe\UserForms\Model\EditableFormField\EditableEmailField.another-email-field
|
||||||
- =>SilverStripe\UserForms\Model\EditableFormField\EditableTextField.another-required
|
- =>SilverStripe\UserForms\Model\EditableFormField\EditableTextField.another-required
|
||||||
|
|
||||||
|
form-with-multioptions:
|
||||||
|
Title: Form with MultipleOption fields
|
||||||
|
Fields:
|
||||||
|
- =>SilverStripe\UserForms\Model\EditableFormField\EditableDropdown.basic-dropdown
|
||||||
|
Loading…
Reference in New Issue
Block a user