mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #241 from oddnoc/date-default-timezone-for-tests
Set UTC timezone for SapphireTest
This commit is contained in:
commit
86b805d03c
@ -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');
|
||||
|
||||
|
@ -12,6 +12,8 @@ class DbDatetimeTest extends FunctionalTest {
|
||||
E_USER_NOTICE => 5,
|
||||
);
|
||||
|
||||
private $adapter;
|
||||
|
||||
/**
|
||||
* Check if dates match more or less. This takes into the account the db query
|
||||
* can overflow to the next second giving offset readings.
|
||||
|
Loading…
Reference in New Issue
Block a user