mirror of
https://github.com/silverstripe/silverstripe-testsession
synced 2024-10-22 14:06:00 +02:00
NEW Mailer class and mock date support
This commit is contained in:
parent
a2d7675e57
commit
7e8021af04
@ -51,7 +51,9 @@ Parameters for "dev/testsession/start":
|
|||||||
Note: The database names are limited to a specific naming convention as a security measure:
|
Note: The database names are limited to a specific naming convention as a security measure:
|
||||||
The "ss_tmpdb" prefix and a random sequence of seven digits.
|
The "ss_tmpdb" prefix and a random sequence of seven digits.
|
||||||
This avoids the user gaining access to other production databases available on the same connection.
|
This avoids the user gaining access to other production databases available on the same connection.
|
||||||
|
* `mailer`: Subclass of `Mailer`, typically used to record emails instead of actually sending them.
|
||||||
|
* `date`: Sets a simulated date used for all framework operations.
|
||||||
|
Format as "yyyy-MM-dd HH:mm:ss" (Example: "2012-12-31 18:40:59").
|
||||||
|
|
||||||
Example usage with parameters:
|
Example usage with parameters:
|
||||||
|
|
||||||
|
16
_config.php
16
_config.php
@ -1,16 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
if(DB::get_alternative_database_name()) {
|
if(DB::get_alternative_database_name()) {
|
||||||
Session::start();
|
|
||||||
require_once BASE_PATH . '/vendor/autoload.php';
|
require_once BASE_PATH . '/vendor/autoload.php';
|
||||||
|
|
||||||
// Register mailer
|
// Register mailer
|
||||||
$this->mailer = new SilverStripe\BehatExtension\Utility\TestMailer();
|
if($mailer = Session::get('testsession.mailer')) {
|
||||||
Email::set_mailer($this->mailer);
|
Email::set_mailer(new $mailer());
|
||||||
Email::send_all_emails_to(null);
|
Email::send_all_emails_to(null);
|
||||||
|
}
|
||||||
|
|
||||||
// Set mock date and time
|
// Set mock date and time
|
||||||
$mockDate = Session::get('behat.mockDate');
|
$date = Session::get('testsession.date');
|
||||||
if($mockDate) {
|
if($date) {
|
||||||
SS_Datetime::set_mock_now($mockDate);
|
SS_Datetime::set_mock_now($date);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -136,6 +136,35 @@ class TestSessionController extends Controller {
|
|||||||
array_shift($dataClasses);
|
array_shift($dataClasses);
|
||||||
foreach($dataClasses as $dataClass) singleton($dataClass)->requireDefaultRecords();
|
foreach($dataClasses as $dataClass) singleton($dataClass)->requireDefaultRecords();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mailer
|
||||||
|
$mailer = (isset($data['mailer'])) ? $data['mailer'] : null;
|
||||||
|
if($mailer) {
|
||||||
|
if(!class_exists($mailer) || !is_subclass_of($mailer, 'Mailer')) {
|
||||||
|
throw new InvalidArgumentException(sprintf(
|
||||||
|
'Class "%s" is not a valid class, or subclass of Mailer',
|
||||||
|
$mailer
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configured through testsession/_config.php
|
||||||
|
Session::set('testsession.mailer', $mailer);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Date
|
||||||
|
$date = (isset($data['date'])) ? $data['date'] : null;
|
||||||
|
if($date) {
|
||||||
|
require_once 'Zend/Date.php';
|
||||||
|
if(!Zend_Date::isDate($date, 'yyyy-MM-dd HH:mm:ss')) {
|
||||||
|
throw new LogicException(sprintf(
|
||||||
|
'Invalid date format "%s", use yyyy-MM-dd HH:mm:ss',
|
||||||
|
$date
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configured through testsession/_config.php
|
||||||
|
Session::set('testsession.date', $date);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -155,6 +184,18 @@ class TestSessionController extends Controller {
|
|||||||
'Value' => implode(',', array_unique($fixtures)),
|
'Value' => implode(',', array_unique($fixtures)),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
if($mailer = Session::get('testsession.mailer')) {
|
||||||
|
$state[] = new ArrayData(array(
|
||||||
|
'Name' => 'Mailer Class',
|
||||||
|
'Value' => $mailer,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if($date = Session::get('testsession.date')) {
|
||||||
|
$state[] = new ArrayData(array(
|
||||||
|
'Name' => 'Date',
|
||||||
|
'Value' => $date,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
return new ArrayList($state);
|
return new ArrayList($state);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user