/**
  * Tests the generation of the ClassName spec and ensure it's not unnecessarily influenced
  * by the order of classnames of existing records
  */
 public function testClassNameSpecGeneration()
 {
     // Test with blank entries
     DBClassName::clear_classname_cache();
     $do1 = new DataObjectSchemaGenerationTest_DO();
     $fields = DataObject::database_fields('DataObjectSchemaGenerationTest_DO');
     $this->assertEquals("DBClassName", $fields['ClassName']);
     $this->assertEquals(array('DataObjectSchemaGenerationTest_DO' => 'DataObjectSchemaGenerationTest_DO', 'DataObjectSchemaGenerationTest_IndexDO' => 'DataObjectSchemaGenerationTest_IndexDO'), $do1->dbObject('ClassName')->getEnum());
     // Test with instance of subclass
     $item1 = new DataObjectSchemaGenerationTest_IndexDO();
     $item1->write();
     DBClassName::clear_classname_cache();
     $fields = DataObject::database_fields('DataObjectSchemaGenerationTest_DO');
     $this->assertEquals("DBClassName", $fields['ClassName']);
     $this->assertEquals(array('DataObjectSchemaGenerationTest_DO' => 'DataObjectSchemaGenerationTest_DO', 'DataObjectSchemaGenerationTest_IndexDO' => 'DataObjectSchemaGenerationTest_IndexDO'), $item1->dbObject('ClassName')->getEnum());
     $item1->delete();
     // Test with instance of main class
     $item2 = new DataObjectSchemaGenerationTest_DO();
     $item2->write();
     DBClassName::clear_classname_cache();
     $fields = DataObject::database_fields('DataObjectSchemaGenerationTest_DO');
     $this->assertEquals("DBClassName", $fields['ClassName']);
     $this->assertEquals(array('DataObjectSchemaGenerationTest_DO' => 'DataObjectSchemaGenerationTest_DO', 'DataObjectSchemaGenerationTest_IndexDO' => 'DataObjectSchemaGenerationTest_IndexDO'), $item2->dbObject('ClassName')->getEnum());
     $item2->delete();
     // Test with instances of both classes
     $item1 = new DataObjectSchemaGenerationTest_IndexDO();
     $item1->write();
     $item2 = new DataObjectSchemaGenerationTest_DO();
     $item2->write();
     DBClassName::clear_classname_cache();
     $fields = DataObject::database_fields('DataObjectSchemaGenerationTest_DO');
     $this->assertEquals("DBClassName", $fields['ClassName']);
     $this->assertEquals(array('DataObjectSchemaGenerationTest_DO' => 'DataObjectSchemaGenerationTest_DO', 'DataObjectSchemaGenerationTest_IndexDO' => 'DataObjectSchemaGenerationTest_IndexDO'), $item1->dbObject('ClassName')->getEnum());
     $item1->delete();
     $item2->delete();
 }
 /**
  * Tests the generation of the ClassName spec and ensure it's not unnecessarily influenced
  * by the order of classnames of existing records
  */
 public function testClassNameSpecGeneration()
 {
     // Test with blank entries
     DataObject::clear_classname_spec_cache();
     $fields = DataObject::database_fields('DataObjectSchemaGenerationTest_DO');
     $this->assertEquals("Enum('DataObjectSchemaGenerationTest_DO, DataObjectSchemaGenerationTest_IndexDO')", $fields['ClassName']);
     // Test with instance of subclass
     $item1 = new DataObjectSchemaGenerationTest_IndexDO();
     $item1->write();
     DataObject::clear_classname_spec_cache();
     $fields = DataObject::database_fields('DataObjectSchemaGenerationTest_DO');
     $this->assertEquals("Enum('DataObjectSchemaGenerationTest_DO, DataObjectSchemaGenerationTest_IndexDO')", $fields['ClassName']);
     $item1->delete();
     // Test with instance of main class
     $item2 = new DataObjectSchemaGenerationTest_DO();
     $item2->write();
     DataObject::clear_classname_spec_cache();
     $fields = DataObject::database_fields('DataObjectSchemaGenerationTest_DO');
     $this->assertEquals("Enum('DataObjectSchemaGenerationTest_DO, DataObjectSchemaGenerationTest_IndexDO')", $fields['ClassName']);
     $item2->delete();
     // Test with instances of both classes
     $item1 = new DataObjectSchemaGenerationTest_IndexDO();
     $item1->write();
     $item2 = new DataObjectSchemaGenerationTest_DO();
     $item2->write();
     DataObject::clear_classname_spec_cache();
     $fields = DataObject::database_fields('DataObjectSchemaGenerationTest_DO');
     $this->assertEquals("Enum('DataObjectSchemaGenerationTest_DO, DataObjectSchemaGenerationTest_IndexDO')", $fields['ClassName']);
     $item1->delete();
     $item2->delete();
 }
 /**
  * Check that updates to a dataobject's indexes are reflected in DDL
  */
 public function testIndexesRerequestChanges()
 {
     $db = DB::getConn();
     DB::quiet();
     // Table will have been initially created by the $extraDataObjects setting
     // 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();
     $needsUpdating = $db->doesSchemaNeedUpdating();
     $db->cancelSchemaUpdate();
     $this->assertTrue($needsUpdating);
     // Restore old indexes
     DataObjectSchemaGenerationTest_IndexDO::$indexes = $oldIndexes;
 }