API CHANGE: Don't generate TestOnly DataObjects in the database immediately; instead let test developers specify them in SapphireTest::$extraDataObjects.

API CHANGE: Added SapphireTest::resetDBSchema() (from r90054)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@96734 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2010-01-12 23:16:14 +00:00
parent 675942261a
commit 63096cfefb
28 changed files with 228 additions and 48 deletions

View File

@ -46,6 +46,10 @@ class ClassInfo {
} }
} }
static function reset_db_cache() {
self::$_cache_all_tables = null;
}
/** /**
* Returns the manifest of all classes which are present in the database. * Returns the manifest of all classes which are present in the database.
*/ */
@ -70,15 +74,15 @@ class ClassInfo {
if(!$_ALL_CLASSES['parents'][$class]) user_error("ClassInfo::dataClassesFor() no parents for $class", E_USER_WARNING); if(!$_ALL_CLASSES['parents'][$class]) user_error("ClassInfo::dataClassesFor() no parents for $class", E_USER_WARNING);
foreach($_ALL_CLASSES['parents'][$class] as $subclass) { foreach($_ALL_CLASSES['parents'][$class] as $subclass) {
if(DataObject::has_own_table($subclass)) $dataClasses[] = $subclass; if(self::hasTable($subclass)) $dataClasses[] = $subclass;
} }
if(DataObject::has_own_table($class)) $dataClasses[] = $class; if(self::hasTable($class)) $dataClasses[] = $class;
if(isset($_ALL_CLASSES['children'][$class])) if(isset($_ALL_CLASSES['children'][$class]))
foreach($_ALL_CLASSES['children'][$class] as $subclass) foreach($_ALL_CLASSES['children'][$class] as $subclass)
{ {
if(DataObject::has_own_table($subclass)) $dataClasses[] = $subclass; if(self::hasTable($subclass)) $dataClasses[] = $subclass;
} }
return $dataClasses; return $dataClasses;

View File

@ -225,6 +225,7 @@ class DatabaseAdmin extends Controller {
} }
if(!$quiet) echo "<p>Database build completed!</p>"; if(!$quiet) echo "<p>Database build completed!</p>";
ClassInfo::reset_db_cache();
} }
/** /**

View File

@ -38,12 +38,12 @@ class CliTestReporter extends SapphireTestReporter {
// Use sake dev/tests/all --showslow to show slow tests // Use sake dev/tests/all --showslow to show slow tests
if((isset($_GET['args']) && is_array($_GET['args']) && in_array('--showslow', $_GET['args'])) || isset($_GET['showslow'])) { if((isset($_GET['args']) && is_array($_GET['args']) && in_array('--showslow', $_GET['args'])) || isset($_GET['showslow'])) {
$avgSpeed = round(array_sum($this->testSpeeds) / count($this->testSpeeds), 3); $avgSpeed = round(array_sum($this->testSpeeds) / count($this->testSpeeds), 3);
echo "Slow tests (more than twice the average $avgSpeed seconds):\n"; echo "Slow tests (more than the average $avgSpeed seconds):\n";
arsort($this->testSpeeds); arsort($this->testSpeeds);
foreach($this->testSpeeds as $k => $v) { foreach($this->testSpeeds as $k => $v) {
// Ignore below-average speeds // Ignore below-average speeds
if($v < $avgSpeed*2) break; if($v < $avgSpeed) break;
echo " - $k: " . round($v,3) . "\n"; echo " - $k: " . round($v,3) . "\n";
} }

View File

@ -52,6 +52,13 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
protected $requiredExtensions = array( protected $requiredExtensions = array(
); );
/**
* By default, the test database won't contain any DataObjects that have the interface TestOnly.
* This variable lets you define additional TestOnly DataObjects to set up for this test.
* Set it to an array of DataObject subclass names.
*/
protected $extraDataObjects = array();
/** /**
* We need to disabling backing up of globals to avoid overriding * We need to disabling backing up of globals to avoid overriding
* the few globals SilverStripe relies on, like $lang for the i18n subsystem. * the few globals SilverStripe relies on, like $lang for the i18n subsystem.
@ -166,15 +173,8 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
} }
// If we have made changes to the extensions present, then migrate the database schema. // If we have made changes to the extensions present, then migrate the database schema.
if($this->extensionsToReapply || $this->extensionsToRemove) { if($this->extensionsToReapply || $this->extensionsToRemove || $this->extraDataObjects) {
// clear singletons, they're caching old extension info which is used in DatabaseAdmin->doBuild() $this->resetDBSchema(true);
global $_SINGLETONS;
$_SINGLETONS = array();
// rebuild the db schema
$dbadmin = new DatabaseAdmin();
$dbadmin->doBuild(true, false, true);
singleton('DataObject')->flushCache();
} }
// clear singletons, they're caching old extension info // clear singletons, they're caching old extension info
// which is used in DatabaseAdmin->doBuild() // which is used in DatabaseAdmin->doBuild()
@ -201,14 +201,10 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
Object::add_extension($class, $extension); Object::add_extension($class, $extension);
} }
} }
}
// clear singletons, they're caching old extension info which is used in DatabaseAdmin->doBuild() if($this->extensionsToReapply || $this->extensionsToRemove || $this->extraDataObjects) {
global $_SINGLETONS; $this->resetDBSchema();
$_SINGLETONS = array();
// rebuild the db schema
$dbadmin = new DatabaseAdmin();
$dbadmin->doBuild(true, false, true);
} }
} }
@ -569,8 +565,7 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
$dbConn->selectDatabase($dbname); $dbConn->selectDatabase($dbname);
$dbConn->createDatabase(); $dbConn->createDatabase();
$dbadmin = new DatabaseAdmin(); singleton('SapphireTest')->resetDBSchema();
$dbadmin->doBuild(true, false, true);
return $dbname; return $dbname;
} }
@ -585,6 +580,46 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
} }
} }
/**
* Reset the testing database's schema.
* @param $includeExtraDataObjects If true, the extraDataObjects tables will also be included
*/
function resetDBSchema($includeExtraDataObjects = false) {
if(self::using_temp_db()) {
// clear singletons, they're caching old extension info which is used in DatabaseAdmin->doBuild()
global $_SINGLETONS;
$_SINGLETONS = array();
$dataClasses = ClassInfo::subclassesFor('DataObject');
array_shift($dataClasses);
$conn = DB::getConn();
$conn->beginSchemaUpdate();
DB::quiet();
foreach($dataClasses as $dataClass) {
// Check if class exists before trying to instantiate - this sidesteps any manifest weirdness
if(class_exists($dataClass)) {
$SNG = singleton($dataClass);
if(!($SNG instanceof TestOnly)) $SNG->requireTable();
}
}
// If we have additional dataobjects which need schema, do so here:
if($includeExtraDataObjects && $this->extraDataObjects) {
foreach($this->extraDataObjects as $dataClass) {
$SNG = singleton($dataClass);
if(singleton($dataClass) instanceof DataObject) $SNG->requireTable();
}
}
$conn->endSchemaUpdate();
ClassInfo::reset_db_cache();
singleton('DataObject')->flushCache();
}
}
/** /**
* Create a member and group with the given permission code, and log in with it. * Create a member and group with the given permission code, and log in with it.
* Returns the member ID. * Returns the member ID.

View File

@ -1,7 +1,15 @@
<?php <?php
class DataObjectDecoratorTest extends SapphireTest { class DataObjectDecoratorTest extends SapphireTest {
static $fixture_file = 'sapphire/tests/DataObjectDecoratorTest.yml'; static $fixture_file = 'sapphire/tests/DataObjectDecoratorTest.yml';
protected $extraDataObjects = array(
'DataObjectDecoratorTest_Member',
'DataObjectDecoratorTest_Player',
'DataObjectDecoratorTest_RelatedObject',
'DataObjectDecoratorTest_MyObject',
);
function testOneToManyAssociationWithDecorator() { function testOneToManyAssociationWithDecorator() {
// Fails in RestfulServerTest // Fails in RestfulServerTest
// Error: Object::__call() Method 'RelatedObjects' not found in class 'RestfulServerTest_Comment' // Error: Object::__call() Method 'RelatedObjects' not found in class 'RestfulServerTest_Comment'
@ -66,8 +74,7 @@ class DataObjectDecoratorTest extends SapphireTest {
Object::add_extension('DataObjectDecoratorTest_Player', 'DataObjectDecoratorTest_PlayerDecorator'); Object::add_extension('DataObjectDecoratorTest_Player', 'DataObjectDecoratorTest_PlayerDecorator');
// Now that we've just added the decorator, we need to rebuild the database // Now that we've just added the decorator, we need to rebuild the database
$da = new DatabaseAdmin(); $this->resetDBSchema(true);
$da->doBuild(true, false, true);
// Create a test record with decorated fields, writing to the DB // Create a test record with decorated fields, writing to the DB
$player = new DataObjectDecoratorTest_Player(); $player = new DataObjectDecoratorTest_Player();

View File

@ -9,6 +9,12 @@ class DataObjectSetTest extends SapphireTest {
static $fixture_file = 'sapphire/tests/DataObjectTest.yml'; static $fixture_file = 'sapphire/tests/DataObjectTest.yml';
protected $extraDataObjects = array(
'DataObjectTest_Team',
'DataObjectTest_SubTeam',
'DataObjectTest_Player',
);
function testIterator() { function testIterator() {
$set = new DataObjectSet(array( $set = new DataObjectSet(array(
$one = new DataObject(array('Title'=>'one')), $one = new DataObject(array('Title'=>'one')),

View File

@ -7,6 +7,17 @@ class DataObjectTest extends SapphireTest {
static $fixture_file = 'sapphire/tests/DataObjectTest.yml'; static $fixture_file = 'sapphire/tests/DataObjectTest.yml';
protected $extraDataObjects = array(
'DataObjectTest_Team',
'DataObjectTest_Fixture',
'DataObjectTest_SubTeam',
'OtherSubclassWithSameField',
'DataObjectTest_FieldlessTable',
'DataObjectTest_FieldlessSubTable',
'DataObjectTest_ValidatedObject',
'DataObjectTest_Player',
);
/** /**
* Test deletion of DataObjects * Test deletion of DataObjects
* - Deleting using delete() on the DataObject * - Deleting using delete() on the DataObject
@ -949,7 +960,7 @@ class DataObjectTest_SubTeam extends DataObjectTest_Team implements TestOnly {
'SubclassDatabaseField' => 'Varchar' 'SubclassDatabaseField' => 'Varchar'
); );
} }
class OtherSubclassWithSameField extends DataObjectTest_Team { class OtherSubclassWithSameField extends DataObjectTest_Team implements TestOnly {
static $db = array( static $db = array(
'SubclassDatabaseField' => 'Varchar', 'SubclassDatabaseField' => 'Varchar',
); );

View File

@ -4,6 +4,10 @@ class SQLQueryTest extends SapphireTest {
static $fixture_file = null; static $fixture_file = null;
protected $extraDataObjects = array(
'SQLQueryTest_DO',
);
function testEmptyQueryReturnsNothing() { function testEmptyQueryReturnsNothing() {
$query = new SQLQuery(); $query = new SQLQuery();
$this->assertEquals('', $query->sql()); $this->assertEquals('', $query->sql());

View File

@ -4,6 +4,16 @@ class SearchContextTest extends SapphireTest {
static $fixture_file = 'sapphire/tests/SearchContextTest.yml'; static $fixture_file = 'sapphire/tests/SearchContextTest.yml';
protected $extraDataObjects = array(
'SearchContextTest_Person',
'SearchContextTest_Book',
'SearchContextTest_Company',
'SearchContextTest_Project',
'SearchContextTest_Deadline',
'SearchContextTest_Action',
'SearchContextTest_AllFilterTypes',
);
function testResultSetFilterReturnsExpectedCount() { function testResultSetFilterReturnsExpectedCount() {
$person = singleton('SearchContextTest_Person'); $person = singleton('SearchContextTest_Person');
$context = $person->getDefaultSearchContext(); $context = $person->getDefaultSearchContext();

View File

@ -12,6 +12,11 @@ class SoapModelAccessTest extends SapphireTest {
static $fixture_file = 'sapphire/tests/SoapModelAccessTest.yml'; static $fixture_file = 'sapphire/tests/SoapModelAccessTest.yml';
protected $extraDataObjects = array(
'SoapModelAccessTest_Comment',
'SoapModelAccessTest_Page',
);
public function getTestSoapConnection() { public function getTestSoapConnection() {
// We can't actually test the SOAP server itself because there's not currently a way of putting it into "test mode" // We can't actually test the SOAP server itself because there's not currently a way of putting it into "test mode"
return new SOAPModelAccess(); return new SOAPModelAccess();

View File

@ -10,6 +10,14 @@ class RestfulServerTest extends SapphireTest {
static $fixture_file = 'sapphire/tests/api/RestfulServerTest.yml'; static $fixture_file = 'sapphire/tests/api/RestfulServerTest.yml';
protected $extraDataObjects = array(
'RestfulServerTest_Comment',
'RestfulServerTest_SecretThing',
'RestfulServerTest_Page',
'RestfulServerTest_Author',
'RestfulServerTest_AuthorRating',
);
public function testApiAccess() { public function testApiAccess() {
$comment1 = $this->objFromFixture('RestfulServerTest_Comment', 'comment1'); $comment1 = $this->objFromFixture('RestfulServerTest_Comment', 'comment1');
$page1 = $this->objFromFixture('RestfulServerTest_Page', 'page1'); $page1 = $this->objFromFixture('RestfulServerTest_Page', 'page1');

View File

@ -7,6 +7,12 @@
class CsvBulkLoaderTest extends SapphireTest { class CsvBulkLoaderTest extends SapphireTest {
static $fixture_file = 'sapphire/tests/dev/CsvBulkLoaderTest.yml'; static $fixture_file = 'sapphire/tests/dev/CsvBulkLoaderTest.yml';
protected $extraDataObjects = array(
'CsvBulkLoaderTest_Team',
'CsvBulkLoaderTest_Player',
'CsvBulkLoaderTest_PlayerContract',
);
// /** // /**
// * Test plain import with column auto-detection // * Test plain import with column auto-detection
// */ // */

View File

@ -5,6 +5,10 @@
*/ */
class CheckboxFieldTest extends SapphireTest { class CheckboxFieldTest extends SapphireTest {
protected $extraDataObjects = array(
'CheckboxFieldTest_Article',
);
function testFieldValueTrue() { function testFieldValueTrue() {
/* Create the field, and set the value as boolean true */ /* Create the field, and set the value as boolean true */
$field = new CheckboxField('IsChecked', 'Checked'); $field = new CheckboxField('IsChecked', 'Checked');

View File

@ -4,9 +4,13 @@
* @subpackage tests * @subpackage tests
*/ */
class CheckboxSetFieldTest extends SapphireTest { class CheckboxSetFieldTest extends SapphireTest {
static $fixture_file = 'sapphire/tests/forms/CheckboxSetFieldTest.yml'; static $fixture_file = 'sapphire/tests/forms/CheckboxSetFieldTest.yml';
protected $extraDataObjects = array(
'CheckboxSetFieldTest_Article',
'CheckboxSetFieldTest_Tag',
);
function testAddExtraClass() { function testAddExtraClass() {
/* CheckboxSetField has an extra class name and is in the HTML the field returns */ /* CheckboxSetField has an extra class name and is in the HTML the field returns */
$cboxSetField = new CheckboxSetField('FeelingOk', 'Are you feeling ok?', array(0 => 'No', 1 => 'Yes'), '', null, '(Select one)'); $cboxSetField = new CheckboxSetField('FeelingOk', 'Are you feeling ok?', array(0 => 'No', 1 => 'Yes'), '', null, '(Select one)');

View File

@ -8,6 +8,12 @@ class ComplexTableFieldTest extends FunctionalTest {
static $fixture_file = 'sapphire/tests/forms/ComplexTableFieldTest.yml'; static $fixture_file = 'sapphire/tests/forms/ComplexTableFieldTest.yml';
static $use_draft_site = true; static $use_draft_site = true;
protected $extraDataObjects = array(
'ComplexTableFieldTest_Player',
'ComplexTableFieldTest_Team',
'ComplexTableFieldTest_Sponsor',
);
/** /**
* An instance of {@link Controller} used for * An instance of {@link Controller} used for
* running tests against. * running tests against.

View File

@ -11,6 +11,13 @@ class FormScaffolderTest extends SapphireTest {
static $fixture_file = 'sapphire/tests/forms/FormScaffolderTest.yml'; static $fixture_file = 'sapphire/tests/forms/FormScaffolderTest.yml';
protected $extraDataObjects = array(
'FormScaffolderTest_Article',
'FormScaffolderTest_Tag',
'FormScaffolderTest_Author',
);
function testGetCMSFieldsSingleton() { function testGetCMSFieldsSingleton() {
$fields = singleton('FormScaffolderTest_Article')->getCMSFields(); $fields = singleton('FormScaffolderTest_Article')->getCMSFields();
$this->assertTrue($fields->hasTabSet(), 'getCMSFields() produces a TabSet'); $this->assertTrue($fields->hasTabSet(), 'getCMSFields() produces a TabSet');

View File

@ -7,6 +7,11 @@ class FormTest extends FunctionalTest {
static $fixture_file = 'sapphire/tests/forms/FormTest.yml'; static $fixture_file = 'sapphire/tests/forms/FormTest.yml';
protected $extraDataObjects = array(
'FormTest_Player',
'FormTest_Team',
);
public function testLoadDataFromRequest() { public function testLoadDataFromRequest() {
$form = new Form( $form = new Form(
new Controller(), new Controller(),

View File

@ -4,6 +4,12 @@
* @subpackage tests * @subpackage tests
*/ */
class MoneyFieldTest extends SapphireTest { class MoneyFieldTest extends SapphireTest {
protected $extraDataObjects = array(
'MoneyFieldTest_Object',
'MoneyFieldTest_CustomSetter_Object',
);
function testSaveInto() { function testSaveInto() {
$o = new MoneyFieldTest_Object(); $o = new MoneyFieldTest_Object();

View File

@ -3,6 +3,11 @@
class TableFieldTest extends SapphireTest { class TableFieldTest extends SapphireTest {
static $fixture_file = 'sapphire/tests/forms/TableFieldTest.yml'; static $fixture_file = 'sapphire/tests/forms/TableFieldTest.yml';
protected $extraDataObjects = array(
'TableFieldTest_Object',
'TableFieldTest_HasManyRelation',
);
function testAdd() { function testAdd() {
$group = $this->objFromFixture('Group','group1_no_perms'); $group = $this->objFromFixture('Group','group1_no_perms');

View File

@ -3,6 +3,11 @@
class TableListFieldTest extends SapphireTest { class TableListFieldTest extends SapphireTest {
static $fixture_file = 'sapphire/tests/forms/TableListFieldTest.yml'; static $fixture_file = 'sapphire/tests/forms/TableListFieldTest.yml';
protected $extraDataObjects = array(
'TableListFieldTest_Obj',
'TableListFieldTest_CsvExport',
);
function testCanReferenceCustomMethodsAndFieldsOnObject() { function testCanReferenceCustomMethodsAndFieldsOnObject() {
$table = new TableListField("Tester", "TableListFieldTest_Obj", array( $table = new TableListField("Tester", "TableListFieldTest_Obj", array(
"A" => "Col A", "A" => "Col A",

View File

@ -18,6 +18,11 @@ class i18nTest extends SapphireTest {
*/ */
protected $alternateBasePath; protected $alternateBasePath;
protected $extraDataObjects = array(
'i18nTest_DataObject'
);
function setUp() { function setUp() {
parent::setUp(); parent::setUp();

View File

@ -4,6 +4,12 @@
* @subpackage tests * @subpackage tests
*/ */
class CompositeDBFieldTest extends SapphireTest { class CompositeDBFieldTest extends SapphireTest {
protected $extraDataObjects = array(
'CompositeDBFieldTest_DataObject',
'SubclassedDBFieldObject',
);
function testHasDatabaseFieldOnDataObject() { function testHasDatabaseFieldOnDataObject() {
$obj = singleton('CompositeDBFieldTest_DataObject'); $obj = singleton('CompositeDBFieldTest_DataObject');

View File

@ -5,6 +5,10 @@
*/ */
class DatabaseTest extends SapphireTest { class DatabaseTest extends SapphireTest {
protected $extraDataObjects = array(
'DatabaseTest_MyObject',
);
function testDontRequireField() { function testDontRequireField() {
$conn = DB::getConn(); $conn = DB::getConn();
$this->assertArrayHasKey( $this->assertArrayHasKey(
@ -19,9 +23,7 @@ class DatabaseTest extends SapphireTest {
'Field is renamed to _obsolete_<fieldname> through dontRequireField()' 'Field is renamed to _obsolete_<fieldname> through dontRequireField()'
); );
// tested schema updates, so need to rebuild the database $this->resetDBSchema(true);
self::kill_temp_db();
self::create_temp_db();
} }
function testRenameField() { function testRenameField() {
@ -40,9 +42,7 @@ class DatabaseTest extends SapphireTest {
'Old fieldname isnt preserved through renameField()' 'Old fieldname isnt preserved through renameField()'
); );
// tested schema updates, so need to rebuild the database $this->resetDBSchema(true);
self::kill_temp_db();
self::create_temp_db();
} }
function testMySQLCreateTableOptions() { function testMySQLCreateTableOptions() {

View File

@ -15,6 +15,10 @@ class MoneyTest extends SapphireTest {
static $fixture_file = 'sapphire/tests/model/MoneyTest.yml'; static $fixture_file = 'sapphire/tests/model/MoneyTest.yml';
protected $extraDataObjects = array(
'MoneyTest_DataObject',
);
function testMoneyFieldsReturnedAsObjects() { function testMoneyFieldsReturnedAsObjects() {
$obj = $this->objFromFixture('MoneyTest_DataObject', 'test1'); $obj = $this->objFromFixture('MoneyTest_DataObject', 'test1');
$this->assertType('Money', $obj->MyMoney); $this->assertType('Money', $obj->MyMoney);

View File

@ -9,6 +9,11 @@ class TranslatableTest extends FunctionalTest {
static $fixture_file = 'sapphire/tests/model/TranslatableTest.yml'; static $fixture_file = 'sapphire/tests/model/TranslatableTest.yml';
protected $extraDataObjects = array(
'TranslatableTest_DataObject',
'TranslatableTest_Page',
);
protected $requiredExtensions = array( protected $requiredExtensions = array(
'SiteTree' => array('Translatable'), 'SiteTree' => array('Translatable'),
'TranslatableTest_DataObject' => array('Translatable'), 'TranslatableTest_DataObject' => array('Translatable'),

View File

@ -3,6 +3,10 @@
class VersionedTest extends SapphireTest { class VersionedTest extends SapphireTest {
static $fixture_file = 'sapphire/tests/model/VersionedTest.yml'; static $fixture_file = 'sapphire/tests/model/VersionedTest.yml';
protected $extraDataObjects = array(
'VersionedTest_DataObject',
);
function testForceChangeUpdatesVersion() { function testForceChangeUpdatesVersion() {
$page = $this->objFromFixture('Page', 'page3'); $page = $this->objFromFixture('Page', 'page3');
$oldVersion = $page->Version; $oldVersion = $page->Version;
@ -52,7 +56,7 @@ class VersionedTest extends SapphireTest {
} }
class VersionedTest_DataObject extends DataObject { class VersionedTest_DataObject extends DataObject implements TestOnly {
static $db = array( static $db = array(
"Name" => "Varchar", "Name" => "Varchar",
); );
@ -62,7 +66,7 @@ class VersionedTest_DataObject extends DataObject {
); );
} }
class VersionedTest_Subclass extends VersionedTest_DataObject { class VersionedTest_Subclass extends VersionedTest_DataObject implements TestOnly {
static $db = array( static $db = array(
"ExtraField" => "Varchar", "ExtraField" => "Varchar",
); );

View File

@ -11,6 +11,18 @@
class SearchFilterApplyRelationTest extends SapphireTest{ class SearchFilterApplyRelationTest extends SapphireTest{
static $fixture_file = 'sapphire/tests/search/SearchFilterApplyRelationTest.yml'; static $fixture_file = 'sapphire/tests/search/SearchFilterApplyRelationTest.yml';
protected $extraDataObjects = array(
'SearchFilterApplyRelationTest_DO',
'SearchFilterApplyRelationTest_HasOneParent',
'SearchFilterApplyRelationTest_HasOneChild',
'SearchFilterApplyRelationTest_HasOneGrantChild',
'SearchFilterApplyRelationTest_HasManyParent',
'SearchFilterApplyRelationTest_HasManyChild',
'SearchFilterApplyRelationTest_HasManyGrantChild',
'SearchFilterApplyRelationTest_ManyManyParent',
'SearchFilterApplyRelationTest_ManyManyChild',
'SearchFilterApplyRelationTest_ManyManyGrantChild',
);
function testApplyRelationHasOne(){ function testApplyRelationHasOne(){
@ -117,14 +129,14 @@ class SearchFilterApplyRelationTest_HasOneParent extends DataObject implements T
); );
} }
class SearchFilterApplyRelationTest_HasOneChild extends SearchFilterApplyRelationTest_HasOneParent{ class SearchFilterApplyRelationTest_HasOneChild extends SearchFilterApplyRelationTest_HasOneParent implements TestOnly {
// This is to create an seperate Table only. // This is to create an seperate Table only.
static $db = array( static $db = array(
"ChildField" => "Varchar" "ChildField" => "Varchar"
); );
} }
class SearchFilterApplyRelationTest_HasOneGrantChild extends SearchFilterApplyRelationTest_HasOneChild{ class SearchFilterApplyRelationTest_HasOneGrantChild extends SearchFilterApplyRelationTest_HasOneChild implements TestOnly {
// This is to create an seperate Table only. // This is to create an seperate Table only.
static $db = array( static $db = array(
"GrantChildField" => "Varchar" "GrantChildField" => "Varchar"
@ -140,7 +152,7 @@ class SearchFilterApplyRelationTest_HasManyParent extends DataObject implements
); );
} }
class SearchFilterApplyRelationTest_HasManyChild extends SearchFilterApplyRelationTest_HasManyParent{ class SearchFilterApplyRelationTest_HasManyChild extends SearchFilterApplyRelationTest_HasManyParent implements TestOnly {
// This is to create an seperate Table only. // This is to create an seperate Table only.
static $db = array( static $db = array(
"ChildField" => "Varchar" "ChildField" => "Varchar"
@ -159,14 +171,14 @@ class SearchFilterApplyRelationTest_ManyManyParent extends DataObject implements
); );
} }
class SearchFilterApplyRelationTest_ManyManyChild extends SearchFilterApplyRelationTest_ManyManyParent{ class SearchFilterApplyRelationTest_ManyManyChild extends SearchFilterApplyRelationTest_ManyManyParent implements TestOnly {
// This is to create an seperate Table only. // This is to create an seperate Table only.
static $db = array( static $db = array(
"ChildField" => "Varchar" "ChildField" => "Varchar"
); );
} }
class SearchFilterApplyRelationTest_ManyManyGrantChild extends SearchFilterApplyRelationTest_ManyManyChild{ class SearchFilterApplyRelationTest_ManyManyGrantChild extends SearchFilterApplyRelationTest_ManyManyChild implements TestOnly {
// This is to create an seperate Table only. // This is to create an seperate Table only.
static $db = array( static $db = array(
"GrantChildField" => "Varchar" "GrantChildField" => "Varchar"

View File

@ -3,6 +3,11 @@
class YamlFixtureTest extends SapphireTest { class YamlFixtureTest extends SapphireTest {
static $fixture_file = 'sapphire/tests/testing/YamlFixtureTest.yml'; static $fixture_file = 'sapphire/tests/testing/YamlFixtureTest.yml';
protected $extraDataObjects = array(
'YamlFixtureTest_DataObject',
'YamlFixtureTest_DataObjectRelation',
);
function testSQLInsert() { function testSQLInsert() {
$object1 = DataObject::get_by_id("YamlFixtureTest_DataObject", $this->idFromFixture("YamlFixtureTest_DataObject", "testobject1")); $object1 = DataObject::get_by_id("YamlFixtureTest_DataObject", $this->idFromFixture("YamlFixtureTest_DataObject", "testobject1"));
$this->assertTrue($object1->ManyMany()->Count() == 2, "Should be 2 items in this manymany relationship"); $this->assertTrue($object1->ManyMany()->Count() == 2, "Should be 2 items in this manymany relationship");
@ -11,7 +16,7 @@ class YamlFixtureTest extends SapphireTest {
} }
} }
class YamlFixtureTest_DataObject extends DataObject { class YamlFixtureTest_DataObject extends DataObject implements TestOnly {
static $db = array( static $db = array(
"Name" => "Varchar" "Name" => "Varchar"
); );
@ -20,7 +25,7 @@ class YamlFixtureTest_DataObject extends DataObject {
); );
} }
class YamlFixtureTest_DataObjectRelation extends DataObject { class YamlFixtureTest_DataObjectRelation extends DataObject implements TestOnly {
static $db = array( static $db = array(
"Name" => "Varchar" "Name" => "Varchar"
); );