Fix MakeUrl() for when calling it at the root page.
authorRobert Sesek <rsesek@bluestatic.org>
Mon, 22 Aug 2011 04:51:06 +0000 (00:51 -0400)
committerRobert Sesek <rsesek@bluestatic.org>
Mon, 22 Aug 2011 04:51:06 +0000 (00:51 -0400)
http/root_controller.php
testing/tests/http/root_controller_test.php

index f83c9fdefd01ea6727331b6ad99544484202a091..e95037a9c4b7ff7adc9ce0cb1fb3ee5539f4a2ae 100644 (file)
@@ -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)
index 332454531fc325df0c803013f004bfdd23e56d67..9a2d74cdbaaf095be7d06b1d2542c817a4ea59f7 100644 (file)
@@ -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');
+  }
 }