summaryrefslogtreecommitdiffstats
path: root/tests/lib/SimpleSAML/Utils/HTTPTest.php
diff options
context:
space:
mode:
authorJaime Perez Crespo <jaime.perez@uninett.no>2016-04-19 20:09:13 +0200
committerJaime Perez Crespo <jaime.perez@uninett.no>2016-04-19 20:09:13 +0200
commit59e9cb381bf5bc142e465703187b7f6de31b4a91 (patch)
tree7cfe9dcf252617898d14d7ca9794ad19913299a6 /tests/lib/SimpleSAML/Utils/HTTPTest.php
parent08e9270232692aac75d11855b1a34716c45cb01c (diff)
downloadsimplesamlphp-59e9cb381bf5bc142e465703187b7f6de31b4a91.zip
simplesamlphp-59e9cb381bf5bc142e465703187b7f6de31b4a91.tar.gz
simplesamlphp-59e9cb381bf5bc142e465703187b7f6de31b4a91.tar.bz2
Add some tests for the new SimpleSAML\Utils\HTTP::guessBasePath().
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.
*/