mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Fix controller namespace
Move states to sub namespace
This commit is contained in:
parent
2a278e2953
commit
06364af3c3
@ -2,18 +2,19 @@
|
|||||||
Name: sapphiretest
|
Name: sapphiretest
|
||||||
---
|
---
|
||||||
SilverStripe\Core\Injector\Injector:
|
SilverStripe\Core\Injector\Injector:
|
||||||
SilverStripe\Dev\SapphireTestState:
|
SilverStripe\Dev\State\SapphireTestState:
|
||||||
properties:
|
properties:
|
||||||
States:
|
States:
|
||||||
extensions: %$SilverStripe\Dev\ExtensionTestState
|
globals: %$SilverStripe\Dev\State\GlobalsTestState
|
||||||
flushable: %$SilverStripe\Dev\FlushableTestState
|
extensions: %$SilverStripe\Dev\State\ExtensionTestState
|
||||||
|
flushable: %$SilverStripe\Dev\State\FlushableTestState
|
||||||
requirements: %$SilverStripe\View\Dev\RequirementsTestState
|
requirements: %$SilverStripe\View\Dev\RequirementsTestState
|
||||||
---
|
---
|
||||||
Name: kerneltest
|
Name: kerneltest
|
||||||
Before: '*'
|
Before: '*'
|
||||||
---
|
---
|
||||||
SilverStripe\Core\Injector\Injector:
|
SilverStripe\Core\Injector\Injector:
|
||||||
SilverStripe\Dev\SapphireTestState:
|
SilverStripe\Dev\State\SapphireTestState:
|
||||||
properties:
|
properties:
|
||||||
States:
|
States:
|
||||||
kernel: %$SilverStripe\Dev\KernelTestState
|
kernel: %$SilverStripe\Dev\State\KernelTestState
|
||||||
|
@ -176,6 +176,49 @@ class Director implements TemplateGlobalProvider
|
|||||||
$headers = array(),
|
$headers = array(),
|
||||||
$cookies = array(),
|
$cookies = array(),
|
||||||
&$request = null
|
&$request = null
|
||||||
|
) {
|
||||||
|
return static::mockRequest(
|
||||||
|
function (HTTPRequest $request) {
|
||||||
|
return static::direct($request);
|
||||||
|
},
|
||||||
|
$url,
|
||||||
|
$postVars,
|
||||||
|
$session,
|
||||||
|
$httpMethod,
|
||||||
|
$body,
|
||||||
|
$headers,
|
||||||
|
$cookies,
|
||||||
|
$request
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mock a request, passing this to the given callback, before resetting.
|
||||||
|
*
|
||||||
|
* @param callable $callback Action to pass the HTTPRequst object
|
||||||
|
* @param string $url The URL to build
|
||||||
|
* @param array $postVars The $_POST & $_FILES variables.
|
||||||
|
* @param array|Session $session The {@link Session} object representing the current session.
|
||||||
|
* By passing the same object to multiple calls of Director::test(), you can simulate a persisted
|
||||||
|
* session.
|
||||||
|
* @param string $httpMethod The HTTP method, such as GET or POST. It will default to POST if
|
||||||
|
* postVars is set, GET otherwise. Overwritten by $postVars['_method'] if present.
|
||||||
|
* @param string $body The HTTP body.
|
||||||
|
* @param array $headers HTTP headers with key-value pairs.
|
||||||
|
* @param array|Cookie_Backend $cookies to populate $_COOKIE.
|
||||||
|
* @param HTTPRequest $request The {@see SS_HTTP_Request} object generated as a part of this request.
|
||||||
|
* @return mixed Result of callback
|
||||||
|
*/
|
||||||
|
public static function mockRequest(
|
||||||
|
$callback,
|
||||||
|
$url,
|
||||||
|
$postVars = [],
|
||||||
|
$session = [],
|
||||||
|
$httpMethod = null,
|
||||||
|
$body = null,
|
||||||
|
$headers = [],
|
||||||
|
$cookies = [],
|
||||||
|
&$request = null
|
||||||
) {
|
) {
|
||||||
// Build list of cleanup promises
|
// Build list of cleanup promises
|
||||||
$finally = [];
|
$finally = [];
|
||||||
@ -261,6 +304,7 @@ class Director implements TemplateGlobalProvider
|
|||||||
$newVars['_GET'] = [];
|
$newVars['_GET'] = [];
|
||||||
}
|
}
|
||||||
$newVars['_SERVER']['REQUEST_URI'] = Director::baseURL() . $url;
|
$newVars['_SERVER']['REQUEST_URI'] = Director::baseURL() . $url;
|
||||||
|
$newVars['_REQUEST'] = array_merge($newVars['_GET'], $newVars['_POST']);
|
||||||
|
|
||||||
// Create new request
|
// Create new request
|
||||||
$request = HTTPRequest::createFromVariables($newVars, $body);
|
$request = HTTPRequest::createFromVariables($newVars, $body);
|
||||||
@ -275,7 +319,7 @@ class Director implements TemplateGlobalProvider
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Normal request handling
|
// Normal request handling
|
||||||
return static::direct($request);
|
return call_user_func($callback, $request);
|
||||||
} finally {
|
} finally {
|
||||||
// Restore state in reverse order to assignment
|
// Restore state in reverse order to assignment
|
||||||
foreach (array_reverse($finally) as $callback) {
|
foreach (array_reverse($finally) as $callback) {
|
||||||
|
@ -132,7 +132,7 @@ class CoreKernel implements Kernel
|
|||||||
|
|
||||||
public function setEnvironment($environment)
|
public function setEnvironment($environment)
|
||||||
{
|
{
|
||||||
if (!in_array($environment, [self::DEV, self::TEST, self::LIVE])) {
|
if (!in_array($environment, [self::DEV, self::TEST, self::LIVE, null])) {
|
||||||
throw new InvalidArgumentException(
|
throw new InvalidArgumentException(
|
||||||
"Director::set_environment_type passed '$environment'. It should be passed dev, test, or live"
|
"Director::set_environment_type passed '$environment'. It should be passed dev, test, or live"
|
||||||
);
|
);
|
||||||
|
@ -85,12 +85,13 @@ class FunctionalTest extends SapphireTest
|
|||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
// Skip calling FunctionalTest directly.
|
// Skip calling FunctionalTest directly.
|
||||||
if (static::class == __CLASS__) {
|
if (static::class == __CLASS__) {
|
||||||
$this->markTestSkipped(sprintf('Skipping %s ', static::class));
|
$this->markTestSkipped(sprintf('Skipping %s ', static::class));
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::setUp();
|
|
||||||
$this->mainSession = new TestSession();
|
$this->mainSession = new TestSession();
|
||||||
|
|
||||||
// Disable theme, if necessary
|
// Disable theme, if necessary
|
||||||
@ -115,9 +116,8 @@ class FunctionalTest extends SapphireTest
|
|||||||
protected function tearDown()
|
protected function tearDown()
|
||||||
{
|
{
|
||||||
SecurityToken::enable();
|
SecurityToken::enable();
|
||||||
|
|
||||||
parent::tearDown();
|
|
||||||
unset($this->mainSession);
|
unset($this->mainSession);
|
||||||
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,6 +20,8 @@ use SilverStripe\Core\Injector\Injector;
|
|||||||
use SilverStripe\Core\Injector\InjectorLoader;
|
use SilverStripe\Core\Injector\InjectorLoader;
|
||||||
use SilverStripe\Core\Manifest\ClassLoader;
|
use SilverStripe\Core\Manifest\ClassLoader;
|
||||||
use SilverStripe\Core\TestKernel;
|
use SilverStripe\Core\TestKernel;
|
||||||
|
use SilverStripe\Dev\State\SapphireTestState;
|
||||||
|
use SilverStripe\Dev\State\TestState;
|
||||||
use SilverStripe\i18n\i18n;
|
use SilverStripe\i18n\i18n;
|
||||||
use SilverStripe\ORM\DataExtension;
|
use SilverStripe\ORM\DataExtension;
|
||||||
use SilverStripe\ORM\DataObject;
|
use SilverStripe\ORM\DataObject;
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace SilverStripe\Dev;
|
namespace SilverStripe\Dev\State;
|
||||||
|
|
||||||
use LogicException;
|
use LogicException;
|
||||||
use SilverStripe\Core\Extension;
|
use SilverStripe\Core\Extension;
|
||||||
use SilverStripe\Core\Injector\Injector;
|
use SilverStripe\Core\Injector\Injector;
|
||||||
|
use SilverStripe\Dev\Debug;
|
||||||
|
use SilverStripe\Dev\SapphireTest;
|
||||||
use SilverStripe\ORM\DataObject;
|
use SilverStripe\ORM\DataObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,7 +40,9 @@ class ExtensionTestState implements TestState
|
|||||||
public function setUpOnce($class)
|
public function setUpOnce($class)
|
||||||
{
|
{
|
||||||
// May be altered by another class
|
// May be altered by another class
|
||||||
$isAltered = $this->extensionsToReapply || $this->extensionsToRemove;
|
$isAltered = false;
|
||||||
|
$this->extensionsToReapply = [];
|
||||||
|
$this->extensionsToRemove = [];
|
||||||
|
|
||||||
/** @var string|SapphireTest $class */
|
/** @var string|SapphireTest $class */
|
||||||
/** @var string|DataObject $dataClass */
|
/** @var string|DataObject $dataClass */
|
||||||
@ -68,7 +72,6 @@ class ExtensionTestState implements TestState
|
|||||||
if (!class_exists($dataClass)) {
|
if (!class_exists($dataClass)) {
|
||||||
throw new LogicException("Test {$class} requires dataClass {$dataClass} which doesn't exist");
|
throw new LogicException("Test {$class} requires dataClass {$dataClass} which doesn't exist");
|
||||||
}
|
}
|
||||||
$this->extensionsToRemove[$dataClass] = array();
|
|
||||||
foreach ($extensions as $extension) {
|
foreach ($extensions as $extension) {
|
||||||
$extension = Extension::get_classname_without_arguments($extension);
|
$extension = Extension::get_classname_without_arguments($extension);
|
||||||
if (!class_exists($extension)) {
|
if (!class_exists($extension)) {
|
||||||
@ -76,7 +79,7 @@ class ExtensionTestState implements TestState
|
|||||||
}
|
}
|
||||||
if (!$dataClass::has_extension($extension)) {
|
if (!$dataClass::has_extension($extension)) {
|
||||||
if (!isset($this->extensionsToRemove[$dataClass])) {
|
if (!isset($this->extensionsToRemove[$dataClass])) {
|
||||||
$this->extensionsToReapply[$dataClass] = [];
|
$this->extensionsToRemove[$dataClass] = [];
|
||||||
}
|
}
|
||||||
$this->extensionsToRemove[$dataClass][] = $extension;
|
$this->extensionsToRemove[$dataClass][] = $extension;
|
||||||
$dataClass::add_extension($extension);
|
$dataClass::add_extension($extension);
|
@ -1,10 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace SilverStripe\Dev;
|
namespace SilverStripe\Dev\State;
|
||||||
|
|
||||||
use SilverStripe\Core\ClassInfo;
|
use SilverStripe\Core\ClassInfo;
|
||||||
use SilverStripe\Core\Flushable;
|
use SilverStripe\Core\Flushable;
|
||||||
use SilverStripe\Core\Resettable;
|
use SilverStripe\Core\Resettable;
|
||||||
|
use SilverStripe\Dev\SapphireTest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears flushable / resettable objects
|
* Clears flushable / resettable objects
|
44
src/Dev/State/GlobalsTestState.php
Normal file
44
src/Dev/State/GlobalsTestState.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\Dev\State;
|
||||||
|
|
||||||
|
use SilverStripe\Control\Director;
|
||||||
|
use SilverStripe\Dev\SapphireTest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cleans up and reset global env vars between tests
|
||||||
|
*/
|
||||||
|
class GlobalsTestState implements TestState
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Var backed up for the class
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $staticVars = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vars backed up for the test
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $vars = [];
|
||||||
|
|
||||||
|
public function setUp(SapphireTest $test)
|
||||||
|
{
|
||||||
|
$this->vars = Director::envToVars();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tearDown(SapphireTest $test)
|
||||||
|
{
|
||||||
|
Director::varsToEnv($this->vars);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUpOnce($class)
|
||||||
|
{
|
||||||
|
$this->staticVars = Director::envToVars();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tearDownOnce($class)
|
||||||
|
{
|
||||||
|
Director::varsToEnv($this->staticVars);
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace SilverStripe\Dev;
|
namespace SilverStripe\Dev\State;
|
||||||
|
|
||||||
use SilverStripe\Core\Injector\Injector;
|
use SilverStripe\Core\Injector\Injector;
|
||||||
use SilverStripe\Core\Kernel;
|
use SilverStripe\Core\Kernel;
|
||||||
use SilverStripe\Core\TestKernel;
|
use SilverStripe\Core\TestKernel;
|
||||||
|
use SilverStripe\Dev\SapphireTest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles nesting of kernel before / after tests
|
* Handles nesting of kernel before / after tests
|
@ -1,8 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace SilverStripe\Dev;
|
namespace SilverStripe\Dev\State;
|
||||||
|
|
||||||
use SilverStripe\Core\Injector\Injectable;
|
use SilverStripe\Core\Injector\Injectable;
|
||||||
|
use SilverStripe\Dev\Debug;
|
||||||
|
use SilverStripe\Dev\SapphireTest;
|
||||||
|
|
||||||
class SapphireTestState implements TestState
|
class SapphireTestState implements TestState
|
||||||
{
|
{
|
@ -1,6 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace SilverStripe\Dev;
|
namespace SilverStripe\Dev\State;
|
||||||
|
|
||||||
|
use SilverStripe\Dev\SapphireTest;
|
||||||
|
use SilverStripe\Dev\TestOnly;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper for resetting, booting, or cleaning up test state.
|
* Helper for resetting, booting, or cleaning up test state.
|
@ -4,7 +4,7 @@
|
|||||||
namespace SilverStripe\View\Dev;
|
namespace SilverStripe\View\Dev;
|
||||||
|
|
||||||
use SilverStripe\Dev\SapphireTest;
|
use SilverStripe\Dev\SapphireTest;
|
||||||
use SilverStripe\Dev\TestState;
|
use SilverStripe\Dev\State\TestState;
|
||||||
use SilverStripe\View\Requirements;
|
use SilverStripe\View\Requirements;
|
||||||
use SilverStripe\View\Requirements_Backend;
|
use SilverStripe\View\Requirements_Backend;
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ namespace SilverStripe\Control\Tests;
|
|||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use SilverStripe\Control\Controller;
|
use SilverStripe\Control\Controller;
|
||||||
use SilverStripe\Control\Director;
|
use SilverStripe\Control\Director;
|
||||||
use SilverStripe\Control\HTTPRequest;
|
|
||||||
use SilverStripe\Control\Tests\ControllerTest\AccessBaseController;
|
use SilverStripe\Control\Tests\ControllerTest\AccessBaseController;
|
||||||
use SilverStripe\Control\Tests\ControllerTest\AccessSecuredController;
|
use SilverStripe\Control\Tests\ControllerTest\AccessSecuredController;
|
||||||
use SilverStripe\Control\Tests\ControllerTest\AccessWildcardSecuredController;
|
use SilverStripe\Control\Tests\ControllerTest\AccessWildcardSecuredController;
|
||||||
@ -522,22 +521,12 @@ class ControllerTest extends FunctionalTest
|
|||||||
|
|
||||||
public function testSubActions()
|
public function testSubActions()
|
||||||
{
|
{
|
||||||
/* If a controller action returns another controller, ensure that the $action variable is correctly forwarded */
|
// If a controller action returns another controller, ensure that the $action variable is correctly forwarded
|
||||||
$response = $this->get("ContainerController/subcontroller/subaction");
|
$response = $this->get("ContainerController/subcontroller/subaction");
|
||||||
$this->assertEquals('subaction', $response->getBody());
|
$this->assertEquals('subaction', $response->getBody());
|
||||||
|
|
||||||
$request = new HTTPRequest(
|
// Handle nested action
|
||||||
'GET',
|
$response = $this->get('ContainerController/subcontroller/substring/subvieweraction');
|
||||||
'ContainerController/subcontroller/substring/subvieweraction'
|
$this->assertEquals('Hope this works', $response->getBody());
|
||||||
);
|
|
||||||
/* Shift to emulate the director selecting the controller */
|
|
||||||
$request->shift();
|
|
||||||
/* Handle the request to create conditions where improperly passing the action to the viewer might fail */
|
|
||||||
$controller = new ControllerTest\ContainerController();
|
|
||||||
try {
|
|
||||||
$controller->handleRequest($request);
|
|
||||||
} catch (ControllerTest\SubController_Exception $e) {
|
|
||||||
$this->fail($e->getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,10 +34,6 @@ class SubController extends Controller implements TestOnly
|
|||||||
|
|
||||||
public function subvieweraction()
|
public function subvieweraction()
|
||||||
{
|
{
|
||||||
return $this->customise(
|
return 'Hope this works';
|
||||||
array(
|
|
||||||
'Thoughts' => 'Hope this works',
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,31 +3,21 @@
|
|||||||
namespace SilverStripe\Control\Tests;
|
namespace SilverStripe\Control\Tests;
|
||||||
|
|
||||||
use SilverStripe\Control\Cookie_Backend;
|
use SilverStripe\Control\Cookie_Backend;
|
||||||
|
use SilverStripe\Control\Director;
|
||||||
use SilverStripe\Control\HTTPRequest;
|
use SilverStripe\Control\HTTPRequest;
|
||||||
use SilverStripe\Control\HTTPResponse;
|
use SilverStripe\Control\HTTPResponse;
|
||||||
use SilverStripe\Control\HTTPResponse_Exception;
|
use SilverStripe\Control\HTTPResponse_Exception;
|
||||||
use SilverStripe\Control\Tests\DirectorTest\TestController;
|
|
||||||
use SilverStripe\Core\Config\Config;
|
|
||||||
use SilverStripe\Core\Injector\Injector;
|
|
||||||
use SilverStripe\Dev\SapphireTest;
|
|
||||||
use SilverStripe\Control\Director;
|
|
||||||
use SilverStripe\Control\RequestProcessor;
|
use SilverStripe\Control\RequestProcessor;
|
||||||
use SilverStripe\Security\Security;
|
use SilverStripe\Control\Tests\DirectorTest\TestController;
|
||||||
|
use SilverStripe\Core\Injector\Injector;
|
||||||
|
use SilverStripe\Core\Kernel;
|
||||||
|
use SilverStripe\Dev\SapphireTest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @todo test Director::alternateBaseFolder()
|
* @todo test Director::alternateBaseFolder()
|
||||||
*/
|
*/
|
||||||
class DirectorTest extends SapphireTest
|
class DirectorTest extends SapphireTest
|
||||||
{
|
{
|
||||||
|
|
||||||
protected static $originalRequestURI;
|
|
||||||
|
|
||||||
protected $originalProtocolHeaders = array();
|
|
||||||
|
|
||||||
protected $originalGet = array();
|
|
||||||
|
|
||||||
protected $originalSession = array();
|
|
||||||
|
|
||||||
protected static $extra_controllers = [
|
protected static $extra_controllers = [
|
||||||
TestController::class,
|
TestController::class,
|
||||||
];
|
];
|
||||||
@ -35,28 +25,8 @@ class DirectorTest extends SapphireTest
|
|||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
Director::config()->set('alternate_base_url', 'http://www.mysite.com/');
|
||||||
// Hold the original request URI once so it doesn't get overwritten
|
$this->expectedRedirect = null;
|
||||||
if (!self::$originalRequestURI) {
|
|
||||||
self::$originalRequestURI = $_SERVER['REQUEST_URI'];
|
|
||||||
}
|
|
||||||
$_SERVER['REQUEST_URI'] = 'http://www.mysite.com';
|
|
||||||
|
|
||||||
$this->originalGet = $_GET;
|
|
||||||
$this->originalSession = $_SESSION;
|
|
||||||
$_SESSION = array();
|
|
||||||
|
|
||||||
$headers = array(
|
|
||||||
'HTTP_X_FORWARDED_PROTOCOL', 'HTTPS', 'SSL'
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ($headers as $header) {
|
|
||||||
if (isset($_SERVER[$header])) {
|
|
||||||
$this->originalProtocolHeaders[$header] = $_SERVER[$header];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Config::modify()->set(Director::class, 'alternate_base_url', '/');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getExtraRoutes()
|
protected function getExtraRoutes()
|
||||||
@ -77,24 +47,6 @@ class DirectorTest extends SapphireTest
|
|||||||
Director::config()->set('rules', $this->getExtraRoutes());
|
Director::config()->set('rules', $this->getExtraRoutes());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function tearDown()
|
|
||||||
{
|
|
||||||
$_GET = $this->originalGet;
|
|
||||||
$_SESSION = $this->originalSession;
|
|
||||||
|
|
||||||
// Reinstate the original REQUEST_URI after it was modified by some tests
|
|
||||||
$_SERVER['REQUEST_URI'] = self::$originalRequestURI;
|
|
||||||
|
|
||||||
if ($this->originalProtocolHeaders) {
|
|
||||||
foreach ($this->originalProtocolHeaders as $header => $value) {
|
|
||||||
$_SERVER[$header] = $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
parent::tearDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testFileExists()
|
public function testFileExists()
|
||||||
{
|
{
|
||||||
$tempFileName = 'DirectorTest_testFileExists.tmp';
|
$tempFileName = 'DirectorTest_testFileExists.tmp';
|
||||||
@ -118,55 +70,53 @@ class DirectorTest extends SapphireTest
|
|||||||
|
|
||||||
public function testAbsoluteURL()
|
public function testAbsoluteURL()
|
||||||
{
|
{
|
||||||
|
Director::config()->set('alternate_base_url', 'http://www.mysite.com/mysite/');
|
||||||
$rootURL = Director::protocolAndHost();
|
$_SERVER['REQUEST_URI'] = "http://www.mysite.com/mysite/sub-page/";
|
||||||
$_SERVER['REQUEST_URI'] = "$rootURL/mysite/sub-page/";
|
|
||||||
Director::config()->set('alternate_base_url', '/mysite/');
|
|
||||||
|
|
||||||
//test empty / local urls
|
//test empty / local urls
|
||||||
foreach (array('', './', '.') as $url) {
|
foreach (array('', './', '.') as $url) {
|
||||||
$this->assertEquals("$rootURL/mysite/", Director::absoluteURL($url, Director::BASE));
|
$this->assertEquals("http://www.mysite.com/mysite/", Director::absoluteURL($url, Director::BASE));
|
||||||
$this->assertEquals("$rootURL/", Director::absoluteURL($url, Director::ROOT));
|
$this->assertEquals("http://www.mysite.com/", Director::absoluteURL($url, Director::ROOT));
|
||||||
$this->assertEquals("$rootURL/mysite/sub-page/", Director::absoluteURL($url, Director::REQUEST));
|
$this->assertEquals("http://www.mysite.com/mysite/sub-page/", Director::absoluteURL($url, Director::REQUEST));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test site root url
|
// Test site root url
|
||||||
$this->assertEquals("$rootURL/", Director::absoluteURL('/'));
|
$this->assertEquals("http://www.mysite.com/", Director::absoluteURL('/'));
|
||||||
|
|
||||||
// Test Director::BASE
|
// Test Director::BASE
|
||||||
$this->assertEquals($rootURL, Director::absoluteURL($rootURL, Director::BASE));
|
$this->assertEquals('http://www.mysite.com/', Director::absoluteURL('http://www.mysite.com/', Director::BASE));
|
||||||
$this->assertEquals('http://www.mytest.com', Director::absoluteURL('http://www.mytest.com', Director::BASE));
|
$this->assertEquals('http://www.mytest.com', Director::absoluteURL('http://www.mytest.com', Director::BASE));
|
||||||
$this->assertEquals("$rootURL/test", Director::absoluteURL("$rootURL/test", Director::BASE));
|
$this->assertEquals("http://www.mysite.com/test", Director::absoluteURL("http://www.mysite.com/test", Director::BASE));
|
||||||
$this->assertEquals("$rootURL/root", Director::absoluteURL("/root", Director::BASE));
|
$this->assertEquals("http://www.mysite.com/root", Director::absoluteURL("/root", Director::BASE));
|
||||||
$this->assertEquals("$rootURL/root/url", Director::absoluteURL("/root/url", Director::BASE));
|
$this->assertEquals("http://www.mysite.com/root/url", Director::absoluteURL("/root/url", Director::BASE));
|
||||||
|
|
||||||
// Test Director::ROOT
|
// Test Director::ROOT
|
||||||
$this->assertEquals($rootURL, Director::absoluteURL($rootURL, Director::ROOT));
|
$this->assertEquals('http://www.mysite.com/', Director::absoluteURL('http://www.mysite.com/', Director::ROOT));
|
||||||
$this->assertEquals('http://www.mytest.com', Director::absoluteURL('http://www.mytest.com', Director::ROOT));
|
$this->assertEquals('http://www.mytest.com', Director::absoluteURL('http://www.mytest.com', Director::ROOT));
|
||||||
$this->assertEquals("$rootURL/test", Director::absoluteURL("$rootURL/test", Director::ROOT));
|
$this->assertEquals("http://www.mysite.com/test", Director::absoluteURL("http://www.mysite.com/test", Director::ROOT));
|
||||||
$this->assertEquals("$rootURL/root", Director::absoluteURL("/root", Director::ROOT));
|
$this->assertEquals("http://www.mysite.com/root", Director::absoluteURL("/root", Director::ROOT));
|
||||||
$this->assertEquals("$rootURL/root/url", Director::absoluteURL("/root/url", Director::ROOT));
|
$this->assertEquals("http://www.mysite.com/root/url", Director::absoluteURL("/root/url", Director::ROOT));
|
||||||
|
|
||||||
// Test Director::REQUEST
|
// Test Director::REQUEST
|
||||||
$this->assertEquals($rootURL, Director::absoluteURL($rootURL, Director::REQUEST));
|
$this->assertEquals('http://www.mysite.com/', Director::absoluteURL('http://www.mysite.com/', Director::REQUEST));
|
||||||
$this->assertEquals('http://www.mytest.com', Director::absoluteURL('http://www.mytest.com', Director::REQUEST));
|
$this->assertEquals('http://www.mytest.com', Director::absoluteURL('http://www.mytest.com', Director::REQUEST));
|
||||||
$this->assertEquals("$rootURL/test", Director::absoluteURL("$rootURL/test", Director::REQUEST));
|
$this->assertEquals("http://www.mysite.com/test", Director::absoluteURL("http://www.mysite.com/test", Director::REQUEST));
|
||||||
$this->assertEquals("$rootURL/root", Director::absoluteURL("/root", Director::REQUEST));
|
$this->assertEquals("http://www.mysite.com/root", Director::absoluteURL("/root", Director::REQUEST));
|
||||||
$this->assertEquals("$rootURL/root/url", Director::absoluteURL("/root/url", Director::REQUEST));
|
$this->assertEquals("http://www.mysite.com/root/url", Director::absoluteURL("/root/url", Director::REQUEST));
|
||||||
|
|
||||||
// Test evaluating relative urls relative to base (default)
|
// Test evaluating relative urls relative to base (default)
|
||||||
$this->assertEquals("$rootURL/mysite/test", Director::absoluteURL("test"));
|
$this->assertEquals("http://www.mysite.com/mysite/test", Director::absoluteURL("test"));
|
||||||
$this->assertEquals("$rootURL/mysite/test/url", Director::absoluteURL("test/url"));
|
$this->assertEquals("http://www.mysite.com/mysite/test/url", Director::absoluteURL("test/url"));
|
||||||
$this->assertEquals("$rootURL/mysite/test", Director::absoluteURL("test", Director::BASE));
|
$this->assertEquals("http://www.mysite.com/mysite/test", Director::absoluteURL("test", Director::BASE));
|
||||||
$this->assertEquals("$rootURL/mysite/test/url", Director::absoluteURL("test/url", Director::BASE));
|
$this->assertEquals("http://www.mysite.com/mysite/test/url", Director::absoluteURL("test/url", Director::BASE));
|
||||||
|
|
||||||
// Test evaluting relative urls relative to root
|
// Test evaluting relative urls relative to root
|
||||||
$this->assertEquals("$rootURL/test", Director::absoluteURL("test", Director::ROOT));
|
$this->assertEquals("http://www.mysite.com/test", Director::absoluteURL("test", Director::ROOT));
|
||||||
$this->assertEquals("$rootURL/test/url", Director::absoluteURL("test/url", Director::ROOT));
|
$this->assertEquals("http://www.mysite.com/test/url", Director::absoluteURL("test/url", Director::ROOT));
|
||||||
|
|
||||||
// Test relative to requested page
|
// Test relative to requested page
|
||||||
$this->assertEquals("$rootURL/mysite/sub-page/test", Director::absoluteURL("test", Director::REQUEST));
|
$this->assertEquals("http://www.mysite.com/mysite/sub-page/test", Director::absoluteURL("test", Director::REQUEST));
|
||||||
$this->assertEquals("$rootURL/mysite/sub-page/test/url", Director::absoluteURL("test/url", Director::REQUEST));
|
$this->assertEquals("http://www.mysite.com/mysite/sub-page/test/url", Director::absoluteURL("test/url", Director::REQUEST));
|
||||||
|
|
||||||
// Test that javascript links are not left intact
|
// Test that javascript links are not left intact
|
||||||
$this->assertStringStartsNotWith('javascript', Director::absoluteURL('javascript:alert("attack")'));
|
$this->assertStringStartsNotWith('javascript', Director::absoluteURL('javascript:alert("attack")'));
|
||||||
@ -177,17 +127,15 @@ class DirectorTest extends SapphireTest
|
|||||||
|
|
||||||
public function testAlternativeBaseURL()
|
public function testAlternativeBaseURL()
|
||||||
{
|
{
|
||||||
// Get original protocol and hostname
|
|
||||||
$rootURL = Director::protocolAndHost();
|
|
||||||
|
|
||||||
// relative base URLs - you should end them in a /
|
// relative base URLs - you should end them in a /
|
||||||
Director::config()->set('alternate_base_url', '/relativebase/');
|
Director::config()->set('alternate_base_url', '/relativebase/');
|
||||||
$_SERVER['REQUEST_URI'] = "$rootURL/relativebase/sub-page/";
|
$_SERVER['HTTP_HOST'] = 'www.somesite.com';
|
||||||
|
$_SERVER['REQUEST_URI'] = "/relativebase/sub-page/";
|
||||||
|
|
||||||
$this->assertEquals('/relativebase/', Director::baseURL());
|
$this->assertEquals('/relativebase/', Director::baseURL());
|
||||||
$this->assertEquals($rootURL . '/relativebase/', Director::absoluteBaseURL());
|
$this->assertEquals('http://www.somesite.com/relativebase/', Director::absoluteBaseURL());
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$rootURL . '/relativebase/subfolder/test',
|
'http://www.somesite.com/relativebase/subfolder/test',
|
||||||
Director::absoluteURL('subfolder/test')
|
Director::absoluteURL('subfolder/test')
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -336,6 +284,10 @@ class DirectorTest extends SapphireTest
|
|||||||
unset($_GET['isTest']);
|
unset($_GET['isTest']);
|
||||||
unset($_GET['isDev']);
|
unset($_GET['isDev']);
|
||||||
|
|
||||||
|
/** @var Kernel $kernel */
|
||||||
|
$kernel = Injector::inst()->get(Kernel::class);
|
||||||
|
$kernel->setEnvironment(null);
|
||||||
|
|
||||||
// Test isDev=1
|
// Test isDev=1
|
||||||
$_GET['isDev'] = '1';
|
$_GET['isDev'] = '1';
|
||||||
$this->assertTrue(Director::isDev());
|
$this->assertTrue(Director::isDev());
|
||||||
@ -399,28 +351,40 @@ class DirectorTest extends SapphireTest
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTestRequestCarriesGlobals()
|
public function providerTestTestRequestCarriesGlobals()
|
||||||
{
|
{
|
||||||
$fixture = array('somekey' => 'sometestvalue');
|
$tests = [];
|
||||||
|
$fixture = [ 'somekey' => 'sometestvalue' ];
|
||||||
foreach (array('get', 'post') as $method) {
|
foreach (array('get', 'post') as $method) {
|
||||||
foreach (array('return%sValue', 'returnRequestValue', 'returnCookieValue') as $testfunction) {
|
foreach (array('return%sValue', 'returnRequestValue', 'returnCookieValue') as $testfunction) {
|
||||||
$url = 'TestController/' . sprintf($testfunction, ucfirst($method))
|
$url = 'TestController/' . sprintf($testfunction, ucfirst($method))
|
||||||
. '?' . http_build_query($fixture);
|
. '?' . http_build_query($fixture);
|
||||||
|
$tests[] = [$url, $fixture, $method];
|
||||||
$getresponse = Director::test(
|
|
||||||
$url,
|
|
||||||
$fixture,
|
|
||||||
null,
|
|
||||||
strtoupper($method),
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
Injector::inst()->createWithArgs(Cookie_Backend::class, array($fixture))
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertInstanceOf(HTTPResponse::class, $getresponse, 'Director::test() returns HTTPResponse');
|
|
||||||
$this->assertEquals($fixture['somekey'], $getresponse->getBody(), 'Director::test() ' . $testfunction);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return $tests;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerTestTestRequestCarriesGlobals
|
||||||
|
* @param $url
|
||||||
|
* @param $fixture
|
||||||
|
* @param $method
|
||||||
|
*/
|
||||||
|
public function testTestRequestCarriesGlobals($url, $fixture, $method)
|
||||||
|
{
|
||||||
|
$getresponse = Director::test(
|
||||||
|
$url,
|
||||||
|
$fixture,
|
||||||
|
null,
|
||||||
|
strtoupper($method),
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
Injector::inst()->createWithArgs(Cookie_Backend::class, array($fixture))
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertInstanceOf(HTTPResponse::class, $getresponse, 'Director::test() returns HTTPResponse');
|
||||||
|
$this->assertEquals($fixture['somekey'], $getresponse->getBody(), "Director::test({$url}, {$method})");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -446,46 +410,87 @@ class DirectorTest extends SapphireTest
|
|||||||
|
|
||||||
public function testForceSSLProtectsEntireSite()
|
public function testForceSSLProtectsEntireSite()
|
||||||
{
|
{
|
||||||
$_SERVER['REQUEST_URI'] = '/admin';
|
$this->expectExceptionRedirect('https://www.mysite.com/some-url');
|
||||||
$output = Director::forceSSL();
|
Director::mockRequest(function () {
|
||||||
$this->assertEquals($output, 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
|
Director::forceSSL();
|
||||||
|
}, '/some-url');
|
||||||
$_SERVER['REQUEST_URI'] = Director::baseURL() . 'some-url';
|
|
||||||
$output = Director::forceSSL();
|
|
||||||
$this->assertEquals($output, 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testForceSSLOnTopLevelPagePattern()
|
public function testForceSSLOnTopLevelPagePattern()
|
||||||
{
|
{
|
||||||
$_SERVER['REQUEST_URI'] = Director::baseURL() . 'admin';
|
// Expect admin to trigger redirect
|
||||||
$output = Director::forceSSL(array('/^admin/'));
|
$this->expectExceptionRedirect('https://www.mysite.com/admin');
|
||||||
$this->assertEquals($output, 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
|
Director::mockRequest(function () {
|
||||||
|
Director::forceSSL(array('/^admin/'));
|
||||||
|
}, '/admin');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testForceSSLOnSubPagesPattern()
|
public function testForceSSLOnSubPagesPattern()
|
||||||
{
|
{
|
||||||
$_SERVER['REQUEST_URI'] = Director::baseURL() . Config::inst()->get(Security::class, 'login_url');
|
// Expect to redirect to security login page
|
||||||
$output = Director::forceSSL(array('/^Security/'));
|
$this->expectExceptionRedirect('https://www.mysite.com/Security/login');
|
||||||
$this->assertEquals($output, 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
|
Director::mockRequest(function () {
|
||||||
|
Director::forceSSL(array('/^Security/'));
|
||||||
|
}, '/Security/login');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testForceSSLWithPatternDoesNotMatchOtherPages()
|
public function testForceSSLWithPatternDoesNotMatchOtherPages()
|
||||||
{
|
{
|
||||||
$_SERVER['REQUEST_URI'] = Director::baseURL() . 'normal-page';
|
// Not on same url should not trigger redirect
|
||||||
$output = Director::forceSSL(array('/^admin/'));
|
Director::mockRequest(function () {
|
||||||
$this->assertFalse($output);
|
$this->assertFalse(Director::forceSSL(array('/^admin/')));
|
||||||
|
}, Director::baseURL() . 'normal-page');
|
||||||
|
|
||||||
$_SERVER['REQUEST_URI'] = Director::baseURL() . 'just-another-page/sub-url';
|
// nested url should not triger redirect either
|
||||||
$output = Director::forceSSL(array('/^admin/', '/^Security/'));
|
Director::mockRequest(function () {
|
||||||
$this->assertFalse($output);
|
$this->assertFalse(Director::forceSSL(array('/^admin/', '/^Security/')));
|
||||||
|
}, Director::baseURL() . 'just-another-page/sub-url');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testForceSSLAlternateDomain()
|
public function testForceSSLAlternateDomain()
|
||||||
{
|
{
|
||||||
Director::config()->set('alternate_base_url', '/');
|
// Ensure that forceSSL throws the appropriate exception
|
||||||
$_SERVER['REQUEST_URI'] = Director::baseURL() . 'admin';
|
$this->expectExceptionRedirect('https://secure.mysite.com/admin');
|
||||||
$output = Director::forceSSL(array('/^admin/'), 'secure.mysite.com');
|
Director::mockRequest(function (HTTPRequest $request) {
|
||||||
$this->assertEquals($output, 'https://secure.mysite.com/admin');
|
return Director::forceSSL(array('/^admin/'), 'secure.mysite.com');
|
||||||
|
}, Director::baseURL() . 'admin');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set url to redirect to
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $expectedRedirect = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expects this test to throw a HTTPResponse_Exception with the given redirect
|
||||||
|
*
|
||||||
|
* @param string $url
|
||||||
|
*/
|
||||||
|
protected function expectExceptionRedirect($url)
|
||||||
|
{
|
||||||
|
$this->expectedRedirect = $url;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function runTest()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$result = parent::runTest();
|
||||||
|
if ($this->expectedRedirect) {
|
||||||
|
$this->fail("Expected to redirect to {$this->expectedRedirect} but no redirect found");
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
} catch (HTTPResponse_Exception $exception) {
|
||||||
|
// Check URL
|
||||||
|
if ($this->expectedRedirect) {
|
||||||
|
$url = $exception->getResponse()->getHeader('Location');
|
||||||
|
$this->assertEquals($this->expectedRedirect, $url, "Expected to redirect to {$this->expectedRedirect}");
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
throw $exception;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -614,28 +619,30 @@ class DirectorTest extends SapphireTest
|
|||||||
$processor = new RequestProcessor(array($filter));
|
$processor = new RequestProcessor(array($filter));
|
||||||
|
|
||||||
Injector::inst()->registerService($processor, RequestProcessor::class);
|
Injector::inst()->registerService($processor, RequestProcessor::class);
|
||||||
|
$response = Director::test('some-dummy-url');
|
||||||
Director::test('some-dummy-url');
|
$this->assertEquals(404, $response->getStatusCode());
|
||||||
|
|
||||||
$this->assertEquals(1, $filter->preCalls);
|
$this->assertEquals(1, $filter->preCalls);
|
||||||
$this->assertEquals(1, $filter->postCalls);
|
$this->assertEquals(1, $filter->postCalls);
|
||||||
|
|
||||||
$filter->failPost = true;
|
$filter->failPost = true;
|
||||||
|
|
||||||
$this->expectException(HTTPResponse_Exception::class);
|
$response = Director::test('some-dummy-url');
|
||||||
|
$this->assertEquals(500, $response->getStatusCode());
|
||||||
Director::test('some-dummy-url');
|
$this->assertEquals(_t(Director::class.'.REQUEST_ABORTED', 'Request aborted'), $response->getBody());
|
||||||
|
|
||||||
$this->assertEquals(2, $filter->preCalls);
|
$this->assertEquals(2, $filter->preCalls);
|
||||||
$this->assertEquals(2, $filter->postCalls);
|
$this->assertEquals(2, $filter->postCalls);
|
||||||
|
|
||||||
$filter->failPre = true;
|
$filter->failPre = true;
|
||||||
|
|
||||||
Director::test('some-dummy-url');
|
$response = Director::test('some-dummy-url');
|
||||||
|
$this->assertEquals(400, $response->getStatusCode());
|
||||||
|
$this->assertEquals(_t(Director::class.'.INVALID_REQUEST', 'Invalid request'), $response->getBody());
|
||||||
|
|
||||||
$this->assertEquals(3, $filter->preCalls);
|
$this->assertEquals(3, $filter->preCalls);
|
||||||
|
|
||||||
// preCall 'false' will trigger an exception and prevent post call execution
|
// preCall 'true' will trigger an exception and prevent post call execution
|
||||||
$this->assertEquals(2, $filter->postCalls);
|
$this->assertEquals(2, $filter->postCalls);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,21 +26,33 @@ class TestController extends Controller implements TestOnly
|
|||||||
|
|
||||||
public function returnGetValue($request)
|
public function returnGetValue($request)
|
||||||
{
|
{
|
||||||
return $_GET['somekey'];
|
if (isset($_GET['somekey'])) {
|
||||||
|
return $_GET['somekey'];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function returnPostValue($request)
|
public function returnPostValue($request)
|
||||||
{
|
{
|
||||||
return $_POST['somekey'];
|
if (isset($_POST['somekey'])) {
|
||||||
|
return $_POST['somekey'];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function returnRequestValue($request)
|
public function returnRequestValue($request)
|
||||||
{
|
{
|
||||||
return $_REQUEST['somekey'];
|
if (isset($_REQUEST['somekey'])) {
|
||||||
|
return $_REQUEST['somekey'];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function returnCookieValue($request)
|
public function returnCookieValue($request)
|
||||||
{
|
{
|
||||||
return $_COOKIE['somekey'];
|
if (isset($_COOKIE['somekey'])) {
|
||||||
|
return $_COOKIE['somekey'];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,7 @@ class FlushRequestFilterTest extends FunctionalTest
|
|||||||
public function testImplementorsAreCalled()
|
public function testImplementorsAreCalled()
|
||||||
{
|
{
|
||||||
TestFlushable::$flushed = false;
|
TestFlushable::$flushed = false;
|
||||||
|
|
||||||
$this->get('?flush=1');
|
$this->get('?flush=1');
|
||||||
|
|
||||||
$this->assertTrue(TestFlushable::$flushed);
|
$this->assertTrue(TestFlushable::$flushed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ use SilverStripe\Dev\TestOnly;
|
|||||||
|
|
||||||
class TestFlushable implements Flushable, TestOnly
|
class TestFlushable implements Flushable, TestOnly
|
||||||
{
|
{
|
||||||
|
|
||||||
public static $flushed = false;
|
public static $flushed = false;
|
||||||
|
|
||||||
public static function flush()
|
public static function flush()
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
namespace SilverStripe\Control\Tests;
|
namespace SilverStripe\Control\Tests;
|
||||||
|
|
||||||
use SilverStripe\Control\Session;
|
use SilverStripe\Control\Session;
|
||||||
use SilverStripe\Core\Config\Config;
|
|
||||||
use SilverStripe\Dev\SapphireTest;
|
use SilverStripe\Dev\SapphireTest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -105,14 +104,6 @@ class SessionTest extends SapphireTest
|
|||||||
$this->assertEquals(array('something' => array('does' => null)), $result);
|
$this->assertEquals(array('something' => array('does' => null)), $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNonStandardPath()
|
|
||||||
{
|
|
||||||
Session::config()->set('store_path', (realpath(dirname($_SERVER['DOCUMENT_ROOT']) . '/../session')));
|
|
||||||
$this->session->start();
|
|
||||||
|
|
||||||
$this->assertEquals(Config::inst()->get('SilverStripe\\Control\\Session', 'store_path'), '');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testUserAgentLockout()
|
public function testUserAgentLockout()
|
||||||
{
|
{
|
||||||
// Set a user agent
|
// Set a user agent
|
||||||
@ -120,6 +111,7 @@ class SessionTest extends SapphireTest
|
|||||||
|
|
||||||
// Generate our session
|
// Generate our session
|
||||||
$s = new Session(array());
|
$s = new Session(array());
|
||||||
|
$s->init();
|
||||||
$s->set('val', 123);
|
$s->set('val', 123);
|
||||||
$s->finalize();
|
$s->finalize();
|
||||||
|
|
||||||
@ -128,6 +120,7 @@ class SessionTest extends SapphireTest
|
|||||||
|
|
||||||
// Verify the new session reset our values
|
// Verify the new session reset our values
|
||||||
$s2 = new Session($s);
|
$s2 = new Session($s);
|
||||||
|
$s2->init();
|
||||||
$this->assertNotEquals($s2->get('val'), 123);
|
$this->assertNotEquals($s2->get('val'), 123);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user