From c2720824482f7e04d128b7f6724cabea277288be Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Thu, 23 Apr 2009 12:14:44 +0000 Subject: [PATCH] MINOR Added CheckboxFieldTest git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@75047 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- tests/forms/CheckboxFieldTest.php | 68 +++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 tests/forms/CheckboxFieldTest.php diff --git a/tests/forms/CheckboxFieldTest.php b/tests/forms/CheckboxFieldTest.php new file mode 100644 index 000000000..ff39bcdf7 --- /dev/null +++ b/tests/forms/CheckboxFieldTest.php @@ -0,0 +1,68 @@ +setValue(true); + + /* dataValue() for the field is 1 */ + $this->assertEquals($field->dataValue(), 1, 'dataValue() returns a 1'); + + /* Value() returns 1 as well */ + $this->assertEquals($field->Value(), 1, 'Value() returns a 1'); + } + + function testFieldValueString() { + /* Create the field, and set the value as "on" (raw request field value from DOM) */ + $field = new CheckboxField('IsChecked', 'Checked'); + $field->setValue('on'); + + /* dataValue() for the field is 1 */ + $this->assertEquals($field->dataValue(), 1, 'dataValue() returns a 1'); + + /* Value() returns 1 as well */ + $this->assertEquals($field->Value(), 1, 'Value() returns a 1'); + } + + function testFieldValueSettingNull() { + /* Create the field, and set the value as NULL */ + $field = new CheckboxField('IsChecked', 'Checked'); + $field->setValue(null); + + /* dataValue() for the field is 0 */ + $this->assertEquals($field->dataValue(), 0, 'dataValue() returns a 0'); + + /* Value() returns 0 as well */ + $this->assertEquals($field->Value(), 0, 'Value() returns a 0'); + } + + function testFieldValueSettingFalse() { + /* Create the field, and set the value as NULL */ + $field = new CheckboxField('IsChecked', 'Checked'); + $field->setValue(false); + + /* dataValue() for the field is 0 */ + $this->assertEquals($field->dataValue(), 0, 'dataValue() returns a 0'); + + /* Value() returns 0 as well */ + $this->assertEquals($field->Value(), 0, 'Value() returns a 0'); + } + + function testFieldValueWithoutSettingValue() { + /* Create the field, but don't set any value on it */ + $field = new CheckboxField('IsChecked', 'Checked'); + + /* dataValue() for the field is 0 */ + $this->assertEquals($field->dataValue(), 0, 'dataValue() returns a 0'); + + /* Value() returns 0 as well */ + $this->assertEquals($field->Value(), 0, 'Value() returns a 0'); + } + +} +?> \ No newline at end of file