Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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 df050ed, 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.
  • Loading branch information...
commit 59547745303bda7d08171ebca089e0de38a20007 1 parent 82bb12b
@oddnoc oddnoc authored
View
11 dev/SapphireTest.php
@@ -143,6 +143,9 @@ function setUp() {
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 @@ function setUpOnce() {
// 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 @@ static function create_temp_db() {
// 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);
View
16 tests/model/DateTest.php
@@ -32,16 +32,16 @@ function tearDown() {
}
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 @@ function testNiceDate() {
}
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(),
View
2  tests/model/DatetimeTest.php
@@ -35,8 +35,6 @@ function testNowWithMockDate() {
}
function testSetNullAndZeroValues() {
- date_default_timezone_set('UTC');
-
$date = DBField::create('SS_Datetime', '');
$this->assertNull($date->getValue(), 'Empty string evaluates to NULL');
Please sign in to comment.
Something went wrong with that request. Please try again.