mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX: Use UTC consistently across all tests for date/time calculations
This ensures that tests will not pass or fail based on whether the test
machine is on NZ time.
This partially reverts df050eda5d
, which has
already been merged. Instead of finding tests that use date calculations, we
are now setting the default time zone in SapphireTest so it will apply to the
whole test suite and any future tests.
Adjust expected values in certain tests for UTC, where the expected values had
previously been expressed in NZ time.
When creating a temp DB for test fixtures, create the DB connection with
timezone UTC.
This commit is contained in:
parent
82bb12b5d3
commit
5954774530
@ -143,6 +143,9 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
|
||||
i18n::set_date_format(null);
|
||||
i18n::set_time_format(null);
|
||||
|
||||
// Set default timezone consistently to avoid NZ-specific dependencies
|
||||
date_default_timezone_set('UTC');
|
||||
|
||||
// Remove password validation
|
||||
$this->originalMemberPasswordValidator = Member::password_validator();
|
||||
$this->originalRequirements = Requirements::backend();
|
||||
@ -272,6 +275,9 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
|
||||
// which is used in DatabaseAdmin->doBuild()
|
||||
global $_SINGLETONS;
|
||||
$_SINGLETONS = array();
|
||||
|
||||
// Set default timezone consistently to avoid NZ-specific dependencies
|
||||
date_default_timezone_set('UTC');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -765,7 +771,10 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
|
||||
// Disable PHPUnit error handling
|
||||
restore_error_handler();
|
||||
|
||||
// Create a temporary database
|
||||
// Create a temporary database, and force the connection to use UTC for time
|
||||
global $databaseConfig;
|
||||
$databaseConfig['timezone'] = '+0:00';
|
||||
DB::connect($databaseConfig);
|
||||
$dbConn = DB::getConn();
|
||||
$prefix = defined('SS_DATABASE_PREFIX') ? SS_DATABASE_PREFIX : 'ss_';
|
||||
$dbname = strtolower(sprintf('%stmpdb', $prefix)) . rand(1000000,9999999);
|
||||
|
@ -32,16 +32,16 @@ class DateTest extends SapphireTest {
|
||||
}
|
||||
|
||||
function testNiceDate() {
|
||||
$this->assertEquals('01/04/2008', DBField::create('Date', 1206968400)->Nice(),
|
||||
$this->assertEquals('31/03/2008', DBField::create('Date', 1206968400)->Nice(),
|
||||
"Date->Nice() works with timestamp integers"
|
||||
);
|
||||
$this->assertEquals('31/03/2008', DBField::create('Date', 1206882000)->Nice(),
|
||||
$this->assertEquals('30/03/2008', DBField::create('Date', 1206882000)->Nice(),
|
||||
"Date->Nice() works with timestamp integers"
|
||||
);
|
||||
$this->assertEquals('01/04/2008', DBField::create('Date', '1206968400')->Nice(),
|
||||
$this->assertEquals('31/03/2008', DBField::create('Date', '1206968400')->Nice(),
|
||||
"Date->Nice() works with timestamp strings"
|
||||
);
|
||||
$this->assertEquals('31/03/2008', DBField::create('Date', '1206882000')->Nice(),
|
||||
$this->assertEquals('30/03/2008', DBField::create('Date', '1206882000')->Nice(),
|
||||
"Date->Nice() works with timestamp strings"
|
||||
);
|
||||
$this->assertEquals('04/03/2003', DBField::create('Date', '4/3/03')->Nice(),
|
||||
@ -74,16 +74,16 @@ class DateTest extends SapphireTest {
|
||||
}
|
||||
|
||||
function testLongDate() {
|
||||
$this->assertEquals('1 April 2008', DBField::create('Date', 1206968400)->Long(),
|
||||
$this->assertEquals('31 March 2008', DBField::create('Date', 1206968400)->Long(),
|
||||
"Date->Long() works with numeric timestamp"
|
||||
);
|
||||
$this->assertEquals('1 April 2008', DBField::create('Date', '1206968400')->Long(),
|
||||
$this->assertEquals('31 March 2008', DBField::create('Date', '1206968400')->Long(),
|
||||
"Date->Long() works with string timestamp"
|
||||
);
|
||||
$this->assertEquals('31 March 2008', DBField::create('Date', 1206882000)->Long(),
|
||||
$this->assertEquals('30 March 2008', DBField::create('Date', 1206882000)->Long(),
|
||||
"Date->Long() works with numeric timestamp"
|
||||
);
|
||||
$this->assertEquals('31 March 2008', DBField::create('Date', '1206882000')->Long(),
|
||||
$this->assertEquals('30 March 2008', DBField::create('Date', '1206882000')->Long(),
|
||||
"Date->Long() works with numeric timestamp"
|
||||
);
|
||||
$this->assertEquals('3 April 2003', DBField::create('Date', '2003-4-3')->Long(),
|
||||
|
@ -35,8 +35,6 @@ class SS_DatetimeTest extends SapphireTest {
|
||||
}
|
||||
|
||||
function testSetNullAndZeroValues() {
|
||||
date_default_timezone_set('UTC');
|
||||
|
||||
$date = DBField::create('SS_Datetime', '');
|
||||
$this->assertNull($date->getValue(), 'Empty string evaluates to NULL');
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user