dev/joomla#26 - Fix path derivation when CMS is rooted in a subdir
authorTim Otten <totten@civicrm.org>
Tue, 24 Mar 2020 05:56:36 +0000 (22:56 -0700)
committerTim Otten <totten@civicrm.org>
Tue, 24 Mar 2020 05:56:36 +0000 (22:56 -0700)
commitd0cda11f761d4babb3fc515517dbbc0a80743338
treee26a0737dceb58ddfb63b4f61baa6b812cfb8809
parent72f729007273c50b80c9b216518f95e7864d2c04
dev/joomla#26 - Fix path derivation when CMS is rooted in a subdir

Overview
--------

CiviCRM is deployed inside a CMS. The CMS is usually deployed at the HTTP root (`http://example.org`),
but it is sometimes deployed in a subdirectory (`http://example.org/my-cms`).

Some asset URLs are computed using the variables `[civicrm.bower]`, `[civicrm.packages]`, and `[civicrm.vendor]`, which
are derived from the value of `[civicrm.root]`.  However, if the site is deployed in a subdirectory, and if using v5.23,
then the computation of `[civicrm.bower]` (etc) can misbehave.

Before
------

When the URL for `[civicrm.bower]` (or similar) is derived, it goes through multiple filters - first, from absolute to
relative, and then later from relative back to absolute.  In the process, the base is inadvertently changed.

After
-----

When the URL is derived, it is computed in absolute format - and simply kept that way.

Comments
--------

Regarding test coverage, there are two relevant unit-tests. This PR only updates one.

* `E2E\Core\PathUrlTest`: This is a more concrete smoke test which demonstrates functional problems with variables like
  `[civicrm.bower]`.  It should already catch problems like dev/joomla#26...  but only if you run the E2E suite on a system
  where the CMS was deployed to a subdirectory.  `civibuild` doesn't currently include such a build-type.
* `Civi\Core\PathsTest`: This is a more abstract, headless test to examine edge-cases in `Civi\Core\Paths`. It does not
  specifically check for `[civicrm.bower]` or similar variables (b/c the URL routing is ill-defined in a headless context).
  However, I've updated it to compare/contrast the working and non-working ways to derive variables.
Civi/Core/Paths.php
tests/phpunit/Civi/Core/PathsTest.php