mirror of
https://github.com/silverstripe/silverstripe-testsession
synced 2024-10-22 14:06:00 +02:00
Tie test session files to browser session
This commit is contained in:
parent
40dd841eb3
commit
808d6aa87a
@ -13,7 +13,10 @@ Further data can be loaded from YAML fixtures or database dumps.
|
|||||||
The session is persisted in a file which is generated upon starting the session.
|
The session is persisted in a file which is generated upon starting the session.
|
||||||
As long as this file exists, the test session is considered in progress,
|
As long as this file exists, the test session is considered in progress,
|
||||||
both in web browsers and command-line execution. By default, the file
|
both in web browsers and command-line execution. By default, the file
|
||||||
is stored in the webroot under `TESTS_RUNNING.js`.
|
is stored in the webroot under `TESTS_RUNNING-<id>.js`. The `<id>` value
|
||||||
|
is a random token stored in the browser session, in order to make the
|
||||||
|
test session specific to the executing browser, and allow multiple
|
||||||
|
people using their own test session in the same webroot.
|
||||||
|
|
||||||
The module also serves as an initializer for the
|
The module also serves as an initializer for the
|
||||||
[SilverStripe Behat Extension](https://github.com/silverstripe-labs/silverstripe-behat-extension/).
|
[SilverStripe Behat Extension](https://github.com/silverstripe-labs/silverstripe-behat-extension/).
|
||||||
|
@ -6,8 +6,3 @@ Injector:
|
|||||||
properties:
|
properties:
|
||||||
filters:
|
filters:
|
||||||
- '%$TestSessionRequestFilter'
|
- '%$TestSessionRequestFilter'
|
||||||
---
|
|
||||||
Name: testsession-setup
|
|
||||||
---
|
|
||||||
TestSessionEnvironment:
|
|
||||||
test_state_file: TESTS_RUNNING.json
|
|
@ -30,7 +30,7 @@ class TestSessionController extends Controller {
|
|||||||
public function __construct() {
|
public function __construct() {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->environment = Injector::inst()->get('TestSessionEnvironment');
|
$this->environment = Injector::inst()->get('TestSessionEnvironment', Session::get('TestSessionId'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function init() {
|
public function init() {
|
||||||
@ -68,6 +68,10 @@ class TestSessionController extends Controller {
|
|||||||
public function start() {
|
public function start() {
|
||||||
$params = $this->request->requestVars();
|
$params = $this->request->requestVars();
|
||||||
|
|
||||||
|
$generator = Injector::inst()->get('RandomGenerator');
|
||||||
|
$id = substr($generator->randomToken(), 0, 10);
|
||||||
|
Session::set('TestSessionId', $id);
|
||||||
|
|
||||||
// Convert datetime from form object into a single string
|
// Convert datetime from form object into a single string
|
||||||
$params = $this->fixDatetimeFormField($params);
|
$params = $this->fixDatetimeFormField($params);
|
||||||
|
|
||||||
@ -83,7 +87,7 @@ class TestSessionController extends Controller {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->environment->startTestSession($params);
|
$this->environment->startTestSession($params, $id);
|
||||||
|
|
||||||
return $this->renderWith('TestSession_inprogress');
|
return $this->renderWith('TestSession_inprogress');
|
||||||
}
|
}
|
||||||
@ -255,6 +259,7 @@ class TestSessionController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->environment->endTestSession();
|
$this->environment->endTestSession();
|
||||||
|
Session::clear('TestSessionId');
|
||||||
|
|
||||||
// Clear out all PHP session states which have been set previously
|
// Clear out all PHP session states which have been set previously
|
||||||
if($sessionStates = Session::get('_TestSessionController.BrowserSessionState')) {
|
if($sessionStates = Session::get('_TestSessionController.BrowserSessionState')) {
|
||||||
|
@ -43,7 +43,13 @@ class TestSessionEnvironment extends Object {
|
|||||||
* @var string Path (from web-root) to the test state file that indicates a testsession is in progress.
|
* @var string Path (from web-root) to the test state file that indicates a testsession is in progress.
|
||||||
* Defaults to value stored in testsession/_config/_config.yml
|
* Defaults to value stored in testsession/_config/_config.yml
|
||||||
*/
|
*/
|
||||||
private static $test_state_file;
|
private static $test_state_file = 'TESTS_RUNNING.json';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @config
|
||||||
|
* @var [type]
|
||||||
|
*/
|
||||||
|
private static $test_state_id_file = 'TESTS_RUNNING-%s.json';
|
||||||
|
|
||||||
public function __construct($id = null) {
|
public function __construct($id = null) {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
@ -84,6 +90,7 @@ class TestSessionEnvironment extends Object {
|
|||||||
*/
|
*/
|
||||||
public function startTestSession($state, $id = null) {
|
public function startTestSession($state, $id = null) {
|
||||||
$this->removeStateFile();
|
$this->removeStateFile();
|
||||||
|
$this->id = $id;
|
||||||
|
|
||||||
$extendedState = $this->extend('onBeforeStartTestSession', $state);
|
$extendedState = $this->extend('onBeforeStartTestSession', $state);
|
||||||
|
|
||||||
|
@ -10,7 +10,10 @@ class TestSessionRequestFilter {
|
|||||||
protected $testSessionEnvironment;
|
protected $testSessionEnvironment;
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->testSessionEnvironment = Injector::inst()->get('testSessionEnvironment');
|
$this->testSessionEnvironment = Injector::inst()->get(
|
||||||
|
'TestSessionEnvironment',
|
||||||
|
Session::get('TestSessionId')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function preRequest($req, $session, $model) {
|
public function preRequest($req, $session, $model) {
|
||||||
|
Loading…
Reference in New Issue
Block a user