Merge branch '4.7' into 4.8

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

View File

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

View File

@ -266,4 +266,33 @@ class TreeDropdownFieldTest extends SapphireTest
$field->getSchemaStateDefaults(); $field->getSchemaStateDefaults();
$this->assertTrue(true); $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'
);
}
} }