2008-08-09 05:54:55 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class HTTPRequestTest extends SapphireTest {
|
|
|
|
static $fixture_file = null;
|
|
|
|
|
|
|
|
function testMatch() {
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
$request = new SS_HTTPRequest("GET", "admin/crm/add");
|
2008-08-09 05:54:55 +02:00
|
|
|
|
|
|
|
/* When a rule matches, but has no variables, array("_matched" => true) is returned. */
|
|
|
|
$this->assertEquals(array("_matched" => true), $request->match('admin/crm', true));
|
|
|
|
|
|
|
|
/* Becasue we shifted admin/crm off the stack, just "add" should be remaining */
|
|
|
|
$this->assertEquals("add", $request->remaining());
|
|
|
|
|
|
|
|
$this->assertEquals(array("_matched" => true), $request->match('add', true));
|
|
|
|
}
|
|
|
|
|
2008-10-06 16:58:01 +02:00
|
|
|
public function testHttpMethodOverrides() {
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
$request = new SS_HTTPRequest(
|
2008-10-06 16:58:01 +02:00
|
|
|
'GET',
|
|
|
|
'admin/crm'
|
|
|
|
);
|
|
|
|
$this->assertTrue(
|
|
|
|
$request->isGET(),
|
|
|
|
'GET with no method override'
|
|
|
|
);
|
|
|
|
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
$request = new SS_HTTPRequest(
|
2008-10-06 16:58:01 +02:00
|
|
|
'POST',
|
|
|
|
'admin/crm'
|
|
|
|
);
|
|
|
|
$this->assertTrue(
|
|
|
|
$request->isPOST(),
|
|
|
|
'POST with no method override'
|
|
|
|
);
|
|
|
|
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
$request = new SS_HTTPRequest(
|
2008-10-06 16:58:01 +02:00
|
|
|
'GET',
|
|
|
|
'admin/crm',
|
|
|
|
array('_method' => 'DELETE')
|
|
|
|
);
|
|
|
|
$this->assertTrue(
|
|
|
|
$request->isGET(),
|
|
|
|
'GET with invalid POST method override'
|
|
|
|
);
|
|
|
|
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
$request = new SS_HTTPRequest(
|
2008-10-06 16:58:01 +02:00
|
|
|
'POST',
|
|
|
|
'admin/crm',
|
|
|
|
array(),
|
|
|
|
array('_method' => 'DELETE')
|
|
|
|
);
|
|
|
|
$this->assertTrue(
|
|
|
|
$request->isDELETE(),
|
|
|
|
'POST with valid method override to DELETE'
|
|
|
|
);
|
|
|
|
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
$request = new SS_HTTPRequest(
|
2008-10-06 16:58:01 +02:00
|
|
|
'POST',
|
|
|
|
'admin/crm',
|
|
|
|
array(),
|
|
|
|
array('_method' => 'put')
|
|
|
|
);
|
|
|
|
$this->assertTrue(
|
|
|
|
$request->isPUT(),
|
|
|
|
'POST with valid method override to PUT'
|
|
|
|
);
|
|
|
|
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
$request = new SS_HTTPRequest(
|
2008-10-06 16:58:01 +02:00
|
|
|
'POST',
|
|
|
|
'admin/crm',
|
|
|
|
array(),
|
|
|
|
array('_method' => 'head')
|
|
|
|
);
|
|
|
|
$this->assertTrue(
|
|
|
|
$request->isHEAD(),
|
|
|
|
'POST with valid method override to HEAD '
|
|
|
|
);
|
|
|
|
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
$request = new SS_HTTPRequest(
|
2008-10-06 16:58:01 +02:00
|
|
|
'POST',
|
|
|
|
'admin/crm',
|
|
|
|
array(),
|
|
|
|
array('_method' => 'head')
|
|
|
|
);
|
|
|
|
$this->assertTrue(
|
|
|
|
$request->isHEAD(),
|
|
|
|
'POST with valid method override to HEAD'
|
|
|
|
);
|
|
|
|
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
$request = new SS_HTTPRequest(
|
2008-10-06 16:58:01 +02:00
|
|
|
'POST',
|
|
|
|
'admin/crm',
|
|
|
|
array('_method' => 'head')
|
|
|
|
);
|
|
|
|
$this->assertTrue(
|
|
|
|
$request->isPOST(),
|
|
|
|
'POST with invalid method override by GET parameters to HEAD'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-12-22 23:04:44 +01:00
|
|
|
public function testRequestVars() {
|
|
|
|
$getVars = array(
|
|
|
|
'first' => 'a',
|
|
|
|
'second' => 'b',
|
|
|
|
);
|
|
|
|
$postVars = array(
|
|
|
|
'third' => 'c',
|
|
|
|
'fourth' => 'd',
|
|
|
|
);
|
|
|
|
$requestVars = array(
|
|
|
|
'first' => 'a',
|
|
|
|
'second' => 'b',
|
|
|
|
'third' => 'c',
|
|
|
|
'fourth' => 'd',
|
|
|
|
);
|
|
|
|
$request = new SS_HTTPRequest(
|
|
|
|
'POST',
|
|
|
|
'admin/crm',
|
|
|
|
$getVars,
|
|
|
|
$postVars
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
$requestVars,
|
|
|
|
$request->requestVars(),
|
|
|
|
'GET parameters should supplement POST parameters'
|
|
|
|
);
|
|
|
|
|
|
|
|
$getVars = array(
|
|
|
|
'first' => 'a',
|
|
|
|
'second' => 'b',
|
|
|
|
);
|
|
|
|
$postVars = array(
|
|
|
|
'first' => 'c',
|
|
|
|
'third' => 'd',
|
|
|
|
);
|
|
|
|
$requestVars = array(
|
|
|
|
'first' => 'c',
|
|
|
|
'second' => 'b',
|
|
|
|
'third' => 'd',
|
|
|
|
);
|
|
|
|
$request = new SS_HTTPRequest(
|
|
|
|
'POST',
|
|
|
|
'admin/crm',
|
|
|
|
$getVars,
|
|
|
|
$postVars
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
$requestVars,
|
|
|
|
$request->requestVars(),
|
|
|
|
'POST parameters should override GET parameters'
|
|
|
|
);
|
|
|
|
|
|
|
|
$getVars = array(
|
|
|
|
'first' => array(
|
|
|
|
'first' => 'a',
|
|
|
|
),
|
|
|
|
'second' => array(
|
|
|
|
'second' => 'b',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
$postVars = array(
|
|
|
|
'first' => array(
|
|
|
|
'first' => 'c',
|
|
|
|
),
|
|
|
|
'third' => array(
|
|
|
|
'third' => 'd',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
$requestVars = array(
|
|
|
|
'first' => array(
|
|
|
|
'first' => 'c',
|
|
|
|
),
|
|
|
|
'second' => array(
|
|
|
|
'second' => 'b',
|
|
|
|
),
|
|
|
|
'third' => array(
|
|
|
|
'third' => 'd',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
$request = new SS_HTTPRequest(
|
|
|
|
'POST',
|
|
|
|
'admin/crm',
|
|
|
|
$getVars,
|
|
|
|
$postVars
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
$requestVars,
|
|
|
|
$request->requestVars(),
|
|
|
|
'Nested POST parameters should override GET parameters'
|
|
|
|
);
|
|
|
|
|
|
|
|
$getVars = array(
|
|
|
|
'first' => array(
|
|
|
|
'first' => 'a',
|
|
|
|
),
|
|
|
|
'second' => array(
|
|
|
|
'second' => 'b',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
$postVars = array(
|
|
|
|
'first' => array(
|
|
|
|
'second' => 'c',
|
|
|
|
),
|
|
|
|
'third' => array(
|
|
|
|
'third' => 'd',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
$requestVars = array(
|
|
|
|
'first' => array(
|
|
|
|
'first' => 'a',
|
|
|
|
'second' => 'c',
|
|
|
|
),
|
|
|
|
'second' => array(
|
|
|
|
'second' => 'b',
|
|
|
|
),
|
|
|
|
'third' => array(
|
|
|
|
'third' => 'd',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
$request = new SS_HTTPRequest(
|
|
|
|
'POST',
|
|
|
|
'admin/crm',
|
|
|
|
$getVars,
|
|
|
|
$postVars
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
$requestVars,
|
|
|
|
$request->requestVars(),
|
|
|
|
'Nested GET parameters should supplement POST parameters'
|
|
|
|
);
|
|
|
|
}
|
2012-04-05 14:44:42 +02:00
|
|
|
|
|
|
|
function testIsAjax() {
|
|
|
|
$req = new SS_HTTPRequest('GET', '/', array('ajax' => 0));
|
|
|
|
$this->assertFalse($req->isAjax());
|
|
|
|
|
|
|
|
$req = new SS_HTTPRequest('GET', '/', array('ajax' => 1));
|
|
|
|
$this->assertTrue($req->isAjax());
|
|
|
|
|
|
|
|
$req = new SS_HTTPRequest('GET', '/');
|
|
|
|
$req->addHeader('X-Requested-With', 'XMLHttpRequest');
|
|
|
|
$this->assertTrue($req->isAjax());
|
|
|
|
}
|
2012-06-29 12:02:30 +02:00
|
|
|
|
|
|
|
public function testGetURL() {
|
|
|
|
$req = new SS_HTTPRequest('GET', '/');
|
|
|
|
$this->assertEquals('', $req->getURL());
|
|
|
|
|
|
|
|
$req = new SS_HTTPRequest('GET', '/assets/somefile.gif');
|
|
|
|
$this->assertEquals('assets/somefile.gif', $req->getURL());
|
|
|
|
|
|
|
|
$req = new SS_HTTPRequest('GET', '/home?test=1');
|
|
|
|
$this->assertEquals('home?test=1', $req->getURL(true));
|
|
|
|
$this->assertEquals('home', $req->getURL());
|
|
|
|
}
|
2011-12-22 23:04:44 +01:00
|
|
|
}
|