From 360176d23c53f79395cf51172f6b814cca76ab8c Mon Sep 17 00:00:00 2001 From: Geoff Munn Date: Wed, 12 Jan 2011 00:10:38 +0000 Subject: [PATCH] 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 --- tests/model/DatabaseTest.php | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/tests/model/DatabaseTest.php b/tests/model/DatabaseTest.php index 46647c373..3a34876f0 100644 --- a/tests/model/DatabaseTest.php +++ b/tests/model/DatabaseTest.php @@ -8,29 +8,33 @@ class DatabaseTest extends SapphireTest { protected $extraDataObjects = array( 'DatabaseTest_MyObject', ); - + protected $usesDatabase = true; - + 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_ through dontRequireField()' ); - + $this->resetDBSchema(true); } - + function testRenameField() { $conn = DB::getConn(); - + + //Reset our cached fieldlists: + $conn->clear_cached_fieldlist(); + $conn->renameField('DatabaseTest_MyObject', 'MyField', 'MyRenamedField'); $this->assertArrayHasKey( @@ -46,7 +50,7 @@ class DatabaseTest extends SapphireTest { $this->resetDBSchema(true); } - + function testMySQLCreateTableOptions() { if(DB::getConn() instanceof MySQLDatabase) { $ret = DB::query(sprintf( @@ -58,14 +62,14 @@ class DatabaseTest extends SapphireTest { ); } } - + function testSchemaUpdateChecking() { $db = DB::getConn(); // Initially, no schema changes necessary $db->beginSchemaUpdate(); $this->assertFalse($db->doesSchemaNeedUpdating()); - + // If we make a change, then the schema will need updating $db->transCreateTable("TestTable"); $this->assertTrue($db->doesSchemaNeedUpdating()); @@ -74,18 +78,18 @@ class DatabaseTest extends SapphireTest { $db->cancelSchemaUpdate(); $this->assertFalse($db->doesSchemaNeedUpdating()); } - + function testHasTable() { $this->assertTrue(DB::getConn()->hasTable('DatabaseTest_MyObject')); $this->assertFalse(DB::getConn()->hasTable('asdfasdfasdf')); } - + } class DatabaseTest_MyObject extends DataObject implements TestOnly { - + static $create_table_options = array('MySQLDatabase' => 'ENGINE=InnoDB'); - + static $db = array( 'MyField' => 'Varchar' );