mirror of
https://github.com/silverstripe/silverstripe-testsession
synced 2024-10-22 14:06:00 +02:00
Update for framework 3.2 compatibility
This commit is contained in:
parent
b98bbbe276
commit
869b4e8933
@ -12,7 +12,7 @@ env:
|
|||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- php: 5.3
|
- php: 5.3
|
||||||
env: DB=PGSQL CORE_RELEASE=3.1
|
env: DB=PGSQL CORE_RELEASE=master
|
||||||
- php: 5.4
|
- php: 5.4
|
||||||
env: DB=MYSQL CORE_RELEASE=3.1
|
env: DB=MYSQL CORE_RELEASE=3.1
|
||||||
- php: 5.5
|
- php: 5.5
|
||||||
|
@ -37,7 +37,7 @@ class TestSessionController extends Controller {
|
|||||||
parent::init();
|
parent::init();
|
||||||
|
|
||||||
$this->extend('init');
|
$this->extend('init');
|
||||||
|
|
||||||
$canAccess = (
|
$canAccess = (
|
||||||
!Director::isLive()
|
!Director::isLive()
|
||||||
&& (Director::isDev() || Director::isTest() || Director::is_cli() || Permission::check("ADMIN"))
|
&& (Director::isDev() || Director::isTest() || Director::is_cli() || Permission::check("ADMIN"))
|
||||||
@ -59,7 +59,7 @@ class TestSessionController extends Controller {
|
|||||||
return $this->renderWith('TestSession_start');
|
return $this->renderWith('TestSession_start');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start a test session. If you wish to extend how the test session is started (and add additional test state),
|
* Start a test session. If you wish to extend how the test session is started (and add additional test state),
|
||||||
* then take a look at {@link TestSessionEnvironment::startTestSession()} and
|
* then take a look at {@link TestSessionEnvironment::startTestSession()} and
|
||||||
@ -92,7 +92,7 @@ class TestSessionController extends Controller {
|
|||||||
);
|
);
|
||||||
|
|
||||||
$this->environment->startTestSession($params, $id);
|
$this->environment->startTestSession($params, $id);
|
||||||
|
|
||||||
// Optionally import database
|
// Optionally import database
|
||||||
if(!empty($params['importDatabasePath'])) {
|
if(!empty($params['importDatabasePath'])) {
|
||||||
$this->environment->importDatabase(
|
$this->environment->importDatabase(
|
||||||
@ -108,7 +108,7 @@ class TestSessionController extends Controller {
|
|||||||
if($fixtureFile) {
|
if($fixtureFile) {
|
||||||
$this->environment->loadFixtureIntoDb($fixtureFile);
|
$this->environment->loadFixtureIntoDb($fixtureFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->renderWith('TestSession_inprogress');
|
return $this->renderWith('TestSession_inprogress');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,7 +126,7 @@ class TestSessionController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$sessionStates = (array)Session::get('_TestSessionController.BrowserSessionState');
|
$sessionStates = (array)Session::get('_TestSessionController.BrowserSessionState');
|
||||||
|
|
||||||
foreach($newSessionStates as $k => $v) {
|
foreach($newSessionStates as $k => $v) {
|
||||||
Session::set($k, $v);
|
Session::set($k, $v);
|
||||||
}
|
}
|
||||||
@ -157,14 +157,14 @@ class TestSessionController extends Controller {
|
|||||||
}
|
}
|
||||||
$fields->merge($this->getBaseFields());
|
$fields->merge($this->getBaseFields());
|
||||||
$form = new Form(
|
$form = new Form(
|
||||||
$this,
|
$this,
|
||||||
'StartForm',
|
'StartForm',
|
||||||
$fields,
|
$fields,
|
||||||
new FieldList(
|
new FieldList(
|
||||||
new FormAction('start', 'Start Session')
|
new FormAction('start', 'Start Session')
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->extend('updateStartForm', $form);
|
$this->extend('updateStartForm', $form);
|
||||||
|
|
||||||
return $form;
|
return $form;
|
||||||
@ -176,15 +176,15 @@ class TestSessionController extends Controller {
|
|||||||
public function ProgressForm() {
|
public function ProgressForm() {
|
||||||
$fields = $this->getBaseFields();
|
$fields = $this->getBaseFields();
|
||||||
$form = new Form(
|
$form = new Form(
|
||||||
$this,
|
$this,
|
||||||
'ProgressForm',
|
'ProgressForm',
|
||||||
$fields,
|
$fields,
|
||||||
new FieldList(
|
new FieldList(
|
||||||
new FormAction('set', 'Set testing state')
|
new FormAction('set', 'Set testing state')
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
$form->setFormAction($this->Link('set'));
|
$form->setFormAction($this->Link('set'));
|
||||||
|
|
||||||
$this->extend('updateProgressForm', $form);
|
$this->extend('updateProgressForm', $form);
|
||||||
@ -216,8 +216,8 @@ class TestSessionController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function DatabaseName() {
|
public function DatabaseName() {
|
||||||
$db = DB::getConn();
|
$db = DB::get_conn();
|
||||||
if(method_exists($db, 'currentDatabase')) return $db->currentDatabase();
|
return $db->getSelectedDatabase();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -264,7 +264,7 @@ class TestSessionController extends Controller {
|
|||||||
if(SapphireTest::using_temp_db()) {
|
if(SapphireTest::using_temp_db()) {
|
||||||
SapphireTest::empty_temp_db();
|
SapphireTest::empty_temp_db();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($_SESSION['_testsession_codeblocks'])) {
|
if(isset($_SESSION['_testsession_codeblocks'])) {
|
||||||
unset($_SESSION['_testsession_codeblocks']);
|
unset($_SESSION['_testsession_codeblocks']);
|
||||||
}
|
}
|
||||||
@ -292,7 +292,7 @@ class TestSessionController extends Controller {
|
|||||||
foreach($sessionStates as $k => $v) {
|
foreach($sessionStates as $k => $v) {
|
||||||
Session::clear($k);
|
Session::clear($k);
|
||||||
}
|
}
|
||||||
Session::clear('_TestSessionController');
|
Session::clear('_TestSessionController');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -332,17 +332,17 @@ class TestSessionController extends Controller {
|
|||||||
/**
|
/**
|
||||||
* Get all *.sql database files located in a specific path,
|
* Get all *.sql database files located in a specific path,
|
||||||
* keyed by their file name.
|
* keyed by their file name.
|
||||||
*
|
*
|
||||||
* @param String $path Absolute folder path
|
* @param String $path Absolute folder path
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function getDatabaseTemplates($path = null) {
|
protected function getDatabaseTemplates($path = null) {
|
||||||
$templates = array();
|
$templates = array();
|
||||||
|
|
||||||
if(!$path) {
|
if(!$path) {
|
||||||
$path = $this->config()->database_templates_path;
|
$path = $this->config()->database_templates_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Remove once we can set BASE_PATH through the config layer
|
// TODO Remove once we can set BASE_PATH through the config layer
|
||||||
if($path && !Director::is_absolute($path)) {
|
if($path && !Director::is_absolute($path)) {
|
||||||
$path = BASE_PATH . '/' . $path;
|
$path = BASE_PATH . '/' . $path;
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
*
|
*
|
||||||
* An environment can have an optional identifier ({@link id}), which allows
|
* An environment can have an optional identifier ({@link id}), which allows
|
||||||
* multiple environments to exist at the same time in the same webroot.
|
* multiple environments to exist at the same time in the same webroot.
|
||||||
* This enables parallel testing with (mostly) isolated state.
|
* This enables parallel testing with (mostly) isolated state.
|
||||||
*
|
*
|
||||||
* For a valid test session to exist, this needs to contain at least:
|
* For a valid test session to exist, this needs to contain at least:
|
||||||
* - database: The alternate database name that is being used for this test session (e.g. ss_tmpdb_1234567)
|
* - database: The alternate database name that is being used for this test session (e.g. ss_tmpdb_1234567)
|
||||||
@ -25,7 +25,7 @@
|
|||||||
* See {@link $state} for default information stored in the test session.
|
* See {@link $state} for default information stored in the test session.
|
||||||
*/
|
*/
|
||||||
class TestSessionEnvironment extends Object {
|
class TestSessionEnvironment extends Object {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int Optional identifier for the session.
|
* @var int Optional identifier for the session.
|
||||||
*/
|
*/
|
||||||
@ -69,9 +69,9 @@ class TestSessionEnvironment extends Object {
|
|||||||
*/
|
*/
|
||||||
public function getFilePath() {
|
public function getFilePath() {
|
||||||
if($this->id) {
|
if($this->id) {
|
||||||
$path = Director::getAbsFile(sprintf($this->config()->test_state_id_file, $this->id));
|
$path = Director::getAbsFile(sprintf($this->config()->test_state_id_file, $this->id));
|
||||||
} else {
|
} else {
|
||||||
$path = Director::getAbsFile($this->config()->test_state_file);
|
$path = Director::getAbsFile($this->config()->test_state_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $path;
|
return $path;
|
||||||
@ -174,7 +174,7 @@ class TestSessionEnvironment extends Object {
|
|||||||
|
|
||||||
// ensure we have a connection to the database
|
// ensure we have a connection to the database
|
||||||
if(isset($state->database) && $state->database) {
|
if(isset($state->database) && $state->database) {
|
||||||
if(!DB::getConn()) {
|
if(!DB::get_conn()) {
|
||||||
// No connection, so try and connect to tmpdb if it exists
|
// No connection, so try and connect to tmpdb if it exists
|
||||||
if(isset($state->database)) {
|
if(isset($state->database)) {
|
||||||
$this->oldDatabaseName = $databaseConfig['database'];
|
$this->oldDatabaseName = $databaseConfig['database'];
|
||||||
@ -185,7 +185,7 @@ class TestSessionEnvironment extends Object {
|
|||||||
DB::connect($databaseConfig);
|
DB::connect($databaseConfig);
|
||||||
} else {
|
} else {
|
||||||
// We've already connected to the database, do a fast check to see what database we're currently using
|
// We've already connected to the database, do a fast check to see what database we're currently using
|
||||||
$db = DB::getConn()->currentDatabase();
|
$db = DB::get_conn()->getSelectedDatabase();
|
||||||
if(isset($state->database) && $db != $state->database) {
|
if(isset($state->database) && $db != $state->database) {
|
||||||
$this->oldDatabaseName = $databaseConfig['database'];
|
$this->oldDatabaseName = $databaseConfig['database'];
|
||||||
$databaseConfig['database'] = $state->database;
|
$databaseConfig['database'] = $state->database;
|
||||||
@ -199,7 +199,7 @@ class TestSessionEnvironment extends Object {
|
|||||||
$dbName = (isset($state->database)) ? $state->database : null;
|
$dbName = (isset($state->database)) ? $state->database : null;
|
||||||
|
|
||||||
if($dbName) {
|
if($dbName) {
|
||||||
$dbExists = DB::getConn()->databaseExists($dbName);
|
$dbExists = DB::get_conn()->databaseExists($dbName);
|
||||||
} else {
|
} else {
|
||||||
$dbExists = false;
|
$dbExists = false;
|
||||||
}
|
}
|
||||||
@ -290,7 +290,7 @@ class TestSessionEnvironment extends Object {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sliented as if the file already exists by another process, we don't want
|
* Sliented as if the file already exists by another process, we don't want
|
||||||
* to modify.
|
* to modify.
|
||||||
*/
|
*/
|
||||||
public function saveState($state) {
|
public function saveState($state) {
|
||||||
@ -393,10 +393,10 @@ class TestSessionEnvironment extends Object {
|
|||||||
|
|
||||||
$databaseConfig['database'] = $this->oldDatabaseName;
|
$databaseConfig['database'] = $this->oldDatabaseName;
|
||||||
|
|
||||||
$conn = DB::getConn();
|
$conn = DB::get_conn();
|
||||||
|
|
||||||
if($conn) {
|
if($conn) {
|
||||||
$conn->selectDatabase($this->oldDatabaseName);
|
$conn->selectDatabase($this->oldDatabaseName, false, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
/**
|
/**
|
||||||
* Sets state previously initialized through {@link TestSessionController}.
|
* Sets state previously initialized through {@link TestSessionController}.
|
||||||
*/
|
*/
|
||||||
class TestSessionRequestFilter {
|
class TestSessionRequestFilter implements RequestFilter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var TestSessionEnvironment
|
* @var TestSessionEnvironment
|
||||||
@ -12,8 +12,8 @@ class TestSessionRequestFilter {
|
|||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->testSessionEnvironment = Injector::inst()->get('TestSessionEnvironment');
|
$this->testSessionEnvironment = Injector::inst()->get('TestSessionEnvironment');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function preRequest($req, $session, $model) {
|
public function preRequest(SS_HTTPRequest $request, Session $session, DataModel $model) {
|
||||||
if(!$this->testSessionEnvironment->isRunningTests()) return;
|
if(!$this->testSessionEnvironment->isRunningTests()) return;
|
||||||
|
|
||||||
$testState = $this->testSessionEnvironment->getState();
|
$testState = $this->testSessionEnvironment->getState();
|
||||||
@ -46,9 +46,9 @@ class TestSessionRequestFilter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function postRequest() {
|
public function postRequest(SS_HTTPRequest $request, SS_HTTPResponse $response, DataModel $model) {
|
||||||
if(!$this->testSessionEnvironment->isRunningTests()) return;
|
if(!$this->testSessionEnvironment->isRunningTests()) return;
|
||||||
|
|
||||||
// Store PHP session
|
// Store PHP session
|
||||||
$state = $this->testSessionEnvironment->getState();
|
$state = $this->testSessionEnvironment->getState();
|
||||||
$state->session = Session::get_all();
|
$state->session = Session::get_all();
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.3.2",
|
"php": ">=5.3.2",
|
||||||
"composer/installers": "*",
|
"composer/installers": "*",
|
||||||
"silverstripe/framework": ">=3.1,<3.2"
|
"silverstripe/framework": "~3.2"
|
||||||
},
|
},
|
||||||
"minimum-stability": "dev"
|
"minimum-stability": "dev"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user