Exemplo n.º 1
0
$t->is($request->getClientIp(false), '127.0.0.1', '->getClientIp() returns the remote address even if HTTP_CLIENT_IP exists when "proxy" argument is set to false');
unset($_SERVER['HTTP_CLIENT_IP']);
$_SERVER['HTTP_X_FORWARDED_FOR'] = '10.0.0.1, 10.0.0.2';
$t->is($request->getClientIp(false), '127.0.0.1', '->getClientIp() returns the remote address even if HTTP_X_FORWARDED_FOR exists when "proxy" argument is set to false');
unset($_SERVER['HTTP_X_FORWARDED_FOR']);
$t->is($request->getClientIp(false), '127.0.0.1', '->getClientIp() returns remote address by default');
$request->setOption('trust_proxy', false);
$_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';