mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
MINOR Added CheckboxFieldTest
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@75047 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
8605743ea6
commit
c272082448
68
tests/forms/CheckboxFieldTest.php
Normal file
68
tests/forms/CheckboxFieldTest.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?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');
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user