mirror of
https://github.com/silverstripe/silverstripe-testsession
synced 2024-10-22 14:06:00 +02:00
ENH: allow specify database by filename
This commit is contained in:
parent
d30852db1d
commit
9da7574f28
@ -56,7 +56,8 @@ on "dev/testsession/start":
|
|||||||
(see [fixture format docs](http://doc.silverstripe.org/framework/en/topics/testing/fixtures)).
|
(see [fixture format docs](http://doc.silverstripe.org/framework/en/topics/testing/fixtures)).
|
||||||
The path should be relative to the webroot.
|
The path should be relative to the webroot.
|
||||||
* `createDatabase`: Create a temporary database.
|
* `createDatabase`: Create a temporary database.
|
||||||
* `createDatabaseTemplate`: Path to a database dump to load into a newly created temporary database.
|
* `importDatabasePath`: Absolute path to a database dump to load into a newly created temporary database.
|
||||||
|
* `importDatabaseFilename`: File name for a database dump to load, relative to `TestSessionController.database_templates_path`
|
||||||
* `requireDefaultRecords`: Include default records as defined on the model classes (in PHP)
|
* `requireDefaultRecords`: Include default records as defined on the model classes (in PHP)
|
||||||
* `database`: Set an alternative database name in the current
|
* `database`: Set an alternative database name in the current
|
||||||
browser session as a cookie. Does not actually create the database,
|
browser session as a cookie. Does not actually create the database,
|
||||||
|
@ -94,9 +94,24 @@ 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']) || !empty($params['importDatabaseFilename'])) {
|
||||||
|
$absPath = '';
|
||||||
|
|
||||||
|
// by path
|
||||||
|
if(!empty($params['importDatabasePath'])) {
|
||||||
|
$absPath = $params['importDatabasePath'];
|
||||||
|
|
||||||
|
// by filename
|
||||||
|
}else if(!empty($params['importDatabaseFilename'])) {
|
||||||
|
foreach($this->getDatabaseTemplates() as $tAbsPath => $tFilename){
|
||||||
|
if($tFilename === $params['importDatabaseFilename']){
|
||||||
|
$absPath = $tAbsPath;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
$this->environment->importDatabase(
|
$this->environment->importDatabase(
|
||||||
$params['importDatabasePath'],
|
$absPath,
|
||||||
!empty($params['requireDefaultRecords']) ? $params['requireDefaultRecords'] : false
|
!empty($params['requireDefaultRecords']) ? $params['requireDefaultRecords'] : false
|
||||||
);
|
);
|
||||||
} else if(!empty($params['requireDefaultRecords']) && $params['requireDefaultRecords']) {
|
} else if(!empty($params['requireDefaultRecords']) && $params['requireDefaultRecords']) {
|
||||||
|
Loading…
Reference in New Issue
Block a user