summaryrefslogtreecommitdiffstats
path: root/tests/lib/SimpleSAML/Utils/HTTPTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/SimpleSAML/Utils/HTTPTest.php')
-rw-r--r--tests/lib/SimpleSAML/Utils/HTTPTest.php47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/lib/SimpleSAML/Utils/HTTPTest.php b/tests/lib/SimpleSAML/Utils/HTTPTest.php
index f67b883..417c890 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.
*/