From 57530e5612bca013d692745617bf0a270fd847e7 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 5 Sep 2018 23:56:01 -0500 Subject: [PATCH] CRM_Utils_StringTest - Fix false-negative on systems with non-standard HTTP port 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 | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/CRM/Utils/StringTest.php b/tests/phpunit/CRM/Utils/StringTest.php index ba04a54f31..0f273e2281 100644 --- a/tests/phpunit/CRM/Utils/StringTest.php +++ b/tests/phpunit/CRM/Utils/StringTest.php @@ -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( -- 2.25.1