/**
  * Test that the base class can be detected under various circumstances
  */
 public function testBaseClassDetection()
 {
     // Explicit DataObject
     $field1 = new DBClassName('MyClass', 'DataObject');
     $this->assertEquals('DataObject', $field1->getBaseClass());
     $this->assertNotEquals('DataObject', $field1->getDefault());
     // Explicit base class
     $field2 = new DBClassName('MyClass', 'DBClassNameTest_Object');
     $this->assertEquals('DBClassNameTest_Object', $field2->getBaseClass());
     $this->assertEquals('DBClassNameTest_Object', $field2->getDefault());
     // Explicit subclass
     $field3 = new DBClassName('MyClass');
     $field3->setValue(null, new DBClassNameTest_ObjectSubClass());
     $this->assertEquals('DBClassNameTest_Object', $field3->getBaseClass());
     $this->assertEquals('DBClassNameTest_Object', $field3->getDefault());
     // Implicit table
     $field4 = new DBClassName('MyClass');
     $field4->setTable('DBClassNameTest_ObjectSubClass_versions');
     $this->assertEquals('DBClassNameTest_Object', $field4->getBaseClass());
     $this->assertEquals('DBClassNameTest_Object', $field4->getDefault());
     // Missing
     $field5 = new DBClassName('MyClass');
     $this->assertEquals('DataObject', $field5->getBaseClass());
     $this->assertNotEquals('DataObject', $field5->getDefault());
     // Invalid class
     $field6 = new DBClassName('MyClass');
     $field6->setTable('InvalidTable');
     $this->assertEquals('DataObject', $field6->getBaseClass());
     $this->assertNotEquals('DataObject', $field6->getDefault());
     // Custom default_classname
     $field7 = new DBClassName('MyClass');
     $field7->setTable('DBClassNameTest_CustomDefault');
     $this->assertEquals('DBClassNameTest_CustomDefault', $field7->getBaseClass());
     $this->assertEquals('DBClassNameTest_CustomDefaultSubclass', $field7->getDefault());
 }
 /**
  * Clear all cached classname specs. It's necessary to clear all cached subclassed names
  * for any classes if a new class manifest is generated.
  */
 public static function clear_classname_cache()
 {
     self::$classname_cache = array();
 }
 /**
  * Reset all global caches associated with DataObject.
  */
 public static function reset()
 {
     DBClassName::clear_classname_cache();
     self::$_cache_has_own_table = array();
     self::$_cache_get_one = array();
     self::$_cache_composite_fields = array();
     self::$_cache_database_fields = array();
     self::$_cache_get_class_ancestry = array();
     self::$_cache_field_labels = array();
 }
 /**
  * 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();
 }
 public function testDatabaseIsReadyWithInsufficientMemberColumns()
 {
     $old = Security::$force_database_is_ready;
     Security::$force_database_is_ready = null;
     Security::$database_is_ready = false;
     DBClassName::clear_classname_cache();
     // Assumption: The database has been built correctly by the test runner,
     // and has all columns present in the ORM
     DB::get_schema()->renameField('Member', 'Email', 'Email_renamed');
     // Email column is now missing, which means we're not ready to do permission checks
     $this->assertFalse(Security::database_is_ready());
     // Rebuild the database (which re-adds the Email column), and try again
     $this->resetDBSchema(true);
     $this->assertTrue(Security::database_is_ready());
     Security::$force_database_is_ready = $old;
 }