mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
c8c9c2166d
ENHANCEMENT Added DropdownFieldTest git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@64304 467b73ca-7a2a-4603-9d3b-597d59a354a9
85 lines
1.7 KiB
PHP
85 lines
1.7 KiB
PHP
<?php
|
|
/**
|
|
* @package sapphire
|
|
* @subpackage tests
|
|
*/
|
|
class DropdownFieldTest extends SapphireTest {
|
|
|
|
function testGetSource() {
|
|
$source = array(1=>'one');
|
|
$field = new DropdownField('Field', null, $source);
|
|
$this->assertEquals(
|
|
$field->getSource(),
|
|
array(
|
|
1 => 'one'
|
|
)
|
|
);
|
|
}
|
|
|
|
function testEmptyStringAsBooleanConstructorArgument() {
|
|
$source = array(1=>'one');
|
|
$field = new DropdownField('Field', null, $source, null, null, true);
|
|
$this->assertEquals(
|
|
$field->getSource(),
|
|
array(
|
|
'' => '',
|
|
1 => 'one'
|
|
)
|
|
);
|
|
}
|
|
|
|
function testEmptyStringAsLiteralConstructorArgument() {
|
|
$source = array(1=>'one');
|
|
$field = new DropdownField('Field', null, $source, null, null, 'select...');
|
|
$this->assertEquals(
|
|
$field->getSource(),
|
|
array(
|
|
"" => 'select...',
|
|
1 => 'one'
|
|
)
|
|
);
|
|
}
|
|
|
|
function testHasEmptyDefault() {
|
|
$source = array(1=>'one');
|
|
$field = new DropdownField('Field', null, $source);
|
|
$field->setHasEmptyDefault(true);
|
|
$this->assertEquals(
|
|
$field->getSource(),
|
|
array(
|
|
'' => '',
|
|
1 => 'one'
|
|
)
|
|
);
|
|
}
|
|
|
|
function testEmptyDefaultStringThroughSetter() {
|
|
$source = array(1=>'one');
|
|
$field = new DropdownField('Field', null, $source);
|
|
$field->setEmptyString('select...');
|
|
$this->assertEquals(
|
|
$field->getSource(),
|
|
array(
|
|
'' => 'select...',
|
|
1 => 'one'
|
|
)
|
|
);
|
|
$this->assertTrue(
|
|
$field->getHasEmptyDefault()
|
|
);
|
|
}
|
|
|
|
function testZeroArraySourceNotOverwrittenByEmptyString() {
|
|
$source = array(0=>'zero');
|
|
$field = new DropdownField('Field', null, $source);
|
|
$field->setEmptyString('select...');
|
|
$this->assertEquals(
|
|
$field->getSource(),
|
|
array(
|
|
'' => 'select...',
|
|
0 => 'zero'
|
|
)
|
|
);
|
|
}
|
|
}
|
|
?>
|