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',
|
|
|
|
);
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testHasDatabaseFieldOnDataObject() {
|
2009-06-02 05:45:38 +02:00
|
|
|
$obj = singleton('CompositeDBFieldTest_DataObject');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2009-06-02 05:45:38 +02:00
|
|
|
$this->assertTrue($obj->hasDatabaseField('MyMoneyAmount'));
|
|
|
|
$this->assertTrue($obj->hasDatabaseField('MyMoneyCurrency'));
|
|
|
|
$this->assertFalse($obj->hasDatabaseField('MyMoney'));
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2009-08-11 10:49:52 +02:00
|
|
|
/**
|
|
|
|
* Test DataObject::composite_fields() and DataObject::is_composite_field()
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testCompositeFieldMetaDataFunctions() {
|
2009-08-11 10:49:52 +02:00
|
|
|
$this->assertEquals('Money', DataObject::is_composite_field('CompositeDBFieldTest_DataObject', 'MyMoney'));
|
|
|
|
$this->assertNull(DataObject::is_composite_field('CompositeDBFieldTest_DataObject', 'Title'));
|
2014-08-15 08:53:05 +02:00
|
|
|
$this->assertEquals(array('MyMoney' => 'Money'),
|
2009-08-11 10:49:52 +02:00
|
|
|
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'));
|
2014-08-15 08:53:05 +02:00
|
|
|
$this->assertEquals(array('MyMoney' => 'Money', 'OtherMoney' => 'Money'),
|
2009-08-11 10:49:52 +02:00
|
|
|
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 {
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $db = array(
|
2014-08-15 08:53:05 +02:00
|
|
|
'Title' => 'Text',
|
|
|
|
'MyMoney' => 'Money',
|
2009-06-02 05:45:38 +02:00
|
|
|
);
|
|
|
|
}
|
2009-08-11 10:49:52 +02:00
|
|
|
|
|
|
|
class SubclassedDBFieldObject extends CompositeDBFieldTest_DataObject {
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $db = array(
|
2014-08-15 08:53:05 +02:00
|
|
|
'OtherField' => 'Text',
|
|
|
|
'OtherMoney' => 'Money',
|
2009-08-11 10:49:52 +02:00
|
|
|
);
|
|
|
|
}
|