Merge branch '4.6' into 4.7

This commit is contained in:
Steve Boyd 2021-05-03 14:21:20 +12:00
commit e6aeff6468
2 changed files with 30 additions and 0 deletions

View File

@ -904,6 +904,7 @@ class TreeDropdownField extends FormField
$data['data'] = array_merge($data['data'], [
'urlTree' => $this->Link('tree'),
'showSearch' => $this->getShowSearch(),
'treeBaseId' => $this->getTreeBaseID(),
'emptyString' => $this->getEmptyString(),
'hasEmptyDefault' => $this->getHasEmptyDefault(),
'multiple' => false,

View File

@ -266,4 +266,33 @@ class TreeDropdownFieldTest extends SapphireTest
$field->getSchemaStateDefaults();
$this->assertTrue(true);
}
public function testTreeBaseID()
{
$treeBaseID = $this->idFromFixture(Folder::class, 'folder1');
$field = new TreeDropdownField('TestTree', 'Test tree', Folder::class);
// getSchemaDataDefaults needs the field to be attach to a form
new Form(
null,
'mock',
new FieldList($field)
);
$this->assertEmpty($field->getTreeBaseID(), 'TreeBaseId does not have an initial value');
$field->setTreeBaseID($treeBaseID);
$this->assertEquals(
$treeBaseID,
$field->getTreeBaseID(),
'Value passed to setTreeBaseID is returned by getTreeBaseID'
);
$schema = $field->getSchemaDataDefaults();
$this->assertEquals(
$treeBaseID,
$schema['data']['treeBaseId'],
'TreeBaseId is included in the default schema data'
);
}
}