mirror of
https://github.com/silverstripe/silverstripe-sqlite3
synced 2024-10-22 17:05:37 +02:00
ENHANCEMENT: added a test for checking the time of the webserver against the time of the db server
This commit is contained in:
parent
f9108ae913
commit
5e8234ba2d
@ -8,17 +8,36 @@ class DbDatetimeTest extends FunctionalTest {
|
||||
$this->supportDbDatetime = method_exists($this->adapter, 'datetimeIntervalClause');
|
||||
}
|
||||
|
||||
function testIfWebserverInSyncWithDbServer() {
|
||||
if($this->supportDbDatetime) {
|
||||
$query = 'SELECT ' . $this->adapter->formattedDatetimeClause('now', '%Y-%m-%d %H:%i:%s');
|
||||
$result = DB::query($query)->value();
|
||||
$this->assertEquals($result, date('Y-m-d H:i:s'));
|
||||
}
|
||||
}
|
||||
|
||||
function testCorrectNow() {
|
||||
if($this->supportDbDatetime) {
|
||||
$query = 'SELECT ' . $this->adapter->formattedDatetimeClause('now', '%U');
|
||||
$result = DB::query($query)->value();
|
||||
$this->assertEquals($result, time());
|
||||
}
|
||||
}
|
||||
|
||||
function testDbDatetimeFormat() {
|
||||
if($this->supportDbDatetime) {
|
||||
|
||||
$result = DB::query('SELECT ' . $this->adapter->formattedDatetimeClause('1973-10-14 10:30:00', '%H:%i, %d/%m/%Y'))->value();
|
||||
$query = 'SELECT ' . $this->adapter->formattedDatetimeClause('1973-10-14 10:30:00', '%H:%i, %d/%m/%Y');
|
||||
$result = DB::query($query)->value();
|
||||
$this->assertEquals($result, date('H:i, d/m/Y', strtotime('1973-10-14 10:30:00')), 'nice literal time');
|
||||
|
||||
$result = DB::query('SELECT ' . $this->adapter->formattedDatetimeClause('now', '%d'))->value();
|
||||
$query = 'SELECT ' . $this->adapter->formattedDatetimeClause('now', '%d');
|
||||
$result = DB::query($query)->value();
|
||||
$this->assertEquals($result, date('d'), 'todays day');
|
||||
|
||||
$result = DB::query('SELECT ' . $this->adapter->formattedDatetimeClause('Created', '%U') . ' AS test FROM SiteTree WHERE URLSegment = \'home\'')->value();
|
||||
$this->assertEquals($result, date('U', strtotime(Dataobject::get_one('SiteTree',"URLSegment = 'home'")->Created)), 'SiteTree[home]->Created as timestamp');
|
||||
$query = 'SELECT ' . $this->adapter->formattedDatetimeClause('"Created"', '%U') . ' AS test FROM "SiteTree" WHERE "URLSegment" = \'home\'';
|
||||
$result = DB::query($query)->value();
|
||||
$this->assertEquals($result, date('U', strtotime(Dataobject::get_one('SiteTree',"\"URLSegment\" = 'home'")->Created)), 'SiteTree[home]->Created as timestamp');
|
||||
|
||||
}
|
||||
}
|
||||
@ -26,14 +45,17 @@ class DbDatetimeTest extends FunctionalTest {
|
||||
function testDbDatetimeInterval() {
|
||||
if($this->supportDbDatetime) {
|
||||
|
||||
$result = DB::query('SELECT ' . $this->adapter->datetimeIntervalClause('1973-10-14 10:30:00', '+18 Years'))->value();
|
||||
$query = 'SELECT ' . $this->adapter->datetimeIntervalClause('1973-10-14 10:30:00', '+18 Years');
|
||||
$result = DB::query($query)->value();
|
||||
$this->assertEquals($result, '1991-10-14 10:30:00', 'add 18 years');
|
||||
|
||||
$result = DB::query('SELECT ' . $this->adapter->datetimeIntervalClause('now', '+1 Day'))->value();
|
||||
$query = 'SELECT ' . $this->adapter->datetimeIntervalClause('now', '+1 Day');
|
||||
$result = DB::query($query)->value();
|
||||
$this->assertEquals($result, date('Y-m-d H:i:s', strtotime('+1 Day')), 'tomorrow');
|
||||
|
||||
$result = DB::query('SELECT ' . $this->adapter->datetimeIntervalClause('Created', '-15 Minutes') . ' AS test FROM SiteTree WHERE URLSegment = \'home\'')->value();
|
||||
$this->assertEquals($result, date('Y-m-d H:i:s', strtotime(Dataobject::get_one('SiteTree',"URLSegment = 'home'")->Created) - 900), '15 Minutes before creating SiteTree[home]');
|
||||
$query = 'SELECT ' . $this->adapter->datetimeIntervalClause('"Created"', '-15 Minutes') . ' AS "test" FROM "SiteTree" WHERE "URLSegment" = \'home\'';
|
||||
$result = DB::query($query)->value();
|
||||
$this->assertEquals($result, date('Y-m-d H:i:s', strtotime(Dataobject::get_one('SiteTree',"\"URLSegment\" = 'home'")->Created) - 900), '15 Minutes before creating SiteTree[home]');
|
||||
|
||||
}
|
||||
}
|
||||
@ -41,18 +63,22 @@ class DbDatetimeTest extends FunctionalTest {
|
||||
function testDbDatetimeDifference() {
|
||||
if($this->supportDbDatetime) {
|
||||
|
||||
$result = DB::query('SELECT ' . $this->adapter->datetimeDifferenceClause('1974-10-14 10:30:00', '1973-10-14 10:30:00'))->value();
|
||||
$query = 'SELECT ' . $this->adapter->datetimeDifferenceClause('1974-10-14 10:30:00', '1973-10-14 10:30:00');
|
||||
$result = DB::query($query)->value();
|
||||
$this->assertEquals($result/86400, 365, '1974 - 1973 = 365 * 86400 sec');
|
||||
|
||||
$result = DB::query('SELECT ' . $this->adapter->datetimeDifferenceClause(date('Y-m-d H:i:s', strtotime('-15 seconds')), 'now'))->value();
|
||||
$query = 'SELECT ' . $this->adapter->datetimeDifferenceClause(date('Y-m-d H:i:s', strtotime('-15 seconds')), 'now');
|
||||
$result = DB::query($query)->value();
|
||||
$this->assertEquals($result, -15, '15 seconds ago - now');
|
||||
|
||||
$result = DB::query('SELECT ' . $this->adapter->datetimeDifferenceClause('now', $this->adapter->datetimeIntervalClause('now', '+45 Minutes')))->value();
|
||||
$query = 'SELECT ' . $this->adapter->datetimeDifferenceClause('now', $this->adapter->datetimeIntervalClause('now', '+45 Minutes'));
|
||||
$result = DB::query($query)->value();
|
||||
$this->assertEquals($result, -45 * 60, 'now - 45 minutes ahead');
|
||||
|
||||
$result = DB::query('SELECT ' . $this->adapter->datetimeDifferenceClause('LastEdited', 'Created') . ' AS test FROM SiteTree WHERE URLSegment = \'home\'')->value();
|
||||
$lastedited = Dataobject::get_one('SiteTree',"URLSegment = 'home'")->LastEdited;
|
||||
$created = Dataobject::get_one('SiteTree',"URLSegment = 'home'")->Created;
|
||||
$query = 'SELECT ' . $this->adapter->datetimeDifferenceClause('"LastEdited"', '"Created"') . ' AS "test" FROM "SiteTree" WHERE "URLSegment" = \'home\'';
|
||||
$result = DB::query($query)->value();
|
||||
$lastedited = Dataobject::get_one('SiteTree',"\"URLSegment\" = 'home'")->LastEdited;
|
||||
$created = Dataobject::get_one('SiteTree',"\"URLSegment\" = 'home'")->Created;
|
||||
$this->assertEquals($result, strtotime($lastedited) - strtotime($created), 'age of HomePage record in seconds since unix epoc');
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user