silverstripe-framework/tests/forms/CheckboxFieldTest.php
Sean Harvey c272082448 MINOR Added CheckboxFieldTest
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@75047 467b73ca-7a2a-4603-9d3b-597d59a354a9
2011-02-02 14:27:17 +13:00

68 lines
2.1 KiB
PHP

<?php
/**
* @package sapphire
* @subpackage tests
*/
class CheckboxFieldTest extends SapphireTest {
function testFieldValueTrue() {
/* Create the field, and set the value as boolean true */
$field = new CheckboxField('IsChecked', 'Checked');
$field->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');
}
}
?>