mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-13 13:06:32 +02:00
5c68bb3bde
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@84086 467b73ca-7a2a-4603-9d3b-597d59a354a9
99 lines
4.6 KiB
PHP
99 lines
4.6 KiB
PHP
<?php
|
|
|
|
class DBFieldTest extends SapphireTest {
|
|
|
|
/**
|
|
* Test the prepValueForDB() method on DBField.
|
|
*/
|
|
function testPrepValueForDB() {
|
|
|
|
/* Integer behaviour, asserting we have 0 */
|
|
$this->assertEquals('0', singleton('Int')->prepValueForDB(0));
|
|
$this->assertEquals('0', singleton('Int')->prepValueForDB(null));
|
|
$this->assertEquals('0', singleton('Int')->prepValueForDB(false));
|
|
$this->assertEquals('0', singleton('Int')->prepValueForDB(''));
|
|
$this->assertEquals('0', singleton('Int')->prepValueForDB('0'));
|
|
|
|
/* Integer behaviour, asserting we have 1 */
|
|
$this->assertEquals('1', singleton('Int')->prepValueForDB(true));
|
|
$this->assertEquals('1', singleton('Int')->prepValueForDB(1));
|
|
$this->assertEquals('1', singleton('Int')->prepValueForDB('1'));
|
|
|
|
/* Decimal behaviour, asserting we have 0 */
|
|
$this->assertEquals('0', singleton('Decimal')->prepValueForDB(0));
|
|
$this->assertEquals('0', singleton('Decimal')->prepValueForDB(null));
|
|
$this->assertEquals('0', singleton('Decimal')->prepValueForDB(false));
|
|
$this->assertEquals('0', singleton('Decimal')->prepValueForDB(''));
|
|
$this->assertEquals('0', singleton('Decimal')->prepValueForDB('0'));
|
|
|
|
/* Decimal behaviour, asserting we have 1 */
|
|
$this->assertEquals('1', singleton('Decimal')->prepValueForDB(true));
|
|
$this->assertEquals('1', singleton('Decimal')->prepValueForDB(1));
|
|
$this->assertEquals('1', singleton('Decimal')->prepValueForDB('1'));
|
|
|
|
/* Boolean behaviour, asserting we have 0 */
|
|
$this->assertEquals("'0'", singleton('Boolean')->prepValueForDB(0));
|
|
$this->assertEquals("'0'", singleton('Boolean')->prepValueForDB(null));
|
|
$this->assertEquals("'0'", singleton('Boolean')->prepValueForDB(false));
|
|
$this->assertEquals("'0'", singleton('Boolean')->prepValueForDB(''));
|
|
$this->assertEquals("'0'", singleton('Boolean')->prepValueForDB('0'));
|
|
|
|
/* Boolean behaviour, asserting we have 1 */
|
|
$this->assertEquals("'1'", singleton('Boolean')->prepValueForDB(true));
|
|
$this->assertEquals("'1'", singleton('Boolean')->prepValueForDB(1));
|
|
$this->assertEquals("'1'", singleton('Boolean')->prepValueForDB('1'));
|
|
|
|
/* Varchar behaviour */
|
|
$this->assertEquals("'0'", singleton('Varchar')->prepValueForDB(0));
|
|
$this->assertEquals("null", singleton('Varchar')->prepValueForDB(null));
|
|
$this->assertEquals("null", singleton('Varchar')->prepValueForDB(false));
|
|
$this->assertEquals("null", singleton('Varchar')->prepValueForDB(''));
|
|
$this->assertEquals("'0'", singleton('Varchar')->prepValueForDB('0'));
|
|
$this->assertEquals("'1'", singleton('Varchar')->prepValueForDB(1));
|
|
$this->assertEquals("'1'", singleton('Varchar')->prepValueForDB(true));
|
|
$this->assertEquals("'1'", singleton('Varchar')->prepValueForDB('1'));
|
|
$this->assertEquals("'00000'", singleton('Varchar')->prepValueForDB('00000'));
|
|
$this->assertEquals("'0'", singleton('Varchar')->prepValueForDB(0000));
|
|
$this->assertEquals("'test'", singleton('Varchar')->prepValueForDB('test'));
|
|
$this->assertEquals("'123'", singleton('Varchar')->prepValueForDB(123));
|
|
|
|
/* Text behaviour */
|
|
$this->assertEquals("'0'", singleton('Text')->prepValueForDB(0));
|
|
$this->assertEquals("null", singleton('Text')->prepValueForDB(null));
|
|
$this->assertEquals("null", singleton('Text')->prepValueForDB(false));
|
|
$this->assertEquals("null", singleton('Text')->prepValueForDB(''));
|
|
$this->assertEquals("'0'", singleton('Text')->prepValueForDB('0'));
|
|
$this->assertEquals("'1'", singleton('Text')->prepValueForDB(1));
|
|
$this->assertEquals("'1'", singleton('Text')->prepValueForDB(true));
|
|
$this->assertEquals("'1'", singleton('Text')->prepValueForDB('1'));
|
|
$this->assertEquals("'00000'", singleton('Text')->prepValueForDB('00000'));
|
|
$this->assertEquals("'0'", singleton('Text')->prepValueForDB(0000));
|
|
$this->assertEquals("'test'", singleton('Text')->prepValueForDB('test'));
|
|
$this->assertEquals("'123'", singleton('Text')->prepValueForDB(123));
|
|
|
|
/* Time behaviour */
|
|
$time = singleton('Time');
|
|
$time->setValue('00:01am');
|
|
$this->assertEquals("00:01:00", $time->getValue());
|
|
$time->setValue('00:59am');
|
|
$this->assertEquals("00:59:00", $time->getValue());
|
|
$time->setValue('11:59am');
|
|
$this->assertEquals("11:59:00", $time->getValue());
|
|
$time->setValue('12:00pm');
|
|
$this->assertEquals("12:00:00", $time->getValue());
|
|
$time->setValue('12:59am');
|
|
$this->assertEquals("12:59:00", $time->getValue());
|
|
$time->setValue('1:00pm');
|
|
$this->assertEquals("13:00:00", $time->getValue());
|
|
$time->setValue('11:59pm');
|
|
$this->assertEquals("23:59:00", $time->getValue());
|
|
$time->setValue('00:00am');
|
|
$this->assertEquals("00:00:00", $time->getValue());
|
|
$time->setValue('00:00:00');
|
|
$this->assertEquals("00:00:00", $time->getValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|