diff --git a/tests/php/Control/DirectorTest.php b/tests/php/Control/DirectorTest.php
index 780e252a8..c7afcb0e8 100644
--- a/tests/php/Control/DirectorTest.php
+++ b/tests/php/Control/DirectorTest.php
@@ -518,7 +518,7 @@ class DirectorTest extends SapphireTest
'Content-Length' => '10'
);
- $this->assertEquals($headers, Director::extract_request_headers($request));
+ $this->assertEquals($headers, HTTPRequest::extractRequestHeaders($request));
}
public function testUnmatchedRequestReturns404()
@@ -622,7 +622,7 @@ class DirectorTest extends SapphireTest
$filter->failPost = true;
- $this->setExpectedException(HTTPResponse_Exception::class);
+ $this->expectException(HTTPResponse_Exception::class);
Director::test('some-dummy-url');
diff --git a/tests/php/Control/HTTPTest.php b/tests/php/Control/HTTPTest.php
index 840eaf4cf..c5cc96fec 100644
--- a/tests/php/Control/HTTPTest.php
+++ b/tests/php/Control/HTTPTest.php
@@ -2,10 +2,11 @@
namespace SilverStripe\Control\Tests;
-use SilverStripe\Control\Director;
-use SilverStripe\Dev\FunctionalTest;
-use SilverStripe\Control\HTTPResponse;
use SilverStripe\Control\HTTP;
+use SilverStripe\Control\HTTPResponse;
+use SilverStripe\Core\Injector\Injector;
+use SilverStripe\Core\Kernel;
+use SilverStripe\Dev\FunctionalTest;
/**
* Tests the {@link HTTP} class
@@ -27,13 +28,15 @@ class HTTPTest extends FunctionalTest
$this->assertNotEmpty($response->getHeader('Cache-Control'));
// Ensure max-age is zero for development.
- Director::set_environment_type('dev');
+ /** @var Kernel $kernel */
+ $kernel = Injector::inst()->get(Kernel::class);
+ $kernel->setEnvironment(Kernel::DEV);
$response = new HTTPResponse($body, 200);
HTTP::add_cache_headers($response);
$this->assertContains('max-age=0', $response->getHeader('Cache-Control'));
// Ensure max-age setting is respected in production.
- Director::set_environment_type('live');
+ $kernel->setEnvironment(Kernel::LIVE);
$response = new HTTPResponse($body, 200);
HTTP::add_cache_headers($response);
$this->assertContains('max-age=30', explode(', ', $response->getHeader('Cache-Control')));
@@ -57,9 +60,11 @@ class HTTPTest extends FunctionalTest
public function testConfigVary()
{
+ /** @var Kernel $kernel */
+ $kernel = Injector::inst()->get(Kernel::class);
$body = "
Mysite
";
$response = new HTTPResponse($body, 200);
- Director::set_environment_type('live');
+ $kernel->setEnvironment(Kernel::LIVE);
HTTP::set_cache_age(30);
HTTP::add_cache_headers($response);
@@ -206,30 +211,30 @@ class HTTPTest extends FunctionalTest
{
$this->withBaseURL(
'http://www.silverstripe.org/',
- function ($test) {
+ function () {
// background-image
// Note that using /./ in urls is absolutely acceptable
- $test->assertEquals(
+ $this->assertEquals(
''.
'Content
',
HTTP::absoluteURLs('Content
')
);
// background
- $test->assertEquals(
+ $this->assertEquals(
'Content
',
HTTP::absoluteURLs('Content
')
);
// list-style-image
- $test->assertEquals(
+ $this->assertEquals(
'Content
',
HTTP::absoluteURLs('Content
')
);
// list-style
- $test->assertEquals(
+ $this->assertEquals(
'Content
',
HTTP::absoluteURLs('Content
')
);
@@ -244,37 +249,37 @@ class HTTPTest extends FunctionalTest
{
$this->withBaseURL(
'http://www.silverstripe.org/',
- function ($test) {
+ function () {
//empty links
- $test->assertEquals(
+ $this->assertEquals(
'test',
HTTP::absoluteURLs('test')
);
- $test->assertEquals(
+ $this->assertEquals(
'test',
HTTP::absoluteURLs('test')
);
//relative
- $test->assertEquals(
+ $this->assertEquals(
'test',
HTTP::absoluteURLs('test')
);
- $test->assertEquals(
+ $this->assertEquals(
'test',
HTTP::absoluteURLs('test')
);
// links
- $test->assertEquals(
+ $this->assertEquals(
'SS Blog',
HTTP::absoluteURLs('SS Blog')
);
// background
// Note that using /./ in urls is absolutely acceptable
- $test->assertEquals(
+ $this->assertEquals(
''.
'SS Blog
',
HTTP::absoluteURLs('SS Blog
')
@@ -283,25 +288,25 @@ class HTTPTest extends FunctionalTest
//check dot segments
// Assumption: dots are not removed
//if they were, the url should be: http://www.silverstripe.org/abc
- $test->assertEquals(
+ $this->assertEquals(
'Test',
HTTP::absoluteURLs('Test')
);
// image
- $test->assertEquals(
+ $this->assertEquals(
'',
HTTP::absoluteURLs('')
);
// link
- $test->assertEquals(
+ $this->assertEquals(
'',
HTTP::absoluteURLs('')
);
// Test special characters are retained
- $test->assertEquals(
+ $this->assertEquals(
'password reset link',
HTTP::absoluteURLs('password reset link')
);
@@ -319,14 +324,14 @@ class HTTPTest extends FunctionalTest
function ($test) {
// mailto
- $test->assertEquals(
+ $this->assertEquals(
'Email Us',
HTTP::absoluteURLs('Email Us'),
'Email links are not rewritten'
);
// data uri
- $test->assertEquals(
+ $this->assertEquals(
'',
HTTP::absoluteURLs(
@@ -337,7 +342,7 @@ class HTTPTest extends FunctionalTest
);
// call
- $test->assertEquals(
+ $this->assertEquals(
'',
HTTP::absoluteURLs(''),
'Call to links are not rewritten'
@@ -352,7 +357,7 @@ class HTTPTest extends FunctionalTest
'http://www.silverstripe.org/',
function ($test) {
$frameworkTests = ltrim(FRAMEWORK_DIR . '/tests', '/');
- $test->assertEquals(
+ $this->assertEquals(
"http://www.silverstripe.org/$frameworkTests/php/Control/HTTPTest.php",
HTTP::filename2url(__FILE__)
);
diff --git a/tests/php/Control/SessionTest.php b/tests/php/Control/SessionTest.php
index d64cab649..145e189b8 100644
--- a/tests/php/Control/SessionTest.php
+++ b/tests/php/Control/SessionTest.php
@@ -2,53 +2,62 @@
namespace SilverStripe\Control\Tests;
-use SilverStripe\Core\Config\Config;
-use SilverStripe\Core\Injector\Injector;
-use SilverStripe\Dev\SapphireTest;
use SilverStripe\Control\Session;
+use SilverStripe\Core\Config\Config;
+use SilverStripe\Dev\SapphireTest;
/**
* Tests to cover the {@link Session} class
*/
class SessionTest extends SapphireTest
{
+ /**
+ * @var Session
+ */
+ protected $session = null;
+
+ protected function setUp()
+ {
+ $this->session = new Session([]);
+ return parent::setUp();
+ }
public function testGetSetBasics()
{
- Session::set('Test', 'Test');
+ $this->session->set('Test', 'Test');
- $this->assertEquals(Session::get('Test'), 'Test');
+ $this->assertEquals($this->session->get('Test'), 'Test');
}
public function testClearElement()
{
- Session::set('Test', 'Test');
- Session::clear('Test');
+ $this->session->set('Test', 'Test');
+ $this->session->clear('Test');
- $this->assertEquals(Session::get('Test'), '');
+ $this->assertEquals($this->session->get('Test'), '');
}
public function testClearAllElements()
{
- Session::set('Test', 'Test');
- Session::set('Test-1', 'Test-1');
+ $this->session->set('Test', 'Test');
+ $this->session->set('Test-1', 'Test-1');
- Session::clear_all();
+ $this->session->clearAll();
// should session get return null? The array key should probably be
// unset from the data array
- $this->assertEquals(Session::get('Test'), '');
- $this->assertEquals(Session::get('Test-1'), '');
+ $this->assertEquals($this->session->get('Test'), '');
+ $this->assertEquals($this->session->get('Test-1'), '');
}
public function testGetAllElements()
{
- Session::clear_all(); // Remove all session that might've been set by the test harness
+ $this->session->clearAll(); // Remove all session that might've been set by the test harness
- Session::set('Test', 'Test');
- Session::set('Test-2', 'Test-2');
+ $this->session->set('Test', 'Test');
+ $this->session->set('Test-2', 'Test-2');
- $session = Session::get_all();
+ $session = $this->session->getAll();
unset($session['HTTP_USER_AGENT']);
$this->assertEquals($session, array('Test' => 'Test', 'Test-2' => 'Test-2'));
@@ -56,10 +65,10 @@ class SessionTest extends SapphireTest
public function testSettingExistingDoesntClear()
{
- $s = Injector::inst()->create('SilverStripe\\Control\\Session', array('something' => array('does' => 'exist')));
+ $s = new Session(array('something' => array('does' => 'exist')));
- $s->inst_set('something.does', 'exist');
- $result = $s->inst_changedData();
+ $s->set('something.does', 'exist');
+ $result = $s->changedData();
unset($result['HTTP_USER_AGENT']);
$this->assertEquals(array(), $result);
}
@@ -69,16 +78,16 @@ class SessionTest extends SapphireTest
*/
public function testClearElementThatDoesntExist()
{
- $s = Injector::inst()->create('SilverStripe\\Control\\Session', array('something' => array('does' => 'exist')));
+ $s = new Session(array('something' => array('does' => 'exist')));
- $s->inst_clear('something.doesnt.exist');
- $result = $s->inst_changedData();
+ $s->clear('something.doesnt.exist');
+ $result = $s->changedData();
unset($result['HTTP_USER_AGENT']);
$this->assertEquals(array(), $result);
- $s->inst_set('something-else', 'val');
- $s->inst_clear('something-new');
- $result = $s->inst_changedData();
+ $s->set('something-else', 'val');
+ $s->clear('something-new');
+ $result = $s->changedData();
unset($result['HTTP_USER_AGENT']);
$this->assertEquals(array('something-else' => 'val'), $result);
}
@@ -88,18 +97,18 @@ class SessionTest extends SapphireTest
*/
public function testClearElementThatDoesExist()
{
- $s = Injector::inst()->create('SilverStripe\\Control\\Session', array('something' => array('does' => 'exist')));
+ $s = new Session(array('something' => array('does' => 'exist')));
- $s->inst_clear('something.does');
- $result = $s->inst_changedData();
+ $s->clear('something.does');
+ $result = $s->changedData();
unset($result['HTTP_USER_AGENT']);
$this->assertEquals(array('something' => array('does' => null)), $result);
}
public function testNonStandardPath()
{
- Config::inst()->update('SilverStripe\\Control\\Session', 'store_path', (realpath(dirname($_SERVER['DOCUMENT_ROOT']) . '/../session')));
- Session::start();
+ Session::config()->set('store_path', (realpath(dirname($_SERVER['DOCUMENT_ROOT']) . '/../session')));
+ $this->session->start();
$this->assertEquals(Config::inst()->get('SilverStripe\\Control\\Session', 'store_path'), '');
}
@@ -110,15 +119,15 @@ class SessionTest extends SapphireTest
$_SERVER['HTTP_USER_AGENT'] = 'Test Agent';
// Generate our session
- $s = Injector::inst()->create('SilverStripe\\Control\\Session', array());
- $s->inst_set('val', 123);
- $s->inst_finalize();
+ $s = new Session(array());
+ $s->set('val', 123);
+ $s->finalize();
// Change our UA
$_SERVER['HTTP_USER_AGENT'] = 'Fake Agent';
// Verify the new session reset our values
- $s2 = Injector::inst()->create('SilverStripe\\Control\\Session', $s);
- $this->assertNotEquals($s2->inst_get('val'), 123);
+ $s2 = new Session($s);
+ $this->assertNotEquals($s2->get('val'), 123);
}
}