From 563208698f1c8e7eb38740353ac0480d62a65b5d Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 22 Aug 2011 00:51:06 -0400 Subject: [PATCH] Fix MakeUrl() for when calling it at the root page. --- http/root_controller.php | 5 +++- testing/tests/http/root_controller_test.php | 31 +++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/http/root_controller.php b/http/root_controller.php index f83c9fd..e95037a 100644 --- a/http/root_controller.php +++ b/http/root_controller.php @@ -205,7 +205,10 @@ class RootController // common piece will be the path to the root controller. $request_uri = $this->request()->data['_SERVER']['REQUEST_URI']; $path_info = $this->request()->data['_SERVER']['PATH_INFO']; - $common_uri = strstr($request_uri, $path_info, TRUE); + if ($path_info === NULL) + $common_uri = substr($request_uri, 0, -1); + else + $common_uri = strstr($request_uri, $path_info, TRUE); // If just constructing an absolute path, return that now. if (!$url) diff --git a/testing/tests/http/root_controller_test.php b/testing/tests/http/root_controller_test.php index 3324545..9a2d74c 100644 --- a/testing/tests/http/root_controller_test.php +++ b/testing/tests/http/root_controller_test.php @@ -194,4 +194,35 @@ class RootControllerTest extends \PHPUnit_Framework_TestCase $this->assertEquals($mock->MakeURL('/', TRUE), 'https://www.bluestatic.org:8080/hoplite/webapp/'); $this->assertEquals($mock->MakeURL('/path/3', TRUE), 'https://www.bluestatic.org:8080/hoplite/webapp/path/3'); } + + public function testAbsolutifyRoot() + { + $globals = array( + '_SERVER' => array( + 'HTTP_HOST' => 'www.bluestatic.org', + 'REQUEST_URI' => '/hoplite/webapp/', + 'PATH_INFO' => NULL, + 'SERVER_PORT' => 80, + ), + ); + $mock = new \hoplite\http\RootController($globals); + + $this->assertEquals($mock->MakeURL('/'), '/hoplite/webapp/'); + $this->assertEquals($mock->MakeURL('/', TRUE), 'http://www.bluestatic.org/hoplite/webapp/'); + + $globals['_SERVER']['HTTPS'] = 'on'; + $globals['_SERVER']['SERVER_PORT'] = 443; + $mock = new \hoplite\http\RootController($globals); + $this->assertEquals($mock->MakeURL('/'), '/hoplite/webapp/'); + $this->assertEquals($mock->MakeURL('/', TRUE), 'https://www.bluestatic.org/hoplite/webapp/'); + + $this->assertEquals($mock->MakeURL('/path/2'), '/hoplite/webapp/path/2'); + $this->assertEquals($mock->MakeURL('/path/3', TRUE), 'https://www.bluestatic.org/hoplite/webapp/path/3'); + + $globals['_SERVER']['SERVER_PORT'] = 8080; + $mock = new \hoplite\http\RootController($globals); + $this->assertEquals($mock->MakeURL('/path/2'), '/hoplite/webapp/path/2'); + $this->assertEquals($mock->MakeURL('/', TRUE), 'https://www.bluestatic.org:8080/hoplite/webapp/'); + $this->assertEquals($mock->MakeURL('/path/3', TRUE), 'https://www.bluestatic.org:8080/hoplite/webapp/path/3'); + } } -- 2.22.5