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