|
@@ -34,13 +34,13 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
|
|
$request->initialize(array('foo' => 'bar'));
|
|
|
$this->assertEquals('bar', $request->query->get('foo'), '->initialize() takes an array of query parameters as its first argument');
|
|
|
|
|
|
- $request->initialize(null, array('foo' => 'bar'));
|
|
|
+ $request->initialize(array(), array('foo' => 'bar'));
|
|
|
$this->assertEquals('bar', $request->request->get('foo'), '->initialize() takes an array of request parameters as its second argument');
|
|
|
|
|
|
- $request->initialize(null, null, array('foo' => 'bar'));
|
|
|
+ $request->initialize(array(), array(), array('foo' => 'bar'));
|
|
|
$this->assertEquals('bar', $request->attributes->get('foo'), '->initialize() takes an array of attributes as its thrid argument');
|
|
|
|
|
|
- $request->initialize(null, null, null, null, null, array('HTTP_FOO' => 'bar'));
|
|
|
+ $request->initialize(array(), array(), array(), array(), array(), array('HTTP_FOO' => 'bar'));
|
|
|
$this->assertEquals('bar', $request->headers->get('FOO'), '->initialize() takes an array of HTTP headers as its fourth argument');
|
|
|
}
|
|
|
|
|
@@ -134,7 +134,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
|
|
|
|
|
$request = new Request();
|
|
|
|
|
|
- $request->initialize(null, null, null, null, null,$server);
|
|
|
+ $request->initialize(array(), array(), array(), array(), array(), $server);
|
|
|
|
|
|
$this->assertEquals('http://hostname:8080/index.php/path/info?query=string', $request->getUri(), '->getUri() with non default port');
|
|
|
|
|
@@ -143,7 +143,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
|
|
$server['SERVER_NAME'] = 'hostname';
|
|
|
$server['SERVER_PORT'] = '80';
|
|
|
|
|
|
- $request->initialize(null, null, null, null, null, $server);
|
|
|
+ $request->initialize(array(), array(), array(), array(), array(), $server);
|
|
|
|
|
|
$this->assertEquals('http://hostname/index.php/path/info?query=string', $request->getUri(), '->getUri() with default port');
|
|
|
|
|
@@ -152,7 +152,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
|
|
$server['SERVER_NAME'] = 'hostname';
|
|
|
$server['SERVER_PORT'] = '80';
|
|
|
|
|
|
- $request->initialize(null, null, null, null, null, $server);
|
|
|
+ $request->initialize(array(), array(), array(), array(), array(), $server);
|
|
|
|
|
|
$this->assertEquals('http://hostname/index.php/path/info?query=string', $request->getUri(), '->getUri() with default port without HOST_HEADER');
|
|
|
|
|
@@ -174,7 +174,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
|
|
$server['PHP_SELF'] = '/index.php';
|
|
|
$server['SCRIPT_FILENAME'] = '/some/where/index.php';
|
|
|
|
|
|
- $request->initialize(null, null, null, null, null, $server);
|
|
|
+ $request->initialize(array(), array(), array(), array(), array(), $server);
|
|
|
$this->assertEquals('http://hostname:8080/path/info?query=string', $request->getUri(), '->getUri() with rewrite');
|
|
|
|
|
|
// Use std port number
|
|
@@ -183,7 +183,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
|
|
$server['SERVER_NAME'] = 'hostname';
|
|
|
$server['SERVER_PORT'] = '80';
|
|
|
|
|
|
- $request->initialize(null, null, null, null, null, $server);
|
|
|
+ $request->initialize(array(), array(), array(), array(), array(), $server);
|
|
|
|
|
|
$this->assertEquals('http://hostname/path/info?query=string', $request->getUri(), '->getUri() with rewrite and default port');
|
|
|
|
|
@@ -192,7 +192,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
|
|
$server['SERVER_NAME'] = 'hostname';
|
|
|
$server['SERVER_PORT'] = '80';
|
|
|
|
|
|
- $request->initialize(null, null, null, null, null, $server);
|
|
|
+ $request->initialize(array(), array(), array(), array(), array(), $server);
|
|
|
|
|
|
$this->assertEquals('http://hostname/path/info?query=string', $request->getUri(), '->getUri() with rewrite, default port without HOST_HEADER');
|
|
|
}
|
|
@@ -233,7 +233,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
|
|
|
|
|
$request = new Request();
|
|
|
|
|
|
- $request->initialize(null, null, null, null, null,$server);
|
|
|
+ $request->initialize(array(), array(), array(), array(), array(),$server);
|
|
|
|
|
|
$this->assertEquals('http://hostname:8080/index.php/some/path', $request->getUriForPath('/some/path'), '->getUriForPath() with non default port');
|
|
|
|
|
@@ -242,7 +242,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
|
|
$server['SERVER_NAME'] = 'hostname';
|
|
|
$server['SERVER_PORT'] = '80';
|
|
|
|
|
|
- $request->initialize(null, null, null, null, null, $server);
|
|
|
+ $request->initialize(array(), array(), array(), array(), array(), $server);
|
|
|
|
|
|
$this->assertEquals('http://hostname/index.php/some/path', $request->getUriForPath('/some/path'), '->getUriForPath() with default port');
|
|
|
|
|
@@ -251,7 +251,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
|
|
$server['SERVER_NAME'] = 'hostname';
|
|
|
$server['SERVER_PORT'] = '80';
|
|
|
|
|
|
- $request->initialize(null, null, null, null, null, $server);
|
|
|
+ $request->initialize(array(), array(), array(), array(), array(), $server);
|
|
|
|
|
|
$this->assertEquals('http://hostname/index.php/some/path', $request->getUriForPath('/some/path'), '->getUriForPath() with default port without HOST_HEADER');
|
|
|
|
|
@@ -273,7 +273,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
|
|
$server['PHP_SELF'] = '/index.php';
|
|
|
$server['SCRIPT_FILENAME'] = '/some/where/index.php';
|
|
|
|
|
|
- $request->initialize(null, null, null, null, null, $server);
|
|
|
+ $request->initialize(array(), array(), array(), array(), array(), $server);
|
|
|
$this->assertEquals('http://hostname:8080/some/path', $request->getUriForPath('/some/path'), '->getUri() with rewrite');
|
|
|
|
|
|
// Use std port number
|
|
@@ -282,7 +282,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
|
|
$server['SERVER_NAME'] = 'hostname';
|
|
|
$server['SERVER_PORT'] = '80';
|
|
|
|
|
|
- $request->initialize(null, null, null, null, null, $server);
|
|
|
+ $request->initialize(array(), array(), array(), array(), array(), $server);
|
|
|
|
|
|
$this->assertEquals('http://hostname/some/path', $request->getUriForPath('/some/path'), '->getUriForPath() with rewrite and default port');
|
|
|
|
|
@@ -291,7 +291,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
|
|
$server['SERVER_NAME'] = 'hostname';
|
|
|
$server['SERVER_PORT'] = '80';
|
|
|
|
|
|
- $request->initialize(null, null, null, null, null, $server);
|
|
|
+ $request->initialize(array(), array(), array(), array(), array(), $server);
|
|
|
|
|
|
$this->assertEquals('http://hostname/some/path', $request->getUriForPath('/some/path'), '->getUriForPath() with rewrite, default port without HOST_HEADER');
|
|
|
}
|
|
@@ -335,36 +335,36 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
|
|
$request->initialize(array('foo' => 'bar'));
|
|
|
$this->assertEquals('', $request->getHost(), '->getHost() return empty string if not initialized');
|
|
|
|
|
|
- $request->initialize(null, null, null, null, null, array('HTTP_HOST' => 'www.exemple.com'));
|
|
|
+ $request->initialize(array(), array(), array(), array(), array(), array('HTTP_HOST' => 'www.exemple.com'));
|
|
|
$this->assertEquals('www.exemple.com', $request->getHost(), '->getHost() from Host Header');
|
|
|
|
|
|
// Host header with port number.
|
|
|
- $request->initialize(null, null, null, null, null, array('HTTP_HOST' => 'www.exemple.com:8080'));
|
|
|
+ $request->initialize(array(), array(), array(), array(), array(), array('HTTP_HOST' => 'www.exemple.com:8080'));
|
|
|
$this->assertEquals('www.exemple.com', $request->getHost(), '->getHost() from Host Header with port number');
|
|
|
|
|
|
// Server values.
|
|
|
- $request->initialize(null, null, null, null, null, array('SERVER_NAME' => 'www.exemple.com'));
|
|
|
+ $request->initialize(array(), array(), array(), array(), array(), array('SERVER_NAME' => 'www.exemple.com'));
|
|
|
$this->assertEquals('www.exemple.com', $request->getHost(), '->getHost() from server name');
|
|
|
|
|
|
// X_FORWARDED_HOST.
|
|
|
- $request->initialize(null, null, null, null, null, array('HTTP_X_FORWARDED_HOST' => 'www.exemple.com'));
|
|
|
+ $request->initialize(array(), array(), array(), array(), array(), array('HTTP_X_FORWARDED_HOST' => 'www.exemple.com'));
|
|
|
$this->assertEquals('www.exemple.com', $request->getHost(), '->getHost() from X_FORWARDED_HOST');
|
|
|
|
|
|
// X_FORWARDED_HOST
|
|
|
- $request->initialize(null, null, null, null, null, array('HTTP_X_FORWARDED_HOST' => 'www.exemple.com, www.second.com'));
|
|
|
+ $request->initialize(array(), array(), array(), array(), array(), array('HTTP_X_FORWARDED_HOST' => 'www.exemple.com, www.second.com'));
|
|
|
$this->assertEquals('www.second.com', $request->getHost(), '->getHost() value from X_FORWARDED_HOST use last value');
|
|
|
|
|
|
// X_FORWARDED_HOST with port number
|
|
|
- $request->initialize(null, null, null, null, null, array('HTTP_X_FORWARDED_HOST' => 'www.exemple.com, www.second.com:8080'));
|
|
|
+ $request->initialize(array(), array(), array(), array(), array(), array('HTTP_X_FORWARDED_HOST' => 'www.exemple.com, www.second.com:8080'));
|
|
|
$this->assertEquals('www.second.com', $request->getHost(), '->getHost() value from X_FORWARDED_HOST with port number');
|
|
|
|
|
|
- $request->initialize(null, null, null, null, null, array('HTTP_HOST' => 'www.exemple.com', 'HTTP_X_FORWARDED_HOST' => 'www.forward.com'));
|
|
|
+ $request->initialize(array(), array(), array(), array(), array(), array('HTTP_HOST' => 'www.exemple.com', 'HTTP_X_FORWARDED_HOST' => 'www.forward.com'));
|
|
|
$this->assertEquals('www.forward.com', $request->getHost(), '->getHost() value from X_FORWARDED_HOST has priority over Host');
|
|
|
|
|
|
- $request->initialize(null, null, null, null, null, array('SERVER_NAME' => 'www.exemple.com', 'HTTP_X_FORWARDED_HOST' => 'www.forward.com'));
|
|
|
+ $request->initialize(array(), array(), array(), array(), array(), array('SERVER_NAME' => 'www.exemple.com', 'HTTP_X_FORWARDED_HOST' => 'www.forward.com'));
|
|
|
$this->assertEquals('www.forward.com', $request->getHost(), '->getHost() value from X_FORWARDED_HOST has priority over SERVER_NAME ');
|
|
|
|
|
|
- $request->initialize(null, null, null, null, null, array('SERVER_NAME' => 'www.exemple.com', 'HTTP_HOST' => 'www.host.com'));
|
|
|
+ $request->initialize(array(), array(), array(), array(), array(), array('SERVER_NAME' => 'www.exemple.com', 'HTTP_HOST' => 'www.host.com'));
|
|
|
$this->assertEquals('www.host.com', $request->getHost(), '->getHost() value from Host header has priority over SERVER_NAME ');
|
|
|
}
|
|
|
|
|
@@ -428,8 +428,21 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- protected function createTempFile()
|
|
|
+ public function testFromGlobals()
|
|
|
{
|
|
|
- return tempnam(sys_get_temp_dir(), 'FormTest');
|
|
|
+ $_GET['foo1'] = 'bar1';
|
|
|
+ $_POST['foo2'] = 'bar2';
|
|
|
+ $_COOKIE['foo3'] = 'bar3';
|
|
|
+ $_FILES['foo4'] = array('bar4');
|
|
|
+ $_SERVER['foo5'] = 'bar5';
|
|
|
+
|
|
|
+ $request = Request::fromGlobals();
|
|
|
+ $this->assertEquals('bar1', $request->query->get('foo1'), '::fromGlobals() uses values from $_GET');
|
|
|
+ $this->assertEquals('bar2', $request->request->get('foo2'), '::fromGlobals() uses values from $_POST');
|
|
|
+ $this->assertEquals('bar3', $request->cookies->get('foo3'), '::fromGlobals() uses values from $_COOKIE');
|
|
|
+ $this->assertEquals(array('bar4'), $request->files->get('foo4'), '::fromGlobals() uses values from $_FILES');
|
|
|
+ $this->assertEquals('bar5', $request->server->get('foo5'), '::fromGlobals() uses values from $_SERVER');
|
|
|
+
|
|
|
+ unset($_GET['foo1'], $_POST['foo2'], $_COOKIE['foo3'], $_FILES['foo4'], $_SERVER['foo5']);
|
|
|
}
|
|
|
}
|