mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
NEW add selectsession URL endpoint
This endpoint should be passed a testSessionKey POST parameter. testSessionKey is an indicator for /tmp/testsessions/<testSessionKey> file which stores temp database config. https://github.com/michalochman/SilverStripe-Behaviour-Testing-Framework/issues/27
This commit is contained in:
parent
9b15bac8f3
commit
766b03f360
@ -31,6 +31,7 @@ class TestRunner extends Controller {
|
|||||||
'coverage' => 'coverageAll',
|
'coverage' => 'coverageAll',
|
||||||
'sessionloadyml' => 'sessionloadyml',
|
'sessionloadyml' => 'sessionloadyml',
|
||||||
'startsession' => 'startsession',
|
'startsession' => 'startsession',
|
||||||
|
'selectsession' => 'selectsession',
|
||||||
'endsession' => 'endsession',
|
'endsession' => 'endsession',
|
||||||
'cleanupdb' => 'cleanupdb',
|
'cleanupdb' => 'cleanupdb',
|
||||||
'emptydb' => 'emptydb',
|
'emptydb' => 'emptydb',
|
||||||
@ -48,6 +49,7 @@ class TestRunner extends Controller {
|
|||||||
'coverageModule',
|
'coverageModule',
|
||||||
'coverageOnly',
|
'coverageOnly',
|
||||||
'startsession',
|
'startsession',
|
||||||
|
'selectsession',
|
||||||
'endsession',
|
'endsession',
|
||||||
'cleanupdb',
|
'cleanupdb',
|
||||||
'module',
|
'module',
|
||||||
@ -423,6 +425,54 @@ HTML;
|
|||||||
return "<p>dev/tests/emptydb can only be used with a temporary database. Perhaps you should use dev/tests/startsession first?</p>";
|
return "<p>dev/tests/emptydb can only be used with a temporary database. Perhaps you should use dev/tests/startsession first?</p>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function selectsession() {
|
||||||
|
if(!Director::isLive()) {
|
||||||
|
$tempDir = '/tmp';
|
||||||
|
$testSessionsDir = $tempDir . DIRECTORY_SEPARATOR . 'testsessions';
|
||||||
|
|
||||||
|
if (!is_dir($testSessionsDir)) {
|
||||||
|
return "<p>There are no test sessions available to select from.</p>";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!isset($_POST['testSessionKey'])) {
|
||||||
|
$me = Director::baseURL() . "dev/tests/selectsession";
|
||||||
|
return <<<HTML
|
||||||
|
<form action="$me" method="post">
|
||||||
|
<p>Enter a testSessionKey to select test session associated with that key. Don't forget to visit dev/tests/endsession when you're done!</p>
|
||||||
|
<input type="text" id="testSessionKey" name="testSessionKey" value="">
|
||||||
|
<p><input id="select-session" value="Select test session" type="submit" /></p>
|
||||||
|
</form>
|
||||||
|
HTML;
|
||||||
|
} else {
|
||||||
|
$testSessionKey = $_POST['testSessionKey'];
|
||||||
|
|
||||||
|
$testSessionFile = $testSessionsDir . DIRECTORY_SEPARATOR . $testSessionKey;
|
||||||
|
|
||||||
|
if (!is_file($testSessionFile) || !is_readable($testSessionFile)) {
|
||||||
|
return "<p>Invalid session key.</p>";
|
||||||
|
}
|
||||||
|
|
||||||
|
$testSessionDict = json_decode(file_get_contents($testSessionFile));
|
||||||
|
if (!isset($testSessionDict->databaseConfig, $testSessionDict->databaseConfig->database)) {
|
||||||
|
return "<p>Invalid database config.</p>";
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::set_alternative_database_name($testSessionDict->databaseConfig->database);
|
||||||
|
|
||||||
|
return "<p>Selected test session $testSessionKey.</p>
|
||||||
|
<p>Time to start testing; where would you like to start?</p>
|
||||||
|
<ul>
|
||||||
|
<li><a id=\"home-link\" href=\"" .Director::baseURL() . "\">Homepage - published site</a></li>
|
||||||
|
<li><a id=\"draft-link\" href=\"" .Director::baseURL() . "?stage=Stage\">Homepage - draft site</a></li>
|
||||||
|
<li><a id=\"admin-link\" href=\"" .Director::baseURL() . "admin/\">CMS Admin</a></li>
|
||||||
|
<li><a id=\"endsession-link\" href=\"" .Director::baseURL() . "dev/tests/endsession\">End your test session</a></li>
|
||||||
|
</ul>";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return "<p>setdb can only be used on dev and test sites</p>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function endsession() {
|
function endsession() {
|
||||||
SapphireTest::kill_temp_db();
|
SapphireTest::kill_temp_db();
|
||||||
|
Loading…
Reference in New Issue
Block a user