mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
MINOR: cached fieldlist array can now be cleared
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@115445 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
60d09a6c5b
commit
360176d23c
@ -8,29 +8,33 @@ class DatabaseTest extends SapphireTest {
|
|||||||
protected $extraDataObjects = array(
|
protected $extraDataObjects = array(
|
||||||
'DatabaseTest_MyObject',
|
'DatabaseTest_MyObject',
|
||||||
);
|
);
|
||||||
|
|
||||||
protected $usesDatabase = true;
|
protected $usesDatabase = true;
|
||||||
|
|
||||||
function testDontRequireField() {
|
function testDontRequireField() {
|
||||||
$conn = DB::getConn();
|
$conn = DB::getConn();
|
||||||
$this->assertArrayHasKey(
|
$this->assertArrayHasKey(
|
||||||
'MyField',
|
'MyField',
|
||||||
$conn->fieldList('DatabaseTest_MyObject')
|
$conn->fieldList('DatabaseTest_MyObject')
|
||||||
);
|
);
|
||||||
|
|
||||||
$conn->dontRequireField('DatabaseTest_MyObject', 'MyField');
|
$conn->dontRequireField('DatabaseTest_MyObject', 'MyField');
|
||||||
|
|
||||||
$this->assertArrayHasKey(
|
$this->assertArrayHasKey(
|
||||||
'_obsolete_MyField',
|
'_obsolete_MyField',
|
||||||
$conn->fieldList('DatabaseTest_MyObject'),
|
$conn->fieldList('DatabaseTest_MyObject'),
|
||||||
'Field is renamed to _obsolete_<fieldname> through dontRequireField()'
|
'Field is renamed to _obsolete_<fieldname> through dontRequireField()'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->resetDBSchema(true);
|
$this->resetDBSchema(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testRenameField() {
|
function testRenameField() {
|
||||||
$conn = DB::getConn();
|
$conn = DB::getConn();
|
||||||
|
|
||||||
|
//Reset our cached fieldlists:
|
||||||
|
$conn->clear_cached_fieldlist();
|
||||||
|
|
||||||
$conn->renameField('DatabaseTest_MyObject', 'MyField', 'MyRenamedField');
|
$conn->renameField('DatabaseTest_MyObject', 'MyField', 'MyRenamedField');
|
||||||
|
|
||||||
$this->assertArrayHasKey(
|
$this->assertArrayHasKey(
|
||||||
@ -46,7 +50,7 @@ class DatabaseTest extends SapphireTest {
|
|||||||
|
|
||||||
$this->resetDBSchema(true);
|
$this->resetDBSchema(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testMySQLCreateTableOptions() {
|
function testMySQLCreateTableOptions() {
|
||||||
if(DB::getConn() instanceof MySQLDatabase) {
|
if(DB::getConn() instanceof MySQLDatabase) {
|
||||||
$ret = DB::query(sprintf(
|
$ret = DB::query(sprintf(
|
||||||
@ -58,14 +62,14 @@ class DatabaseTest extends SapphireTest {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function testSchemaUpdateChecking() {
|
function testSchemaUpdateChecking() {
|
||||||
$db = DB::getConn();
|
$db = DB::getConn();
|
||||||
|
|
||||||
// Initially, no schema changes necessary
|
// Initially, no schema changes necessary
|
||||||
$db->beginSchemaUpdate();
|
$db->beginSchemaUpdate();
|
||||||
$this->assertFalse($db->doesSchemaNeedUpdating());
|
$this->assertFalse($db->doesSchemaNeedUpdating());
|
||||||
|
|
||||||
// If we make a change, then the schema will need updating
|
// If we make a change, then the schema will need updating
|
||||||
$db->transCreateTable("TestTable");
|
$db->transCreateTable("TestTable");
|
||||||
$this->assertTrue($db->doesSchemaNeedUpdating());
|
$this->assertTrue($db->doesSchemaNeedUpdating());
|
||||||
@ -74,18 +78,18 @@ class DatabaseTest extends SapphireTest {
|
|||||||
$db->cancelSchemaUpdate();
|
$db->cancelSchemaUpdate();
|
||||||
$this->assertFalse($db->doesSchemaNeedUpdating());
|
$this->assertFalse($db->doesSchemaNeedUpdating());
|
||||||
}
|
}
|
||||||
|
|
||||||
function testHasTable() {
|
function testHasTable() {
|
||||||
$this->assertTrue(DB::getConn()->hasTable('DatabaseTest_MyObject'));
|
$this->assertTrue(DB::getConn()->hasTable('DatabaseTest_MyObject'));
|
||||||
$this->assertFalse(DB::getConn()->hasTable('asdfasdfasdf'));
|
$this->assertFalse(DB::getConn()->hasTable('asdfasdfasdf'));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class DatabaseTest_MyObject extends DataObject implements TestOnly {
|
class DatabaseTest_MyObject extends DataObject implements TestOnly {
|
||||||
|
|
||||||
static $create_table_options = array('MySQLDatabase' => 'ENGINE=InnoDB');
|
static $create_table_options = array('MySQLDatabase' => 'ENGINE=InnoDB');
|
||||||
|
|
||||||
static $db = array(
|
static $db = array(
|
||||||
'MyField' => 'Varchar'
|
'MyField' => 'Varchar'
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user