diff --git a/tests/lib/SimpleSAML/Utils/HTTPTest.php b/tests/lib/SimpleSAML/Utils/HTTPTest.php
index f67b8832e2925c5cfee07ea4c9c0046c489af1c2..417c890f40ee598beae045e03624af8251387d3d 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.
      */