mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
MINOR Added basic tests for Date and DateField
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@70960 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
2939e33554
commit
90e6d713f6
44
tests/fieldtypes/DateTest.php
Normal file
44
tests/fieldtypes/DateTest.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* @package sapphire
|
||||
* @subpackage tests
|
||||
*/
|
||||
class DateTest extends SapphireTest {
|
||||
|
||||
function testNiceDate() {
|
||||
/* Test the DD/MM/YYYY formatting of Date::Nice() */
|
||||
$cases = array(
|
||||
'4/3/03' => '04/03/2003',
|
||||
'04/03/03' => '04/03/2003',
|
||||
'4/3/03' => '04/03/2003',
|
||||
'4/03/03' => '04/03/2003',
|
||||
'4/3/2003' => '04/03/2003',
|
||||
'4-3-2003' => '04/03/2003',
|
||||
'2003-03-04' => '04/03/2003',
|
||||
'04/03/2003' => '04/03/2003',
|
||||
'04-03-2003' => '04/03/2003'
|
||||
);
|
||||
|
||||
foreach($cases as $original => $expected) {
|
||||
$date = new Date();
|
||||
$date->setValue($original);
|
||||
$this->assertEquals($expected, $date->Nice());
|
||||
}
|
||||
}
|
||||
|
||||
function testLongDate() {
|
||||
/* "24 May 2006" style formatting of Date::Long() */
|
||||
$cases = array(
|
||||
'2003-4-3' => '3 April 2003',
|
||||
'3/4/2003' => '3 April 2003',
|
||||
);
|
||||
|
||||
foreach($cases as $original => $expected) {
|
||||
$date = new Date();
|
||||
$date->setValue($original);
|
||||
$this->assertEquals($expected, $date->Long());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
39
tests/forms/DateFieldTest.php
Normal file
39
tests/forms/DateFieldTest.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
* @package sapphire
|
||||
* @subpackage tests
|
||||
*/
|
||||
class DateFieldTest extends SapphireTest {
|
||||
|
||||
function testDMYFormat() {
|
||||
/* We get YYYY-MM-DD format as the data value for DD/MM/YYYY input value */
|
||||
$dateField = new DateField('Date', 'Date', '04/03/2003');
|
||||
$this->assertEquals($dateField->dataValue(), '2003-03-04');
|
||||
|
||||
/* Even if value hasn't got leading 0's in it we still get the correct data value */
|
||||
$dateField2 = new DateField('Date', 'Date', '4/3/03');
|
||||
$this->assertEquals($dateField2->dataValue(), '03-3-4');
|
||||
}
|
||||
|
||||
function testYMDFormat() {
|
||||
/* We get YYYY-MM-DD format as the data value for YYYY-MM-DD input value */
|
||||
$dateField = new DateField('Date', 'Date', '2003/03/04');
|
||||
$this->assertEquals($dateField->dataValue(), '2003-03-04');
|
||||
|
||||
/* Even if input value hasn't got leading 0's in it we still get the correct data value */
|
||||
$dateField2 = new DateField('Date', 'Date', '2003/3/4');
|
||||
$this->assertEquals($dateField2->dataValue(), '2003-03-04');
|
||||
}
|
||||
|
||||
function testMDYFormat() {
|
||||
/* We get MM-DD-YYYY format as the data value for YYYY-MM-DD input value */
|
||||
$dateField = new DateField('Date', 'Date', '03/04/2003');
|
||||
$this->assertEquals($dateField->dataValue(), '2003-04-03');
|
||||
|
||||
/* Even if input value hasn't got leading 0's in it we still get the correct data value */
|
||||
$dateField2 = new DateField('Date', 'Date', '3/4/03');
|
||||
$this->assertEquals($dateField2->dataValue(), '03-4-3');
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue
Block a user