mirror of
https://github.com/silverstripe/doc.silverstripe.org
synced 2024-10-22 15:05:50 +00:00
git-svn-id: http://svn.silverstripe.com/projects/ss2doc/branches/v2@117896 467b73ca-7a2a-4603-9d3b-597d59a354a9
99 lines
2.6 KiB
PHP
99 lines
2.6 KiB
PHP
<?php
|
|
/**
|
|
* @package sapphire
|
|
* @subpackage tests
|
|
*/
|
|
class TimeFieldTest extends SapphireTest {
|
|
|
|
function setUp() {
|
|
parent::setUp();
|
|
|
|
$this->originalLocale = i18n::get_locale();
|
|
i18n::set_locale('en_NZ');
|
|
}
|
|
|
|
function tearDown() {
|
|
parent::tearDown();
|
|
|
|
i18n::set_locale($this->originalLocale);
|
|
}
|
|
|
|
function testConstructorWithoutArgs() {
|
|
$f = new TimeField('Time');
|
|
$this->assertEquals($f->dataValue(), null);
|
|
}
|
|
|
|
function testConstructorWithString() {
|
|
$f = new TimeField('Time', 'Time', '23:00:00');
|
|
$this->assertEquals($f->dataValue(), '23:00:00');
|
|
}
|
|
|
|
function testValidate() {
|
|
$f = new TimeField('Time', 'Time', '11pm');
|
|
$this->assertTrue($f->validate(new RequiredFields()));
|
|
|
|
$f = new TimeField('Time', 'Time', '23:59');
|
|
$this->assertTrue($f->validate(new RequiredFields()));
|
|
|
|
$f = new TimeField('Time', 'Time', 'wrong');
|
|
$this->assertFalse($f->validate(new RequiredFields()));
|
|
}
|
|
|
|
function testSetLocale() {
|
|
// should get en_NZ by default through setUp()
|
|
$f = new TimeField('Time', 'Time');
|
|
$f->setLocale('de_DE');
|
|
// TODO Find a hour format thats actually different
|
|
$f->setValue('23:59');
|
|
$this->assertEquals($f->dataValue(), '23:59:00');
|
|
}
|
|
|
|
function testSetValueWithUseStrToTime() {
|
|
$f = new TimeField('Time', 'Time');
|
|
$f->setValue('11pm');
|
|
$this->assertEquals($f->dataValue(), '23:00:00',
|
|
'Setting value to "11pm" parses with use_strtotime enabled'
|
|
);
|
|
$this->assertTrue($f->validate(new RequiredFields()));
|
|
|
|
$f = new TimeField('Time', 'Time');
|
|
$f->setConfig('use_strtotime', false);
|
|
$f->setValue('11pm');
|
|
$this->assertEquals($f->dataValue(), null,
|
|
'Setting value to "11pm" parses with use_strtotime enabled'
|
|
);
|
|
$this->assertFalse($f->validate(new RequiredFields()));
|
|
|
|
$f = new TimeField('Time', 'Time');
|
|
$f->setValue('11pm');
|
|
$this->assertEquals($f->dataValue(), '23:00:00');
|
|
|
|
$f = new TimeField('Time', 'Time');
|
|
$f->setValue('11:59pm');
|
|
$this->assertEquals($f->dataValue(), '23:59:00');
|
|
|
|
$f = new TimeField('Time', 'Time');
|
|
$f->setValue('11:59 pm');
|
|
$this->assertEquals($f->dataValue(), '23:59:00');
|
|
|
|
$f = new TimeField('Time', 'Time');
|
|
$f->setValue('11:59:38 pm');
|
|
$this->assertEquals($f->dataValue(), '23:59:38');
|
|
|
|
$f = new TimeField('Time', 'Time');
|
|
$f->setValue('23:59');
|
|
$this->assertEquals($f->dataValue(), '23:59:00');
|
|
|
|
$f = new TimeField('Time', 'Time');
|
|
$f->setValue('23:59:38');
|
|
$this->assertEquals($f->dataValue(), '23:59:38');
|
|
}
|
|
|
|
function testOverrideWithNull() {
|
|
$field = new TimeField('Time', 'Time');
|
|
|
|
$field->setValue('11:00pm');
|
|
$field->setValue('');
|
|
$this->assertEquals($field->dataValue(), '');
|
|
}
|
|
} |