Allow "global" test sessions

This commit is contained in:
Ingo Schommer 2014-05-06 16:45:55 +12:00
parent 1582e74d10
commit bb9994ddca
2 changed files with 15 additions and 3 deletions

View File

@ -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:

View File

@ -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,