diff --git a/README.md b/README.md index 82a0321..62be52b 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,8 @@ on "dev/testsession/start": * `mailer`: Subclass of `Mailer`, typically used to record emails instead of actually sending them. * `datetime`: Sets a simulated date used for all framework operations. Format as "yyyy-MM-dd HH:mm:ss" (Example: "2012-12-31 18:40:59"). + * `globalTestSession`: Activate test session independently of the current browser session, + effectively setting the site into test session mode for all users. Only available in "dev" mode. Example usage with parameters: diff --git a/code/TestSessionController.php b/code/TestSessionController.php index 4334c41..275a94d 100644 --- a/code/TestSessionController.php +++ b/code/TestSessionController.php @@ -68,9 +68,13 @@ class TestSessionController extends Controller { public function start() { $params = $this->request->requestVars(); - $generator = Injector::inst()->get('RandomGenerator'); - $id = substr($generator->randomToken(), 0, 10); - Session::set('TestSessionId', $id); + if(!empty($params['globalTestSession'])) { + $id = null; + } else { + $generator = Injector::inst()->get('RandomGenerator'); + $id = substr($generator->randomToken(), 0, 10); + Session::set('TestSessionId', $id); + } // Convert datetime from form object into a single string $params = $this->fixDatetimeFormField($params); @@ -145,6 +149,12 @@ class TestSessionController extends Controller { ->setEmptyString('Empty database'); } $fields->push(new CheckboxField('requireDefaultRecords', 'Create default data?')); + if(Director::isDev()) { + $fields->push( + CheckboxField::create('globalTestSession', 'Use global test session?') + ->setDescription('Caution: Will apply to all users across browsers') + ); + } $fields->merge($this->getBaseFields()); $form = new Form( $this,