コード例 #1
0
 /**
  * Test that the base class can be detected under various circumstances
  */
 public function testBaseClassDetection()
 {
     // Explicit DataObject
     $field1 = new DBClassName('MyClass', 'SilverStripe\\ORM\\DataObject');
     $this->assertEquals('SilverStripe\\ORM\\DataObject', $field1->getBaseClass());
     $this->assertNotEquals('SilverStripe\\ORM\\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('SilverStripe\\ORM\\DataObject', $field5->getBaseClass());
     $this->assertNotEquals('SilverStripe\\ORM\\DataObject', $field5->getDefault());
     // Invalid class
     $field6 = new DBClassName('MyClass');
     $field6->setTable('InvalidTable');
     $this->assertEquals('SilverStripe\\ORM\\DataObject', $field6->getBaseClass());
     $this->assertNotEquals('SilverStripe\\ORM\\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());
 }
コード例 #2
0
 /**
  * Reset all global caches associated with DataObject.
  */
 public static function reset()
 {
     // @todo Decouple these
     DBClassName::clear_classname_cache();
     ClassInfo::reset_db_cache();
     static::getSchema()->reset();
     self::$_cache_get_one = array();
     self::$_cache_field_labels = array();
 }
コード例 #3
0
 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
     /** @skipUpgrade */
     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;
 }
 /**
  * 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');
     /** @skipUpgrade */
     $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');
     /** @skipUpgrade */
     $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');
     /** @skipUpgrade */
     $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');
     /** @skipUpgrade */
     $this->assertEquals("DBClassName", $fields['ClassName']);
     $this->assertEquals(array('DataObjectSchemaGenerationTest_DO' => 'DataObjectSchemaGenerationTest_DO', 'DataObjectSchemaGenerationTest_IndexDO' => 'DataObjectSchemaGenerationTest_IndexDO'), $item1->dbObject('ClassName')->getEnum());
     $item1->delete();
     $item2->delete();
 }