Skip to content

Commit 3678f2c

Browse files
committed
Add tests
1 parent de758ec commit 3678f2c

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tests/src/OneLogin/Saml2/UtilsTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,47 @@ public function testSetBaseURL()
547547
$this->assertEquals('/', OneLogin_Saml2_Utils::getBaseURLPath());
548548
}
549549

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

0 commit comments

Comments
 (0)