2008-09-11 08:22:33 +02:00
|
|
|
<?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 */
|
2008-11-24 20:28:46 +01:00
|
|
|
$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'));
|
2008-09-11 08:22:33 +02:00
|
|
|
|
|
|
|
/* Boolean behaviour, asserting we have 1 */
|
2008-11-24 20:28:46 +01:00
|
|
|
$this->assertEquals("'1'", singleton('Boolean')->prepValueForDB(true));
|
|
|
|
$this->assertEquals("'1'", singleton('Boolean')->prepValueForDB(1));
|
|
|
|
$this->assertEquals("'1'", singleton('Boolean')->prepValueForDB('1'));
|
2008-09-11 08:22:33 +02:00
|
|
|
|
|
|
|
/* 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));
|
2009-08-10 05:56:59 +02:00
|
|
|
|
|
|
|
/* 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());
|
|
|
|
|
2008-09-11 08:22:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|