diff --git a/dev/TestRunner.php b/dev/TestRunner.php index 697370bae..f05feb717 100644 --- a/dev/TestRunner.php +++ b/dev/TestRunner.php @@ -31,6 +31,7 @@ class TestRunner extends Controller { 'coverage' => 'coverageAll', 'sessionloadyml' => 'sessionloadyml', 'startsession' => 'startsession', + 'selectsession' => 'selectsession', 'endsession' => 'endsession', 'cleanupdb' => 'cleanupdb', 'emptydb' => 'emptydb', @@ -48,6 +49,7 @@ class TestRunner extends Controller { 'coverageModule', 'coverageOnly', 'startsession', + 'selectsession', 'endsession', 'cleanupdb', 'module', @@ -423,6 +425,54 @@ HTML; return "

dev/tests/emptydb can only be used with a temporary database. Perhaps you should use dev/tests/startsession first?

"; } } + + function selectsession() { + if(!Director::isLive()) { + $tempDir = '/tmp'; + $testSessionsDir = $tempDir . DIRECTORY_SEPARATOR . 'testsessions'; + + if (!is_dir($testSessionsDir)) { + return "

There are no test sessions available to select from.

"; + } + + if(!isset($_POST['testSessionKey'])) { + $me = Director::baseURL() . "dev/tests/selectsession"; + return << +

Enter a testSessionKey to select test session associated with that key. Don't forget to visit dev/tests/endsession when you're done!

+ +

+ +HTML; + } else { + $testSessionKey = $_POST['testSessionKey']; + + $testSessionFile = $testSessionsDir . DIRECTORY_SEPARATOR . $testSessionKey; + + if (!is_file($testSessionFile) || !is_readable($testSessionFile)) { + return "

Invalid session key.

"; + } + + $testSessionDict = json_decode(file_get_contents($testSessionFile)); + if (!isset($testSessionDict->databaseConfig, $testSessionDict->databaseConfig->database)) { + return "

Invalid database config.

"; + } + + DB::set_alternative_database_name($testSessionDict->databaseConfig->database); + + return "

Selected test session $testSessionKey.

+

Time to start testing; where would you like to start?

+ "; + } + } else { + return "

setdb can only be used on dev and test sites

"; + } + } function endsession() { SapphireTest::kill_temp_db();