2008-11-10 00:56:24 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage Testing
|
|
|
|
*/
|
|
|
|
class DatabaseTest extends SapphireTest {
|
2010-01-13 00:16:14 +01:00
|
|
|
|
|
|
|
protected $extraDataObjects = array(
|
|
|
|
'DatabaseTest_MyObject',
|
|
|
|
);
|
2008-11-10 00:56:24 +01:00
|
|
|
|
|
|
|
function testDontRequireField() {
|
|
|
|
$conn = DB::getConn();
|
|
|
|
$this->assertArrayHasKey(
|
|
|
|
'MyField',
|
|
|
|
$conn->fieldList('DatabaseTest_MyObject')
|
|
|
|
);
|
|
|
|
|
|
|
|
$conn->dontRequireField('DatabaseTest_MyObject', 'MyField');
|
|
|
|
$this->assertArrayHasKey(
|
|
|
|
'_obsolete_MyField',
|
|
|
|
$conn->fieldList('DatabaseTest_MyObject'),
|
|
|
|
'Field is renamed to _obsolete_<fieldname> through dontRequireField()'
|
|
|
|
);
|
|
|
|
|
2010-01-13 00:16:14 +01:00
|
|
|
$this->resetDBSchema(true);
|
2008-11-10 00:56:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function testRenameField() {
|
|
|
|
$conn = DB::getConn();
|
|
|
|
|
|
|
|
$conn->renameField('DatabaseTest_MyObject', 'MyField', 'MyRenamedField');
|
|
|
|
|
|
|
|
$this->assertArrayHasKey(
|
|
|
|
'MyRenamedField',
|
|
|
|
$conn->fieldList('DatabaseTest_MyObject'),
|
|
|
|
'New fieldname is set through renameField()'
|
|
|
|
);
|
|
|
|
$this->assertArrayNotHasKey(
|
|
|
|
'MyField',
|
|
|
|
$conn->fieldList('DatabaseTest_MyObject'),
|
|
|
|
'Old fieldname isnt preserved through renameField()'
|
|
|
|
);
|
2010-01-13 00:16:14 +01:00
|
|
|
|
|
|
|
$this->resetDBSchema(true);
|
2008-11-10 00:56:24 +01:00
|
|
|
}
|
|
|
|
|
2009-05-19 05:55:14 +02:00
|
|
|
function testMySQLCreateTableOptions() {
|
|
|
|
if(DB::getConn() instanceof MySQLDatabase) {
|
|
|
|
$ret = DB::query(sprintf(
|
|
|
|
'SHOW TABLE STATUS WHERE "Name" = \'%s\'',
|
|
|
|
'DatabaseTest_MyObject'
|
|
|
|
))->first();
|
|
|
|
$this->assertEquals($ret['Engine'],'InnoDB',
|
|
|
|
"MySQLDatabase tables can be changed to InnoDB through DataObject::\$create_table_options"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-11-10 00:56:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class DatabaseTest_MyObject extends DataObject implements TestOnly {
|
2009-05-19 05:55:14 +02:00
|
|
|
|
|
|
|
static $create_table_options = array('MySQLDatabase' => 'ENGINE=InnoDB');
|
|
|
|
|
2008-11-10 00:56:24 +01:00
|
|
|
static $db = array(
|
|
|
|
'MyField' => 'Varchar'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
?>
|