Merge pull request #38 from open-sausages/pulls/4.0/namespace-everything

Upgrade for framework namespacing
This commit is contained in:
Ingo Schommer 2016-09-08 16:13:13 +12:00 committed by GitHub
commit 7b918814ba
5 changed files with 55 additions and 13 deletions

View File

@ -1,6 +1,8 @@
<?php
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.
Injector::inst()->get('TestSessionEnvironment')->loadFromFile();

View File

@ -1,8 +1,27 @@
<?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\DB;
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.
@ -51,7 +70,8 @@ class TestSessionController extends Controller
&& (Director::isDev() || Director::isTest() || Director::is_cli() || Permission::check("ADMIN"))
);
if (!$canAccess) {
return Security::permissionFailure($this);
Security::permissionFailure($this);
return;
}
Requirements::javascript('framework/thirdparty/jquery/jquery.js');
@ -84,7 +104,7 @@ class TestSessionController extends Controller
if (!empty($params['globalTestSession'])) {
$id = null;
} else {
$generator = Injector::inst()->get('RandomGenerator');
$generator = Injector::inst()->get('SilverStripe\\Security\\RandomGenerator');
$id = substr($generator->randomToken(), 0, 10);
Session::set('TestSessionId', $id);
}

View File

@ -1,9 +1,16 @@
<?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\DatabaseAdmin;
use SilverStripe\ORM\Versioning\Versioned;
/**
* Responsible for starting and finalizing test sessions.
* 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.
*
* @param array $state An array of test state options to write.
* @param mixed $id
*/
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
* onAfterApplyState() to add your own test state handling in.
*
* @param mixed $state
* @throws LogicException
* @throws InvalidArgumentException
*/
@ -170,8 +179,6 @@ class TestSessionEnvironment extends Object
{
$this->extend('onBeforeApplyState', $state);
$database = (isset($state->database)) ? $state->database : null;
// back up source
global $databaseConfig;
$this->oldDatabaseName = $databaseConfig['database'];
@ -244,7 +251,7 @@ class TestSessionEnvironment extends Object
$mailer = (isset($state->mailer)) ? $state->mailer : null;
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(
'Class "%s" is not a valid class, or subclass of Mailer',
$mailer
@ -272,7 +279,7 @@ class TestSessionEnvironment extends Object
* Import the database
*
* @param String $path Absolute path to a SQL dump (include DROP TABLE commands)
* @return void
* @param bool $requireDefaultRecords
*/
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
* to modify.
*
* @param mixed $state
*/
public function saveState($state)
{
@ -367,11 +376,11 @@ class TestSessionEnvironment extends Object
if (SapphireTest::using_temp_db()) {
$state = $this->getState();
$dbConn = DB::getConn();
$dbConn = DB::get_schema();
$dbExists = $dbConn->databaseExists($state->database);
if($dbExists) {
// Clean up temp database
$dbConn->dropDatabase();
$dbConn->dropDatabase($state->database);
file_put_contents('php://stdout', "Deleted temp database: $state->database" . PHP_EOL);
}
// 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.");
}
$factory = Injector::inst()->create('FixtureFactory');
$fixture = Injector::inst()->create('YamlFixture', $fixtureFile);
$factory = Injector::inst()->create('SilverStripe\\Dev\\FixtureFactory');
$fixture = Injector::inst()->create('SilverStripe\\Dev\\YamlFixture', $fixtureFile);
$fixture->writeInto($factory);
$state = $this->getState();

View File

@ -3,6 +3,14 @@
use SilverStripe\ORM\DataModel;
use SilverStripe\ORM\FieldType\DBDatetime;
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}.
@ -36,8 +44,8 @@ class TestSessionRequestFilter implements RequestFilter
// Register mailer
if (isset($testState->mailer)) {
$mailer = $testState->mailer;
Injector::inst()->registerService(new $mailer(), 'Mailer');
Config::inst()->update("Email", "send_all_emails_to", null);
Injector::inst()->registerService(new $mailer(), 'SilverStripe\\Control\\Email\\Mailer');
Config::inst()->update("SilverStripe\\Control\\Email\\Email", "send_all_emails_to", null);
}
// Allows inclusion of a PHP file, usually with procedural commands

View File

@ -1,4 +1,7 @@
<?php
use SilverStripe\Dev\SapphireTest;
class TestSessionStubCodeWriterTest extends SapphireTest
{