mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIXED: Cleaned up test case, made sure it initialised consistently and correctly
ADDED: Extra assertions to test case to ensure that different expressions of the same index definition were treated as non-changes.
This commit is contained in:
parent
30e15d11a7
commit
0e997d0285
@ -3,8 +3,17 @@
|
||||
class DataObjectSchemaGenerationTest extends SapphireTest {
|
||||
protected $extraDataObjects = array(
|
||||
'DataObjectSchemaGenerationTest_DO',
|
||||
'DataObjectSchemaGenerationTest_IndexDO'
|
||||
);
|
||||
|
||||
function setUpOnce() {
|
||||
|
||||
// enable fulltext option on this table
|
||||
Config::inst()->update('DataObjectSchemaGenerationTest_IndexDO', 'create_table_options', array('MySQLDatabase' => 'ENGINE=MyISAM'));
|
||||
|
||||
parent::setUpOnce();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that once a schema has been generated, then it doesn't need any more updating
|
||||
*/
|
||||
@ -12,21 +21,14 @@ class DataObjectSchemaGenerationTest extends SapphireTest {
|
||||
$db = DB::getConn();
|
||||
DB::quiet();
|
||||
|
||||
|
||||
// Table will have been initially created by the $extraDataObjects setting
|
||||
|
||||
// Verify that it doesn't need to be recreated
|
||||
$db->beginSchemaUpdate();
|
||||
$obj = new DataObjectSchemaGenerationTest_DO();
|
||||
$obj->requireTable();
|
||||
$db->endSchemaUpdate();
|
||||
|
||||
// Test table within this database
|
||||
$db->beginSchemaUpdate();
|
||||
$obj2 = new DataObjectSchemaGenerationTest_DO();
|
||||
$obj2->requireTable();
|
||||
$needsUpdating = $db->doesSchemaNeedUpdating();
|
||||
$db->cancelSchemaUpdate();
|
||||
|
||||
$this->assertFalse($needsUpdating);
|
||||
}
|
||||
|
||||
@ -37,25 +39,22 @@ class DataObjectSchemaGenerationTest extends SapphireTest {
|
||||
$db = DB::getConn();
|
||||
DB::quiet();
|
||||
|
||||
|
||||
// Table will have been initially created by the $extraDataObjects setting
|
||||
// Verify that it doesn't need to be recreated
|
||||
|
||||
// Let's insert a new field here
|
||||
$oldDB = DataObjectSchemaGenerationTest_DO::$db;
|
||||
DataObjectSchemaGenerationTest_DO::$db['SecretField'] = 'Varchar(100)';
|
||||
|
||||
// Verify that the above extra field triggered a schema update
|
||||
$db->beginSchemaUpdate();
|
||||
$obj = new DataObjectSchemaGenerationTest_DO();
|
||||
$obj->requireTable();
|
||||
$db->endSchemaUpdate();
|
||||
|
||||
// Let's insert a new field here
|
||||
DataObjectSchemaGenerationTest_DO::$db['SecretField'] = 'Varchar(100)';
|
||||
|
||||
// Test table within this database
|
||||
$db->beginSchemaUpdate();
|
||||
$obj2 = new DataObjectSchemaGenerationTest_DO();
|
||||
$obj2->requireTable();
|
||||
$needsUpdating = $db->doesSchemaNeedUpdating();
|
||||
$db->cancelSchemaUpdate();
|
||||
|
||||
$this->assertTrue($needsUpdating);
|
||||
|
||||
// Restore db configuration
|
||||
DataObjectSchemaGenerationTest_DO::$db = $oldDB;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,24 +64,30 @@ class DataObjectSchemaGenerationTest extends SapphireTest {
|
||||
$db = DB::getConn();
|
||||
DB::quiet();
|
||||
|
||||
// enable fulltext option on this table
|
||||
Config::inst()->update('DataObjectSchemaGenerationTest_IndexDO', 'create_table_options', array('MySQLDatabase' => 'ENGINE=MyISAM'));
|
||||
|
||||
// Table will have been initially created by the $extraDataObjects setting
|
||||
|
||||
// Verify that it doesn't need to be recreated
|
||||
$db->beginSchemaUpdate();
|
||||
$obj = new DataObjectSchemaGenerationTest_IndexDO();
|
||||
$obj->requireTable();
|
||||
$db->endSchemaUpdate();
|
||||
$needsUpdating = $db->doesSchemaNeedUpdating();
|
||||
$db->cancelSchemaUpdate();
|
||||
$this->assertFalse($needsUpdating);
|
||||
|
||||
// Test table within this database
|
||||
// Test with alternate index format, although these indexes are the same
|
||||
$oldIndexes = DataObjectSchemaGenerationTest_IndexDO::$indexes;
|
||||
DataObjectSchemaGenerationTest_IndexDO::$indexes = DataObjectSchemaGenerationTest_IndexDO::$indexes_alt;
|
||||
|
||||
// Verify that it still doesn't need to be recreated
|
||||
$db->beginSchemaUpdate();
|
||||
$obj2 = new DataObjectSchemaGenerationTest_IndexDO();
|
||||
$obj2->requireTable();
|
||||
$needsUpdating = $db->doesSchemaNeedUpdating();
|
||||
$db->cancelSchemaUpdate();
|
||||
|
||||
$this->assertFalse($needsUpdating);
|
||||
|
||||
// Restore old index format
|
||||
DataObjectSchemaGenerationTest_IndexDO::$indexes = $oldIndexes;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -92,29 +97,23 @@ class DataObjectSchemaGenerationTest extends SapphireTest {
|
||||
$db = DB::getConn();
|
||||
DB::quiet();
|
||||
|
||||
// enable fulltext option on this table
|
||||
Config::inst()->update('DataObjectSchemaGenerationTest_IndexDO', 'create_table_options', array('MySQLDatabase' => 'ENGINE=MyISAM'));
|
||||
|
||||
// Table will have been initially created by the $extraDataObjects setting
|
||||
// Verify that it doesn't need to be recreated
|
||||
|
||||
// Update the SearchFields index here
|
||||
$oldIndexes = DataObjectSchemaGenerationTest_IndexDO::$indexes;
|
||||
DataObjectSchemaGenerationTest_IndexDO::$indexes['SearchFields']['value'] = '"Title"';
|
||||
|
||||
// Verify that the above index change triggered a schema update
|
||||
$db->beginSchemaUpdate();
|
||||
$obj = new DataObjectSchemaGenerationTest_IndexDO();
|
||||
$obj->requireTable();
|
||||
$db->endSchemaUpdate();
|
||||
|
||||
// Let's insert a new field here
|
||||
DataObjectSchemaGenerationTest_IndexDO::$indexes['SearchFields']['value'] = '"Title"';
|
||||
|
||||
// Test table within this database
|
||||
$db->beginSchemaUpdate();
|
||||
$obj2 = new DataObjectSchemaGenerationTest_IndexDO();
|
||||
$obj2->requireTable();
|
||||
$needsUpdating = $db->doesSchemaNeedUpdating();
|
||||
$db->cancelSchemaUpdate();
|
||||
|
||||
$this->assertTrue($needsUpdating);
|
||||
}
|
||||
|
||||
// Restore old indexes
|
||||
DataObjectSchemaGenerationTest_IndexDO::$indexes = $oldIndexes;
|
||||
}
|
||||
}
|
||||
|
||||
class DataObjectSchemaGenerationTest_DO extends DataObject implements TestOnly {
|
||||
@ -132,7 +131,6 @@ class DataObjectSchemaGenerationTest_IndexDO extends DataObjectSchemaGenerationT
|
||||
);
|
||||
|
||||
static $indexes = array(
|
||||
// Space between 'unique' and '("Name")' is critical. @todo - Robustify?
|
||||
'NameIndex' => 'unique ("Title")',
|
||||
'SearchFields' => array(
|
||||
'type' => 'fulltext',
|
||||
@ -141,4 +139,12 @@ class DataObjectSchemaGenerationTest_IndexDO extends DataObjectSchemaGenerationT
|
||||
)
|
||||
);
|
||||
|
||||
static $indexes_alt = array(
|
||||
'NameIndex' => array(
|
||||
'type' => 'unique',
|
||||
'name' => 'NameIndex',
|
||||
'value' => '"Title"'
|
||||
),
|
||||
'SearchFields' => 'fulltext ("Title","Content")'
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue
Block a user