mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUGFIX Ensure that CheckboxField always returns 1 from the form request data instead of "on" - this was because the value attribute didn't exist on the <input> tag
MINOR Added tests for checking saveInto() behaviour on CheckboxFieldTest git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@75049 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
c272082448
commit
bc443b109a
@ -26,6 +26,7 @@ class CheckboxField extends FormField {
|
||||
'class' => ($this->extraClass() ? $this->extraClass() : ''),
|
||||
'id' => $this->id(),
|
||||
'name' => $this->Name(),
|
||||
'value' => 1,
|
||||
'checked' => $this->value ? 'checked' : '',
|
||||
'tabindex' => $this->getTabIndex()
|
||||
);
|
||||
|
@ -64,5 +64,60 @@ class CheckboxFieldTest extends SapphireTest {
|
||||
$this->assertEquals($field->Value(), 0, 'Value() returns a 0');
|
||||
}
|
||||
|
||||
function testSavingChecked() {
|
||||
/* Create a new test data record */
|
||||
$article = new CheckboxFieldTest_Article();
|
||||
|
||||
/* Create a field, with a value of 1 */
|
||||
$field = new CheckboxField('IsChecked', 'Checked', 1);
|
||||
|
||||
/* Save the field into our Article object */
|
||||
$field->saveInto($article);
|
||||
|
||||
/* Write the record to the test database */
|
||||
$article->write();
|
||||
|
||||
/* Check that IsChecked column contains a 1 */
|
||||
$this->assertEquals(
|
||||
DB::query("SELECT IsChecked FROM CheckboxFieldTest_Article")->value(),
|
||||
1,
|
||||
'We have a 1 set in the database, because the field saved into as a 1'
|
||||
);
|
||||
|
||||
/* Delete the record we tested */
|
||||
$article->delete();
|
||||
}
|
||||
|
||||
function testSavingUnchecked() {
|
||||
/* Create a new test data record */
|
||||
$article = new CheckboxFieldTest_Article();
|
||||
|
||||
/* Create a field, with no value */
|
||||
$field = new CheckboxField('IsChecked', 'Checked');
|
||||
|
||||
/* Save the field into our Article object */
|
||||
$field->saveInto($article);
|
||||
|
||||
/* Write the record to the test database */
|
||||
$article->write();
|
||||
|
||||
/* Check that IsChecked column contains a 0 */
|
||||
$this->assertEquals(
|
||||
DB::query("SELECT IsChecked FROM CheckboxFieldTest_Article")->value(),
|
||||
0,
|
||||
'We have a 0 set in the database, because the field saved into as a 0'
|
||||
);
|
||||
|
||||
/* Delete the record we tested */
|
||||
$article->delete();
|
||||
}
|
||||
|
||||
}
|
||||
class CheckboxFieldTest_Article extends DataObject implements TestOnly {
|
||||
|
||||
public static $db = array(
|
||||
'IsChecked' => 'Boolean'
|
||||
);
|
||||
|
||||
}
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user