@@ -545,6 +545,48 @@ public function testSetBaseURL()
545545 $ this ->assertEquals ($ expectedUrl2 , Utils::getSelfURL ());
546546 }
547547
548+ /**
549+ * @covers OneLogin\Saml2\Utils::setBaseURL
550+ */
551+ public function testSetBaseURL2 ()
552+ {
553+ $ _SERVER ['HTTP_HOST ' ] = 'sp.example.com ' ;
554+ $ _SERVER ['HTTPS ' ] = 'https ' ;
555+ $ _SERVER ['REQUEST_URI ' ] = null ;
556+ $ _SERVER ['QUERY_STRING ' ] = null ;
557+ $ _SERVER ['SCRIPT_NAME ' ] = '/ ' ;
558+ unset($ _SERVER ['PATH_INFO ' ]);
559+
560+ Utils::setBaseURL ('https://sp.example.com ' );
561+ $ this ->assertEquals ("https://sp.example.com/ " , Utils::getSelfURLNoQuery ());
562+ $ this ->assertEquals ("https://sp.example.com/ " , Utils::getSelfRoutedURLNoQuery ());
563+ $ this ->assertEquals ("https://sp.example.com/ " , Utils::getSelfURL ());
564+ $ this ->assertEquals ('/ ' , Utils::getBaseURLPath ());
565+
566+ $ _SERVER ['REQUEST_URI ' ] = '/example1/path/route.php?x=test ' ;
567+ $ _SERVER ['QUERY_STRING ' ] = '?x=test ' ;
568+ $ _SERVER ['SCRIPT_NAME ' ] = '/example1/path/route.php ' ;
569+ $ this ->assertEquals ("https://sp.example.com/example1/path/route.php " , Utils::getSelfURLNoQuery ());
570+ $ this ->assertEquals ("https://sp.example.com/example1/path/route.php " , Utils::getSelfRoutedURLNoQuery ());
571+ $ this ->assertEquals ("https://sp.example.com/example1/path/route.php?x=test " , Utils::getSelfURL ());
572+ $ this ->assertEquals ('/ ' , Utils::getBaseURLPath ());
573+
574+ Utils::setBaseURLPath ('/example1/path/ ' );
575+ $ this ->assertEquals ("https://sp.example.com/example1/path/route.php " , Utils::getSelfURLNoQuery ());
576+ $ this ->assertEquals ("https://sp.example.com/example1/path/route.php " , Utils::getSelfRoutedURLNoQuery ());
577+ $ this ->assertEquals ("https://sp.example.com/example1/path/route.php?x=test " , Utils::getSelfURL ());
578+ $ this ->assertEquals ('/example1/path/ ' , Utils::getBaseURLPath ());
579+
580+ $ _SERVER ['REQUEST_URI ' ] = '/example1/path/route/?x=test ' ;
581+ $ _SERVER ['QUERY_STRING ' ] = '?x=test ' ;
582+ $ _SERVER ['SCRIPT_NAME ' ] = '/example1/path/route ' ;
583+ $ this ->assertEquals ("https://sp.example.com/example1/path/route " , Utils::getSelfURLNoQuery ());
584+ $ this ->assertEquals ("https://sp.example.com/example1/path/route " , Utils::getSelfRoutedURLNoQuery ());
585+ $ this ->assertEquals ("https://sp.example.com/example1/path/route/?x=test " , Utils::getSelfURL ());
586+ $ this ->assertEquals ('/example1/path/ ' , Utils::getBaseURLPath ());
587+
588+ }
589+
548590 /**
549591 * Tests the getSelfURLhost method of the Utils
550592 *
0 commit comments