예제 #1
0
$_GET['sf_method'] = 'PUT';
$request = new myRequest($dispatcher);
$t->is($request->getMethod(), 'PUT', '->getMethod() returns the "sf_method" parameter value if it exists and if the method is POST');
$_SERVER['REQUEST_METHOD'] = 'POST';
unset($_GET['sf_method']);
$request = new myRequest($dispatcher);
$t->is($request->getMethod(), 'POST', '->getMethod() returns the "sf_method" parameter value if it exists and if the method is POST');
// ->isMethod()
$t->diag('->isMethod()');
$_SERVER['REQUEST_METHOD'] = 'POST';
$request = new myRequest($dispatcher);
$t->ok($request->isMethod('POST'), '->isMethod() returns true if the method is POST');
// ->isXmlHttpRequest()
$t->diag('->isXmlHttpRequest()');
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
$t->ok($request->isXmlHttpRequest(), '->isXmlHttpRequest() returns true if the method has HTTP_X_REQUESTED_WITH to XMLHttpRequest');
// ->getCookie()
$t->diag('->getCookie()');
$_COOKIE['test'] = 'value';
$request = new myRequest($dispatcher);
$t->is($request->getCookie('test'), 'value', '->getCookie() returns value of cookie');
// ->getScriptName()
$t->diag('->getScriptName()');
$request = new myRequest($dispatcher);
$_SERVER['SCRIPT_NAME'] = '/frontend_test.php';
$_SERVER['ORIG_SCRIPT_NAME'] = '/frontend_test2.php';
$t->is($request->getScriptName(), '/frontend_test.php', '->getScriptName() returns the script name');
$request = new myRequest($dispatcher);
unset($_SERVER['SCRIPT_NAME']);
$_SERVER['ORIG_SCRIPT_NAME'] = '/frontend_test2.php';
$t->is($request->getScriptName(), '/frontend_test2.php', '->getScriptName() returns the script name if SCRIPT_NAME not set it use ORIG_SCRIPT_NAME');