mirror of
https://github.com/silverstripe/silverstripe-testsession
synced 2024-10-22 14:06:00 +02:00
Merge pull request #38 from open-sausages/pulls/4.0/namespace-everything
Upgrade for framework namespacing
This commit is contained in:
commit
7b918814ba
@ -1,6 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use SilverStripe\ORM\DB;
|
use SilverStripe\ORM\DB;
|
||||||
|
use SilverStripe\Core\Injector\Injector;
|
||||||
|
|
||||||
|
|
||||||
// Determine whether there is a testsession currently running, and if so - setup the persistent details for it.
|
// Determine whether there is a testsession currently running, and if so - setup the persistent details for it.
|
||||||
Injector::inst()->get('TestSessionEnvironment')->loadFromFile();
|
Injector::inst()->get('TestSessionEnvironment')->loadFromFile();
|
||||||
|
@ -1,8 +1,27 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use SilverStripe\ORM\DB;
|
use SilverStripe\Control\Controller;
|
||||||
|
use SilverStripe\Control\Director;
|
||||||
|
use SilverStripe\Control\Session;
|
||||||
|
use SilverStripe\Control\SS_HTTPRequest;
|
||||||
|
use SilverStripe\Core\Injector\Injector;
|
||||||
|
use SilverStripe\Dev\Deprecation;
|
||||||
|
use SilverStripe\Dev\SapphireTest;
|
||||||
|
use SilverStripe\Forms\CheckboxField;
|
||||||
|
use SilverStripe\Forms\DatetimeField;
|
||||||
|
use SilverStripe\Forms\DropdownField;
|
||||||
|
use SilverStripe\Forms\FieldList;
|
||||||
|
use SilverStripe\Forms\Form;
|
||||||
|
use SilverStripe\Forms\FormAction;
|
||||||
|
use SilverStripe\Forms\HiddenField;
|
||||||
|
use SilverStripe\Forms\TextField;
|
||||||
use SilverStripe\ORM\ArrayList;
|
use SilverStripe\ORM\ArrayList;
|
||||||
|
use SilverStripe\ORM\DB;
|
||||||
use SilverStripe\ORM\FieldType\DBHTMLText;
|
use SilverStripe\ORM\FieldType\DBHTMLText;
|
||||||
|
use SilverStripe\Security\Permission;
|
||||||
|
use SilverStripe\Security\Security;
|
||||||
|
use SilverStripe\View\ArrayData;
|
||||||
|
use SilverStripe\View\Requirements;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Requires PHP's mycrypt extension in order to set the database name as an encrypted cookie.
|
* Requires PHP's mycrypt extension in order to set the database name as an encrypted cookie.
|
||||||
@ -51,7 +70,8 @@ class TestSessionController extends Controller
|
|||||||
&& (Director::isDev() || Director::isTest() || Director::is_cli() || Permission::check("ADMIN"))
|
&& (Director::isDev() || Director::isTest() || Director::is_cli() || Permission::check("ADMIN"))
|
||||||
);
|
);
|
||||||
if (!$canAccess) {
|
if (!$canAccess) {
|
||||||
return Security::permissionFailure($this);
|
Security::permissionFailure($this);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Requirements::javascript('framework/thirdparty/jquery/jquery.js');
|
Requirements::javascript('framework/thirdparty/jquery/jquery.js');
|
||||||
@ -84,7 +104,7 @@ class TestSessionController extends Controller
|
|||||||
if (!empty($params['globalTestSession'])) {
|
if (!empty($params['globalTestSession'])) {
|
||||||
$id = null;
|
$id = null;
|
||||||
} else {
|
} else {
|
||||||
$generator = Injector::inst()->get('RandomGenerator');
|
$generator = Injector::inst()->get('SilverStripe\\Security\\RandomGenerator');
|
||||||
$id = substr($generator->randomToken(), 0, 10);
|
$id = substr($generator->randomToken(), 0, 10);
|
||||||
Session::set('TestSessionId', $id);
|
Session::set('TestSessionId', $id);
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use SilverStripe\Control\Director;
|
||||||
|
use SilverStripe\Control\Session;
|
||||||
|
use SilverStripe\Core\Injector\Injector;
|
||||||
|
use SilverStripe\Core\Object;
|
||||||
|
use SilverStripe\Dev\FixtureFactory;
|
||||||
|
use SilverStripe\Dev\SapphireTest;
|
||||||
use SilverStripe\ORM\DB;
|
use SilverStripe\ORM\DB;
|
||||||
use SilverStripe\ORM\DatabaseAdmin;
|
use SilverStripe\ORM\DatabaseAdmin;
|
||||||
use SilverStripe\ORM\Versioning\Versioned;
|
use SilverStripe\ORM\Versioning\Versioned;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Responsible for starting and finalizing test sessions.
|
* Responsible for starting and finalizing test sessions.
|
||||||
* Since these session span across multiple requests, session information is persisted
|
* Since these session span across multiple requests, session information is persisted
|
||||||
@ -120,6 +127,7 @@ class TestSessionEnvironment extends Object
|
|||||||
* onBeforeApplyState() and onAfterApplyState(). See the {@link self::applyState()} method for more.
|
* onBeforeApplyState() and onAfterApplyState(). See the {@link self::applyState()} method for more.
|
||||||
*
|
*
|
||||||
* @param array $state An array of test state options to write.
|
* @param array $state An array of test state options to write.
|
||||||
|
* @param mixed $id
|
||||||
*/
|
*/
|
||||||
public function startTestSession($state = null, $id = null)
|
public function startTestSession($state = null, $id = null)
|
||||||
{
|
{
|
||||||
@ -163,6 +171,7 @@ class TestSessionEnvironment extends Object
|
|||||||
* You can extend this by creating an Extension object and implementing either onBeforeApplyState() or
|
* You can extend this by creating an Extension object and implementing either onBeforeApplyState() or
|
||||||
* onAfterApplyState() to add your own test state handling in.
|
* onAfterApplyState() to add your own test state handling in.
|
||||||
*
|
*
|
||||||
|
* @param mixed $state
|
||||||
* @throws LogicException
|
* @throws LogicException
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
@ -170,8 +179,6 @@ class TestSessionEnvironment extends Object
|
|||||||
{
|
{
|
||||||
$this->extend('onBeforeApplyState', $state);
|
$this->extend('onBeforeApplyState', $state);
|
||||||
|
|
||||||
$database = (isset($state->database)) ? $state->database : null;
|
|
||||||
|
|
||||||
// back up source
|
// back up source
|
||||||
global $databaseConfig;
|
global $databaseConfig;
|
||||||
$this->oldDatabaseName = $databaseConfig['database'];
|
$this->oldDatabaseName = $databaseConfig['database'];
|
||||||
@ -244,7 +251,7 @@ class TestSessionEnvironment extends Object
|
|||||||
$mailer = (isset($state->mailer)) ? $state->mailer : null;
|
$mailer = (isset($state->mailer)) ? $state->mailer : null;
|
||||||
|
|
||||||
if ($mailer) {
|
if ($mailer) {
|
||||||
if (!class_exists($mailer) || !is_subclass_of($mailer, 'Mailer')) {
|
if (!class_exists($mailer) || !is_subclass_of($mailer, 'SilverStripe\\Control\\Email\\Mailer')) {
|
||||||
throw new InvalidArgumentException(sprintf(
|
throw new InvalidArgumentException(sprintf(
|
||||||
'Class "%s" is not a valid class, or subclass of Mailer',
|
'Class "%s" is not a valid class, or subclass of Mailer',
|
||||||
$mailer
|
$mailer
|
||||||
@ -272,7 +279,7 @@ class TestSessionEnvironment extends Object
|
|||||||
* Import the database
|
* Import the database
|
||||||
*
|
*
|
||||||
* @param String $path Absolute path to a SQL dump (include DROP TABLE commands)
|
* @param String $path Absolute path to a SQL dump (include DROP TABLE commands)
|
||||||
* @return void
|
* @param bool $requireDefaultRecords
|
||||||
*/
|
*/
|
||||||
public function importDatabase($path, $requireDefaultRecords = false)
|
public function importDatabase($path, $requireDefaultRecords = false)
|
||||||
{
|
{
|
||||||
@ -309,6 +316,8 @@ 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.
|
||||||
|
*
|
||||||
|
* @param mixed $state
|
||||||
*/
|
*/
|
||||||
public function saveState($state)
|
public function saveState($state)
|
||||||
{
|
{
|
||||||
@ -367,11 +376,11 @@ class TestSessionEnvironment extends Object
|
|||||||
|
|
||||||
if (SapphireTest::using_temp_db()) {
|
if (SapphireTest::using_temp_db()) {
|
||||||
$state = $this->getState();
|
$state = $this->getState();
|
||||||
$dbConn = DB::getConn();
|
$dbConn = DB::get_schema();
|
||||||
$dbExists = $dbConn->databaseExists($state->database);
|
$dbExists = $dbConn->databaseExists($state->database);
|
||||||
if($dbExists) {
|
if($dbExists) {
|
||||||
// Clean up temp database
|
// Clean up temp database
|
||||||
$dbConn->dropDatabase();
|
$dbConn->dropDatabase($state->database);
|
||||||
file_put_contents('php://stdout', "Deleted temp database: $state->database" . PHP_EOL);
|
file_put_contents('php://stdout', "Deleted temp database: $state->database" . PHP_EOL);
|
||||||
}
|
}
|
||||||
// End test session mode
|
// End test session mode
|
||||||
@ -406,8 +415,8 @@ class TestSessionEnvironment extends Object
|
|||||||
throw new LogicException("Fixture file must be inside the tests subfolder of one of your modules.");
|
throw new LogicException("Fixture file must be inside the tests subfolder of one of your modules.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$factory = Injector::inst()->create('FixtureFactory');
|
$factory = Injector::inst()->create('SilverStripe\\Dev\\FixtureFactory');
|
||||||
$fixture = Injector::inst()->create('YamlFixture', $fixtureFile);
|
$fixture = Injector::inst()->create('SilverStripe\\Dev\\YamlFixture', $fixtureFile);
|
||||||
$fixture->writeInto($factory);
|
$fixture->writeInto($factory);
|
||||||
|
|
||||||
$state = $this->getState();
|
$state = $this->getState();
|
||||||
|
@ -3,6 +3,14 @@
|
|||||||
use SilverStripe\ORM\DataModel;
|
use SilverStripe\ORM\DataModel;
|
||||||
use SilverStripe\ORM\FieldType\DBDatetime;
|
use SilverStripe\ORM\FieldType\DBDatetime;
|
||||||
use SilverStripe\ORM\DB;
|
use SilverStripe\ORM\DB;
|
||||||
|
use SilverStripe\Core\Injector\Injector;
|
||||||
|
use SilverStripe\Control\SS_HTTPRequest;
|
||||||
|
use SilverStripe\Control\Session;
|
||||||
|
use SilverStripe\Core\Config\Config;
|
||||||
|
use SilverStripe\Control\Director;
|
||||||
|
use SilverStripe\Control\SS_HTTPResponse;
|
||||||
|
use SilverStripe\Control\RequestFilter;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets state previously initialized through {@link TestSessionController}.
|
* Sets state previously initialized through {@link TestSessionController}.
|
||||||
@ -36,8 +44,8 @@ class TestSessionRequestFilter implements RequestFilter
|
|||||||
// Register mailer
|
// Register mailer
|
||||||
if (isset($testState->mailer)) {
|
if (isset($testState->mailer)) {
|
||||||
$mailer = $testState->mailer;
|
$mailer = $testState->mailer;
|
||||||
Injector::inst()->registerService(new $mailer(), 'Mailer');
|
Injector::inst()->registerService(new $mailer(), 'SilverStripe\\Control\\Email\\Mailer');
|
||||||
Config::inst()->update("Email", "send_all_emails_to", null);
|
Config::inst()->update("SilverStripe\\Control\\Email\\Email", "send_all_emails_to", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allows inclusion of a PHP file, usually with procedural commands
|
// Allows inclusion of a PHP file, usually with procedural commands
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use SilverStripe\Dev\SapphireTest;
|
||||||
|
|
||||||
class TestSessionStubCodeWriterTest extends SapphireTest
|
class TestSessionStubCodeWriterTest extends SapphireTest
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user