Revert "Make $civicrm_paths less sensitive to trailing slashes. Add tests."
authoreileen <emcnaughton@wikimedia.org>
Mon, 9 Mar 2020 05:01:36 +0000 (18:01 +1300)
committereileen <emcnaughton@wikimedia.org>
Mon, 9 Mar 2020 05:01:36 +0000 (18:01 +1300)
This is currently causing breakage on wordpress sites where clean urls are not enabled.

Compare the 2 urls below - the top one has an extra (breaking) slash added by this PR.

I propose a quick revert  & patch release followed by 'the right' fix at a slower pace
/wp-admin/admin.php/?page=CiviCRM&q=civicrm%2Fupgrade%2Fqueue%2Fajax%2FrunNext
/wp-admin/admin.php?page=CiviCRM&q=civicrm%2Fupgrade%2Fqueue%2Fajax%2FrunNext

This reverts commit 232fdd3dfac4ea09749d7f178818139514e48e38.

Civi/Core/Paths.php
tests/phpunit/Civi/Core/PathsTest.php [deleted file]

index 651fb29cdc7057669dc137c3a1ae8073b682bceb..e2e1ff62ea53b3d87cf1cc290ac0bfdade1109ca 100644 (file)
@@ -255,7 +255,7 @@ class Paths {
       return $value;
     }
 
-    $value = rtrim($this->getVariable($defaultContainer, 'url'), '/') . '/' . $value;
+    $value = $this->getVariable($defaultContainer, 'url') . $value;
 
     if ($preferFormat === 'relative') {
       $parsed = parse_url($value);
diff --git a/tests/phpunit/Civi/Core/PathsTest.php b/tests/phpunit/Civi/Core/PathsTest.php
deleted file mode 100644 (file)
index bd5cbbd..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-<?php
-
-namespace Civi\Core;
-
-/**
- * Class PathsTest
- * @package Civi\Core
- * @group headless
- */
-class PathsTest extends \CiviUnitTestCase {
-
-  public function getExamples() {
-    $exs = [];
-
-    // Ensure that various permutations of `$civicrm_paths`, `Civi::paths()->getPath()`
-    // and `Civi::paths()->getUrl()` work as expected.
-
-    // Trailing-slash configurations -- these all worked before current patch
-
-    $exs[] = ['te.st', 'path', '/var/www/files/', '[te.st]/foo/bar', '/var/www/files/foo/bar'];
-    $exs[] = ['te.st', 'path', '/var/www/files/', '[te.st]/foo/', '/var/www/files/foo/'];
-    $exs[] = ['te.st', 'path', '/var/www/files/', '[te.st]/foo', '/var/www/files/foo'];
-    $exs[] = ['te.st', 'path', '/var/www/files/', '[te.st]/.', '/var/www/files/'];
-
-    $exs[] = ['te.st', 'url', 'http://example.com/files/', '[te.st]/foo/bar', 'http://example.com/files/foo/bar'];
-    $exs[] = ['te.st', 'url', 'http://example.com/files/', '[te.st]/foo/', 'http://example.com/files/foo/'];
-    $exs[] = ['te.st', 'url', 'http://example.com/files/', '[te.st]/foo', 'http://example.com/files/foo'];
-    $exs[] = ['te.st', 'url', 'http://example.com/files/', '[te.st]/.', 'http://example.com/files/'];
-
-    $exs[] = ['te.st', 'url', 'http://example.com:8080/', '[te.st]/foo/bar', 'http://example.com:8080/foo/bar'];
-    $exs[] = ['te.st', 'url', 'http://example.com:8080/', '[te.st]/foo/', 'http://example.com:8080/foo/'];
-    $exs[] = ['te.st', 'url', 'http://example.com:8080/', '[te.st]/foo', 'http://example.com:8080/foo'];
-    $exs[] = ['te.st', 'url', 'http://example.com:8080/', '[te.st]/.', 'http://example.com:8080/'];
-
-    // Trimmed-slash configurations -- some of these worked before, and some misbehaved. Now fixed.
-
-    $exs[] = ['te.st', 'path', '/var/www/files', '[te.st]/foo/bar', '/var/www/files/foo/bar'];
-    $exs[] = ['te.st', 'path', '/var/www/files', '[te.st]/foo/', '/var/www/files/foo/'];
-    $exs[] = ['te.st', 'path', '/var/www/files', '[te.st]/foo', '/var/www/files/foo'];
-    $exs[] = ['te.st', 'path', '/var/www/files', '[te.st]/.', '/var/www/files/'];
-
-    $exs[] = ['te.st', 'url', 'http://example.com/files', '[te.st]/foo/bar', 'http://example.com/files/foo/bar'];
-    $exs[] = ['te.st', 'url', 'http://example.com/files', '[te.st]/foo/', 'http://example.com/files/foo/'];
-    $exs[] = ['te.st', 'url', 'http://example.com/files', '[te.st]/foo', 'http://example.com/files/foo'];
-    $exs[] = ['te.st', 'url', 'http://example.com/files', '[te.st]/.', 'http://example.com/files/'];
-
-    $exs[] = ['te.st', 'url', 'http://example.com:8080', '[te.st]/foo/bar', 'http://example.com:8080/foo/bar'];
-    $exs[] = ['te.st', 'url', 'http://example.com:8080', '[te.st]/foo/', 'http://example.com:8080/foo/'];
-    $exs[] = ['te.st', 'url', 'http://example.com:8080', '[te.st]/foo', 'http://example.com:8080/foo'];
-    $exs[] = ['te.st', 'url', 'http://example.com:8080', '[te.st]/.', 'http://example.com:8080/'];
-
-    return $exs;
-  }
-
-  /**
-   * @param $varName
-   * @param $varType
-   * @param $varValue
-   * @param $inputExpr
-   * @param $expectValue
-   * @dataProvider getExamples
-   */
-  public function testExamples($varName, $varType, $varValue, $inputExpr, $expectValue) {
-    global $civicrm_paths;
-    $civicrm_paths[$varName][$varType] = $varValue;
-    $func = ($varType === 'url') ? 'getUrl' : 'getPath';
-
-    $paths = new Paths();
-    $paths->register($varName, function() {
-      return ['path' => 'FIXME-PATH', 'url' => 'FIXME-URL'];
-    });
-
-    $actualValue = call_user_func([$paths, $func], $inputExpr);
-    $this->assertEquals($expectValue, $actualValue);
-
-    unset($civicrm_paths[$varName][$varType]);
-  }
-
-  public function testGetUrl_ImplicitBase() {
-    $p = \Civi::paths();
-    $cmsRoot = rtrim($p->getVariable('cms.root', 'url'), '/');
-
-    $this->assertEquals("$cmsRoot/foo/bar", $p->getUrl('foo/bar'));
-    $this->assertEquals("$cmsRoot/foo/", $p->getUrl('foo/'));
-    $this->assertEquals("$cmsRoot/foo", $p->getUrl('foo'));
-  }
-
-}