2009-06-02 05:45:38 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2009-06-02 05:45:38 +02:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
class CompositeDBFieldTest extends SapphireTest {
|
2010-04-12 04:03:16 +02:00
|
|
|
|
|
|
|
protected $extraDataObjects = array(
|
|
|
|
'CompositeDBFieldTest_DataObject',
|
|
|
|
'SubclassedDBFieldObject',
|
|
|
|
);
|
|
|
|
|
2009-06-02 05:45:38 +02:00
|
|
|
function testHasDatabaseFieldOnDataObject() {
|
|
|
|
$obj = singleton('CompositeDBFieldTest_DataObject');
|
|
|
|
|
|
|
|
$this->assertTrue($obj->hasDatabaseField('MyMoneyAmount'));
|
|
|
|
$this->assertTrue($obj->hasDatabaseField('MyMoneyCurrency'));
|
|
|
|
$this->assertFalse($obj->hasDatabaseField('MyMoney'));
|
|
|
|
}
|
2009-08-11 10:49:52 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test DataObject::composite_fields() and DataObject::is_composite_field()
|
|
|
|
*/
|
|
|
|
function testCompositeFieldMetaDataFunctions() {
|
|
|
|
$this->assertEquals('Money', DataObject::is_composite_field('CompositeDBFieldTest_DataObject', 'MyMoney'));
|
|
|
|
$this->assertNull(DataObject::is_composite_field('CompositeDBFieldTest_DataObject', 'Title'));
|
|
|
|
$this->assertEquals(array('MyMoney' => 'Money'),
|
|
|
|
DataObject::composite_fields('CompositeDBFieldTest_DataObject'));
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals('Money', DataObject::is_composite_field('SubclassedDBFieldObject', 'MyMoney'));
|
|
|
|
$this->assertEquals('Money', DataObject::is_composite_field('SubclassedDBFieldObject', 'OtherMoney'));
|
|
|
|
$this->assertNull(DataObject::is_composite_field('SubclassedDBFieldObject', 'Title'));
|
|
|
|
$this->assertNull(DataObject::is_composite_field('SubclassedDBFieldObject', 'OtherField'));
|
|
|
|
$this->assertEquals(array('MyMoney' => 'Money', 'OtherMoney' => 'Money'),
|
|
|
|
DataObject::composite_fields('SubclassedDBFieldObject'));
|
|
|
|
}
|
2009-06-02 05:45:38 +02:00
|
|
|
}
|
|
|
|
|
2009-08-11 10:49:52 +02:00
|
|
|
class CompositeDBFieldTest_DataObject extends DataObject {
|
2009-06-02 05:45:38 +02:00
|
|
|
static $db = array(
|
|
|
|
'Title' => 'Text',
|
|
|
|
'MyMoney' => 'Money',
|
|
|
|
);
|
|
|
|
}
|
2009-08-11 10:49:52 +02:00
|
|
|
|
|
|
|
class SubclassedDBFieldObject extends CompositeDBFieldTest_DataObject {
|
|
|
|
static $db = array(
|
|
|
|
'OtherField' => 'Text',
|
|
|
|
'OtherMoney' => 'Money',
|
|
|
|
);
|
|
|
|
}
|