silverstripe-mssql/tests/MSSQLDatabaseQueryTest.php
Sean Harvey a4c269bf62 BUGFIX Fixing date/datetime handling in MSSQLDatabase
Fixing the date type to actually be "date", and not "datetime" so
that values are returned as "Y-m-d" for dates, and not "Y-m-d H:i:s".

Additionally, fixing a case where using the mssql functions would
return strange datetime formats. We need the datetime field values
in Y-m-d H:i:s. To get this working, we need to inspect the field type
when retrieving rows from the database and re-format the datetime
value at this point. This is done in MSSQLQuery::nextRecord()
2012-06-12 12:57:53 +12:00

29 lines
877 B
PHP

<?php
class MSSQLDatabaseQueryTest extends SapphireTest {
public static $fixture_file = 'MSSQLDatabaseQueryTest.yml';
protected $extraDataObjects = array(
'MSSQLDatabaseQueryTestDataObject'
);
public function testDateValueFormatting() {
$obj = $this->objFromFixture('MSSQLDatabaseQueryTestDataObject', 'test-data-1');
$this->assertEquals('2012-01-01', $obj->TestDate, 'Date field value is formatted correctly (Y-m-d)');
}
public function testDatetimeValueFormatting() {
$obj = $this->objFromFixture('MSSQLDatabaseQueryTestDataObject', 'test-data-1');
$this->assertEquals('2012-01-01 10:30:00', $obj->TestDatetime, 'Datetime field value is formatted correctly (Y-m-d H:i:s)');
}
}
class MSSQLDatabaseQueryTestDataObject extends DataObject implements TestOnly {
public static $db = array(
'TestDate' => 'Date',
'TestDatetime' => 'SS_Datetime'
);
}