Skip to content
This repository
Browse code

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.

michalochman/SilverStripe-Behaviour-Testing-Framework#27
  • Loading branch information...
commit 766b03f360d866e9567d3a7e34299b5a64157491 1 parent 9b15bac
Michał Ochman authored July 06, 2012 chillu committed August 07, 2012

Showing 1 changed file with 50 additions and 0 deletions. Show diff stats Hide diff stats

  1. 50  dev/TestRunner.php
50  dev/TestRunner.php
@@ -31,6 +31,7 @@ class TestRunner extends Controller {
31 31
 		'coverage' => 'coverageAll',
32 32
 		'sessionloadyml' => 'sessionloadyml',
33 33
 		'startsession' => 'startsession',
  34
+		'selectsession' => 'selectsession',
34 35
 		'endsession' => 'endsession',
35 36
 		'cleanupdb' => 'cleanupdb',
36 37
 		'emptydb' => 'emptydb',
@@ -48,6 +49,7 @@ class TestRunner extends Controller {
48 49
 		'coverageModule',
49 50
 		'coverageOnly',
50 51
 		'startsession',
  52
+		'selectsession',
51 53
 		'endsession',
52 54
 		'cleanupdb',
53 55
 		'module',
@@ -423,6 +425,54 @@ function emptydb() {
423 425
 			return "<p>dev/tests/emptydb can only be used with a temporary database. Perhaps you should use dev/tests/startsession first?</p>";
424 426
 		}
425 427
 	}
  428
+
  429
+	function selectsession() {
  430
+		if(!Director::isLive()) {
  431
+			$tempDir = '/tmp';
  432
+			$testSessionsDir = $tempDir . DIRECTORY_SEPARATOR . 'testsessions';
  433
+
  434
+			if (!is_dir($testSessionsDir)) {
  435
+					return "<p>There are no test sessions available to select from.</p>";
  436
+				}
  437
+
  438
+			if(!isset($_POST['testSessionKey'])) {
  439
+				$me = Director::baseURL() . "dev/tests/selectsession";
  440
+				return <<<HTML
  441
+<form action="$me" method="post">
  442
+	<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>
  443
+	<input type="text" id="testSessionKey" name="testSessionKey" value="">
  444
+	<p><input id="select-session" value="Select test session" type="submit" /></p>
  445
+</form>
  446
+HTML;
  447
+			} else {
  448
+				$testSessionKey = $_POST['testSessionKey'];
  449
+
  450
+				$testSessionFile = $testSessionsDir . DIRECTORY_SEPARATOR . $testSessionKey;
  451
+
  452
+				if (!is_file($testSessionFile) || !is_readable($testSessionFile)) {
  453
+					return "<p>Invalid session key.</p>";
  454
+				}
  455
+
  456
+				$testSessionDict = json_decode(file_get_contents($testSessionFile));
  457
+				if (!isset($testSessionDict->databaseConfig, $testSessionDict->databaseConfig->database)) {
  458
+					return "<p>Invalid database config.</p>";
  459
+				}
  460
+
  461
+				DB::set_alternative_database_name($testSessionDict->databaseConfig->database);
  462
+
  463
+				return "<p>Selected test session $testSessionKey.</p>
  464
+						<p>Time to start testing; where would you like to start?</p>
  465
+						<ul>
  466
+							<li><a id=\"home-link\" href=\"" .Director::baseURL() . "\">Homepage - published site</a></li>
  467
+							<li><a id=\"draft-link\" href=\"" .Director::baseURL() . "?stage=Stage\">Homepage - draft site</a></li>
  468
+							<li><a id=\"admin-link\" href=\"" .Director::baseURL() . "admin/\">CMS Admin</a></li>
  469
+							<li><a id=\"endsession-link\" href=\"" .Director::baseURL() . "dev/tests/endsession\">End your test session</a></li>
  470
+						</ul>";
  471
+			}
  472
+		} else {
  473
+			return "<p>setdb can only be used on dev and test sites</p>";
  474
+		}
  475
+	}
426 476
 	
427 477
 	function endsession() {
428 478
 		SapphireTest::kill_temp_db();

0 notes on commit 766b03f

Please sign in to comment.
Something went wrong with that request. Please try again.