Skip to content
Snippets Groups Projects
Commit 59e9cb38 authored by Jaime Perez Crespo's avatar Jaime Perez Crespo
Browse files

Add some tests for the new SimpleSAML\Utils\HTTP::guessBasePath().

parent 08e92702
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,53 @@ use SimpleSAML\Utils\HTTP;
class HTTPTest extends \PHPUnit_Framework_TestCase
{
/**
* Test SimpleSAML\Utils\HTTP::guessBasePath().
*/
public function testGuessBasePath()
{
global $_SERVER;
$original = $_SERVER;
$_SERVER['REQUEST_URI'] = '/simplesaml/module.php';
$_SERVER['SCRIPT_FILENAME'] = '/some/path/simplesamlphp/www/module.php';
$this->assertEquals('/simplesaml/', HTTP::guessBasePath());
$_SERVER['REQUEST_URI'] = '/simplesaml/module.php/some/path/to/other/script.php';
$_SERVER['SCRIPT_FILENAME'] = '/some/path/simplesamlphp/www/module.php';
$this->assertEquals('/simplesaml/', HTTP::guessBasePath());
$_SERVER['REQUEST_URI'] = '/module.php';
$_SERVER['SCRIPT_FILENAME'] = '/some/path/simplesamlphp/www/module.php';
$this->assertEquals('/', HTTP::guessBasePath());
$_SERVER['REQUEST_URI'] = '/module.php/some/path/to/other/script.php';
$_SERVER['SCRIPT_FILENAME'] = '/some/path/simplesamlphp/www/module.php';
$this->assertEquals('/', HTTP::guessBasePath());
$_SERVER['REQUEST_URI'] = '/some/path/module.php';
$_SERVER['SCRIPT_FILENAME'] = '/some/path/simplesamlphp/www/module.php';
$this->assertEquals('/some/path/', HTTP::guessBasePath());
$_SERVER['REQUEST_URI'] = '/some/path/module.php/some/path/to/other/script.php';
$_SERVER['SCRIPT_FILENAME'] = '/some/path/simplesamlphp/www/module.php';
$this->assertEquals('/some/path/', HTTP::guessBasePath());
$_SERVER['REQUEST_URI'] = '/some/dir/in/www/script.php';
$_SERVER['SCRIPT_FILENAME'] = '/some/path/simplesamlphp/www/some/dir/in/www/script.php';
$this->assertEquals('/', HTTP::guessBasePath());
$_SERVER['REQUEST_URI'] = '/simplesaml/some/dir/in/www/script.php';
$_SERVER['SCRIPT_FILENAME'] = '/some/path/simplesamlphp/www/some/dir/in/www/script.php';
$this->assertEquals('/simplesaml/', HTTP::guessBasePath());
$_SERVER = $original;
}
/**
* Test SimpleSAML\Utils\HTTP::getSelfHost() with and without custom port.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment