silverstripe-framework/tests/HTTPRequestTest.php
Andrew Short 79773042be 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 03:06:31 +00:00

102 lines
2.1 KiB
PHP

<?php
class HTTPRequestTest extends SapphireTest {
static $fixture_file = null;
function testMatch() {
$request = new SS_HTTPRequest("GET", "admin/crm/add");
/* 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));
}
public function testHttpMethodOverrides() {
$request = new SS_HTTPRequest(
'GET',
'admin/crm'
);
$this->assertTrue(
$request->isGET(),
'GET with no method override'
);
$request = new SS_HTTPRequest(
'POST',
'admin/crm'
);
$this->assertTrue(
$request->isPOST(),
'POST with no method override'
);
$request = new SS_HTTPRequest(
'GET',
'admin/crm',
array('_method' => 'DELETE')
);
$this->assertTrue(
$request->isGET(),
'GET with invalid POST method override'
);
$request = new SS_HTTPRequest(
'POST',
'admin/crm',
array(),
array('_method' => 'DELETE')
);
$this->assertTrue(
$request->isDELETE(),
'POST with valid method override to DELETE'
);
$request = new SS_HTTPRequest(
'POST',
'admin/crm',
array(),
array('_method' => 'put')
);
$this->assertTrue(
$request->isPUT(),
'POST with valid method override to PUT'
);
$request = new SS_HTTPRequest(
'POST',
'admin/crm',
array(),
array('_method' => 'head')
);
$this->assertTrue(
$request->isHEAD(),
'POST with valid method override to HEAD '
);
$request = new SS_HTTPRequest(
'POST',
'admin/crm',
array(),
array('_method' => 'head')
);
$this->assertTrue(
$request->isHEAD(),
'POST with valid method override to HEAD'
);
$request = new SS_HTTPRequest(
'POST',
'admin/crm',
array('_method' => 'head')
);
$this->assertTrue(
$request->isPOST(),
'POST with invalid method override by GET parameters to HEAD'
);
}
}