CRM_Utils_StringTest - Fix false-negative on systems with non-standard HTTP port
authorTim Otten <totten@civicrm.org>
Thu, 6 Sep 2018 04:56:01 +0000 (23:56 -0500)
committerTim Otten <totten@civicrm.org>
Tue, 11 Sep 2018 00:19:54 +0000 (17:19 -0700)
Before
------

On a local build with the base URL `http://dmaster.bknix:8001`, the test
`testSimplifyURL()` fails because the actual URL includes `:8001`.  The
actual URL is correct, but the test expectation is wrong.

After
-----

The test passes.

Comments
--------

* In the continuous-integration server, we've traditionally tested with
  the default/blank port (`http://core-1234-1234.test-ubu1204-5.civicrm.org`), so
  this didn't come up.
* The formatt returned by `simpleParseUrl()`  in `host+port` is clever about colons.
  It has unit-test coverage to show this.

tests/phpunit/CRM/Utils/StringTest.php

index ba04a54f31ce864686529cc0fe3fe61e1ebd07eb..0f273e2281aed6e761049b3eb526bb417c262b94 100644 (file)
@@ -251,8 +251,11 @@ class CRM_Utils_StringTest extends CiviUnitTestCase {
    */
   public function simplifyURLProvider() {
     $config = CRM_Core_Config::singleton();
-    $urlParts = parse_url($config->userFrameworkBaseURL);
-    $localDomain = $urlParts['host'];
+    $urlParts = CRM_Utils_String::simpleParseUrl($config->userFrameworkBaseURL);
+    $localDomain = $urlParts['host+port'];
+    if (empty($localDomain)) {
+      throw new \Exception("Failed to determine local base URL");
+    }
     $externalDomain = 'example.org';
 
     // Ensure that $externalDomain really is different from $localDomain
@@ -326,6 +329,13 @@ class CRM_Utils_StringTest extends CiviUnitTestCase {
           'path+query' => "/foo/bar/?id=1",
         ),
       ),
+      "default port example" => array(
+        "https://example.com/foo/bar/?id=1#fragment",
+        array(
+          'host+port' => "example.com",
+          'path+query' => "/foo/bar/?id=1",
+        ),
+      ),
       "empty" => array(
         "",
         array(