Ejemplo n.º 1
0
$_SERVER['HTTP_X_FORWARDED_FOR'] = '10.0.0.1, 10.0.0.2';
$t->is($request->getClientIp(), '127.0.0.1', '->getClientIp() returns the remote address even if HTTP_X_FORWARDED_FOR exists when "trust_proxy" is set ot false');
$request->setOption('trust_proxy', true);
unset($_SERVER['HTTP_X_FORWARDED_FOR']);
// ->getGetParameters() ->getGetParameter()
$t->diag('->getGetParameters() ->getGetParameter()');
$_GET['get_param'] = 'value';
$request = new myRequest($dispatcher);
$t->is($request->getGetParameters(), array('get_param' => 'value'), '->getGetParameters() returns GET parameters');
$t->is($request->getGetParameter('get_param'), 'value', '->getGetParameter() returns GET parameter by name');
unset($_GET['get_param']);
// ->getPostParameters() ->getPostParameter()
$t->diag('->getPostParameters() ->getPostParameter()');
$_POST['post_param'] = 'value';
$request = new myRequest($dispatcher);
$t->is($request->getPostParameters(), array('post_param' => 'value'), '->getPostParameters() returns POST parameters');
$t->is($request->getPostParameter('post_param'), 'value', '->getPostParameter() returns POST parameter by name');
unset($_POST['post_param']);
// ->getMethod()
$t->diag('->getMethod()');
$_SERVER['REQUEST_METHOD'] = 'none';
$request = new myRequest($dispatcher);
$t->is($request->getMethod(), 'GET', '->getMethod() returns GET by default');
$_SERVER['REQUEST_METHOD'] = 'GET';
$request = new myRequest($dispatcher);
$t->is($request->getMethod(), 'GET', '->getMethod() returns GET if the method is GET');
$_SERVER['REQUEST_METHOD'] = 'PUT';
$request = new myRequest($dispatcher);
$t->is($request->getMethod(), 'PUT', '->getMethod() returns PUT if the method is PUT');
$_SERVER['REQUEST_METHOD'] = 'PUT';
$_SERVER['CONTENT_TYPE'] = 'application/x-www-form-urlencoded';