From bb9994ddca78d5b9066009aea37efc7b380330a6 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 6 May 2014 16:45:55 +1200 Subject: [PATCH] Allow "global" test sessions --- README.md | 2 ++ code/TestSessionController.php | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) 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,