mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUGFIX: Fix the broken perform readonly transformation which was always showing NO (#6453)
This commit is contained in:
parent
fd649a418d
commit
dee3939cf7
@ -50,7 +50,7 @@ class CheckboxField extends FormField {
|
|||||||
* Returns a readonly version of this field
|
* Returns a readonly version of this field
|
||||||
*/
|
*/
|
||||||
function performReadonlyTransformation() {
|
function performReadonlyTransformation() {
|
||||||
$field = new CheckboxField_Readonly($this->name, $this->title, $this->value ? _t('CheckboxField.YES', 'Yes') : _t('CheckboxField.NO', 'No'));
|
$field = new CheckboxField_Readonly($this->name, $this->title, $this->value);
|
||||||
$field->setForm($this->form);
|
$field->setForm($this->form);
|
||||||
return $field;
|
return $field;
|
||||||
}
|
}
|
||||||
@ -73,9 +73,9 @@ class CheckboxField_Readonly extends ReadonlyField {
|
|||||||
function performReadonlyTransformation() {
|
function performReadonlyTransformation() {
|
||||||
return clone $this;
|
return clone $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setValue($val) {
|
function Value() {
|
||||||
$this->value = (int)($val) ? _t('CheckboxField.YES', 'Yes') : _t('CheckboxField.NO', 'No');
|
return Convert::raw2xml($this->value ? _t('CheckboxField.YES', 'Yes') : _t('CheckboxField.NO', 'No'));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -117,6 +117,23 @@ class CheckboxFieldTest extends SapphireTest {
|
|||||||
/* Delete the record we tested */
|
/* Delete the record we tested */
|
||||||
$article->delete();
|
$article->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testReadonlyCheckboxField() {
|
||||||
|
// Test 1: a checked checkbox goes to "Yes"
|
||||||
|
$field1 = new CheckboxField('IsChecked', 'Checked');
|
||||||
|
$field1->setValue('on');
|
||||||
|
$this->assertEquals(_t('CheckboxField.YES', 'Yes'), trim(strip_tags($field1->performReadonlyTransformation()->Field())));
|
||||||
|
|
||||||
|
// Test 2: an checkbox with the value set to false to "No"
|
||||||
|
$field2 = new CheckboxField('IsChecked', 'Checked');
|
||||||
|
$field2->setValue(false);
|
||||||
|
$this->assertEquals(_t('CheckboxField.NO', 'No'), trim(strip_tags($field2->performReadonlyTransformation()->Field())));
|
||||||
|
|
||||||
|
// Test 3: an checkbox with no value ever set goes to "No"
|
||||||
|
$field3 = new CheckboxField('IsChecked', 'Checked');
|
||||||
|
$this->assertEquals(_t('CheckboxField.NO', 'No'), trim(strip_tags($field3->performReadonlyTransformation()->Field())));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
class CheckboxFieldTest_Article extends DataObject implements TestOnly {
|
class CheckboxFieldTest_Article extends DataObject implements TestOnly {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user