FIX Alias object context in closure for PHP 5.3 compat, add test to cover it

This commit is contained in:
Robbie Averill 2017-08-16 13:59:41 +12:00
parent 51c62c4a90
commit fac99f7b6b
2 changed files with 22 additions and 2 deletions

View File

@ -61,7 +61,10 @@ class EditableTextField extends EditableFormField
public function getCMSFields()
{
$this->beforeUpdateCMSFields(function ($fields) {
// PHP 5.3 compat
$self = $this;
$this->beforeUpdateCMSFields(function ($fields) use ($self) {
$fields->addFieldToTab(
'Root.Main',
NumericField::create(
@ -78,7 +81,7 @@ class EditableTextField extends EditableFormField
DropdownField::create(
'Autocomplete',
_t('EditableTextField.AUTOCOMPLETE', 'Autocomplete'),
$this->config()->get('autocomplete_options')
$self->config()->get('autocomplete_options')
)->setDescription(_t(
'EditableTextField.AUTOCOMPLETE_DESCRIPTION',
'Supported browsers will attempt to populate this field automatically with the users information, use to set the value populated'

View File

@ -0,0 +1,17 @@
<?php
class EditableTextFieldTest extends SapphireTest
{
public function testGetCmsFields()
{
Config::inst()->remove('EditableTextField', 'autocomplete_options');
Config::inst()->update('EditableTextField', 'autocomplete_options', array('foo' => 'foo'));
$field = new EditableTextField;
$result = $field->getCMSFields();
$autocompleteField = $result->fieldByName('Root.Main.Autocomplete');
$this->assertInstanceOf('DropdownField', $autocompleteField);
$this->assertEquals(array('foo' => 'foo'), $autocompleteField->getSource());
}
}