From 59e9cb381bf5bc142e465703187b7f6de31b4a91 Mon Sep 17 00:00:00 2001 From: Jaime Perez Crespo <jaime.perez@uninett.no> Date: Tue, 19 Apr 2016 20:09:13 +0200 Subject: [PATCH] Add some tests for the new SimpleSAML\Utils\HTTP::guessBasePath(). --- tests/lib/SimpleSAML/Utils/HTTPTest.php | 47 +++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/lib/SimpleSAML/Utils/HTTPTest.php b/tests/lib/SimpleSAML/Utils/HTTPTest.php index f67b8832e..417c890f4 100644 --- a/tests/lib/SimpleSAML/Utils/HTTPTest.php +++ b/tests/lib/SimpleSAML/Utils/HTTPTest.php @@ -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. */ -- GitLab