mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #2556 from tractorcow/pulls/3.1-bug-fieldgroup-name-fix
BUG Fixes serious issue with FieldList::addFieldsToTab failing to accept multiple field groups.
This commit is contained in:
commit
15845c8547
@ -130,7 +130,7 @@ class FieldList extends ArrayList {
|
||||
// Check if a field by the same name exists in this tab
|
||||
if($insertBefore) {
|
||||
$tab->insertBefore($field, $insertBefore);
|
||||
} elseif($tab->fieldByName($field->getName())) {
|
||||
} elseif(($name = $field->getName()) && $tab->fieldByName($name)) {
|
||||
// It exists, so we need to replace the old one
|
||||
$this->replaceField($field->getName(), $field);
|
||||
} else {
|
||||
|
@ -49,6 +49,43 @@ class FieldListTest extends SapphireTest {
|
||||
$this->assertEquals(3, $tab->Fields()->Count());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that groups can be added to a fieldlist
|
||||
*/
|
||||
public function testFieldgroup() {
|
||||
$fields = new FieldList();
|
||||
$tab = new Tab('Root');
|
||||
$fields->push($tab);
|
||||
|
||||
$fields->addFieldsToTab('Root', array(
|
||||
$group1 = new FieldGroup(
|
||||
new TextField('Name'),
|
||||
new EmailField('Email')
|
||||
),
|
||||
$group2 = new FieldGroup(
|
||||
new TextField('Company'),
|
||||
new TextareaField('Address')
|
||||
)
|
||||
));
|
||||
|
||||
/* Check that the field objects were created */
|
||||
$this->assertNotNull($fields->dataFieldByName('Name'));
|
||||
$this->assertNotNull($fields->dataFieldByName('Email'));
|
||||
$this->assertNotNull($fields->dataFieldByName('Company'));
|
||||
$this->assertNotNull($fields->dataFieldByName('Address'));
|
||||
|
||||
/* The field objects in the set should be the same as the ones we created */
|
||||
$this->assertSame($fields->dataFieldByName('Name'), $group1->fieldByName('Name'));
|
||||
$this->assertSame($fields->dataFieldByName('Email'), $group1->fieldByName('Email'));
|
||||
$this->assertSame($fields->dataFieldByName('Company'), $group2->fieldByName('Company'));
|
||||
$this->assertSame($fields->dataFieldByName('Address'), $group2->fieldByName('Address'));
|
||||
|
||||
/* We'll have 2 fields directly inside the tab */
|
||||
$this->assertEquals(2, $tab->Fields()->Count());
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test removing a single field from a tab in a set.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user