diff --git a/core/control/Director.php b/core/control/Director.php index 9cb64e517..630c56c57 100644 --- a/core/control/Director.php +++ b/core/control/Director.php @@ -696,6 +696,10 @@ class Director { * * Dev mode can also be forced by putting ?isDev=1 in your URL, which will ask you to log in and then push the site into dev * mode for the remainder of the session. Putting ?isDev=0 onto the URL can turn it back. + * + * Test mode can also be forced by putting ?isTest=1 in your URL, which will ask you to log in and then push the site into test + * mode for the remainder of the session. Putting ?isTest=0 onto the URL can turn it back. + * * Generally speaking, these methods will be called from your _config.php file. * * Once the environment type is set, it can be checked with {@link Director::isDev()}, {@link Director::isTest()}, and @@ -778,12 +782,6 @@ class Director { if(isset($_SERVER['HTTP_HOST']) && in_array($_SERVER['HTTP_HOST'], Director::$dev_servers)) { return true; } - /* - // Check if we are running on one of the test servers - if(in_array($_SERVER['HTTP_HOST'], Director::$test_servers)) { - return true; - } - */ return false; } @@ -793,6 +791,15 @@ class Director { * For information about environment types, see {@link Director::set_environment_type()}. */ static function isTest() { + // Use ?isTest=1 to get test access on the live server, or explicitly set your environment + if(isset($_GET['isTest'])) { + if(Security::database_is_ready()) { + BasicAuth::requireLogin("SilverStripe developer access. Use your CMS login", "ADMIN"); + $_SESSION['isTest'] = $_GET['isTest']; + } else { + return true; + } + } if(self::isDev()) return false; if(self::$environment_type) { diff --git a/tests/DataObjectTest.php b/tests/DataObjectTest.php index d4bf94567..3c54bb316 100644 --- a/tests/DataObjectTest.php +++ b/tests/DataObjectTest.php @@ -154,6 +154,21 @@ class DataObjectTest extends SapphireTest { $this->assertTrue($comment->ParentID == $page->ID); } } + + function testHasOneRelationship() { + $team1 = $this->fixture->objFromFixture('DataObjectTest_Team', 'team1'); + $player1 = $this->fixture->objFromFixture('DataObjectTest_Player', 'player1'); + + // Add a captain to team 1 + $team1->setField('CaptainID', $player1->ID); + $team1->write(); + + $this->assertEquals($player1->ID, $team1->Captain()->ID, 'The captain exists for team 1'); + $this->assertEquals($player1->ID, $team1->getComponent('Captain')->ID, 'The captain exists through the component getter'); + + $this->assertEquals($team1->Captain()->FirstName, 'Player 1', 'Player 1 is the captain'); + $this->assertEquals($team1->getComponent('Captain')->FirstName, 'Player 1', 'Player 1 is the captain'); + } /** * @todo Test removeMany() and addMany() on $many_many relationships @@ -633,7 +648,7 @@ class DataObjectTest_Player extends Member implements TestOnly { static $has_one = array( 'FavouriteTeam' => 'DataObjectTest_Team', ); - + static $belongs_many_many = array( 'Teams' => 'DataObjectTest_Team' );