2012-06-12 02:55:27 +02:00
< ? php
2016-07-15 03:57:54 +02:00
use SilverStripe\ORM\DataObject ;
2016-08-30 03:08:11 +02:00
use SilverStripe\Dev\SapphireTest ;
use SilverStripe\Dev\TestOnly ;
2015-12-17 19:50:59 +01:00
class MSSQLDatabaseQueryTest extends SapphireTest
{
2018-05-25 10:16:01 +02:00
protected static $fixture_file = 'MSSQLDatabaseQueryTest.yml' ;
2012-06-12 02:55:27 +02:00
2018-05-25 10:16:01 +02:00
public static function getExtraDataObjects ()
{
return [ 'MSSQLDatabaseQueryTestDataObject' ];
}
2012-06-12 02:55:27 +02:00
2015-12-17 19:50:59 +01:00
public function testDateValueFormatting ()
{
$obj = $this -> objFromFixture ( 'MSSQLDatabaseQueryTestDataObject' , 'test-data-1' );
2018-05-25 10:16:01 +02:00
$this -> assertEquals ( '2012-01-01' , $obj -> obj ( 'TestDate' ) -> Format ( 'y-MM-dd' ), 'Date field value is formatted correctly (y-MM-dd)' );
2015-12-17 19:50:59 +01:00
}
2012-06-12 02:55:27 +02:00
2015-12-17 19:50:59 +01:00
public function testDatetimeValueFormatting ()
{
$obj = $this -> objFromFixture ( 'MSSQLDatabaseQueryTestDataObject' , 'test-data-1' );
2018-05-25 10:16:01 +02:00
$this -> assertEquals ( '2012-01-01 10:30:00' , $obj -> obj ( 'TestDatetime' ) -> Format ( 'y-MM-dd HH:mm:ss' ), 'Datetime field value is formatted correctly (y-MM-dd HH:mm:ss)' );
2015-12-17 19:50:59 +01:00
}
2012-06-12 02:55:27 +02:00
}
2018-05-25 10:16:01 +02:00
2015-12-17 19:50:59 +01:00
class MSSQLDatabaseQueryTestDataObject extends DataObject implements TestOnly
{
2016-07-15 03:57:54 +02:00
private static $db = array (
2015-12-17 19:50:59 +01:00
'TestDate' => 'Date' ,
2016-07-15 03:57:54 +02:00
'TestDatetime' => 'Datetime'
2015-12-17 19:50:59 +01:00
);
2012-06-12 02:55:27 +02:00
}