2013-11-27 19:29:44 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2013-12-10 18:53:26 +01:00
|
|
|
* Sets state previously initialized through {@link TestSessionController}.
|
2013-11-27 19:29:44 +01:00
|
|
|
*/
|
|
|
|
class TestSessionRequestFilter {
|
|
|
|
|
|
|
|
public function preRequest($req, $session, $model) {
|
2013-12-10 18:53:26 +01:00
|
|
|
if(!$session->inst_get('testsession.started')) return;
|
|
|
|
|
|
|
|
// Date and time
|
|
|
|
if($datetime = $session->inst_get('testsession.datetime')) {
|
|
|
|
SS_Datetime::set_mock_now($datetime);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Register mailer
|
|
|
|
if($mailer = $session->inst_get('testsession.mailer')) {
|
|
|
|
Email::set_mailer(new $mailer());
|
|
|
|
Config::inst()->update("Email","send_all_emails_to", null);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allows inclusion of a PHP file, usually with procedural commands
|
|
|
|
// to set up required test state. The file can be generated
|
|
|
|
// through {@link TestSessionStubCodeWriter}, and the session state
|
|
|
|
// set through {@link TestSessionController->set()} and the
|
|
|
|
// 'testsessio.stubfile' state parameter.
|
2013-11-27 19:29:44 +01:00
|
|
|
$file = $session->inst_get('testsession.stubfile');
|
|
|
|
if(!Director::isLive() && $file && file_exists($file)) {
|
|
|
|
// Connect to the database so the included code can interact with it
|
|
|
|
global $databaseConfig;
|
|
|
|
if ($databaseConfig) DB::connect($databaseConfig);
|
|
|
|
include_once($file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function postRequest() {
|
|
|
|
}
|
|
|
|
}
|