Skip to content
Snippets Groups Projects
Commit 3e4baed9 authored by totten's avatar totten
Browse files

autoload_civicrm_asset.php - Don't leave trailing slashes to chance

The upstream interpretation of `$civicrm_paths['civicrm.packages']['url']`
currently requires a trailing slash...  but `autoload_civicrm_asset.php` may
not provide trailing slashes depending on the happenstance of
defaults+customizations.

This patch updates the generated values for `$civicrm_paths` and
`$civicrm_asset_map` so that they consistently use (or do not use) trailing
slashes.
parent 69f27a05
No related branches found
No related tags found
No related merge requests found
......@@ -149,18 +149,21 @@ abstract class AbstractAssetRule implements AssetRuleInterface {
}
public function createAssetMap(Publisher $publisher, IOInterface $io) {
$noSlash = function($str) {
return rtrim($str, '/' . DIRECTORY_SEPARATOR);
};
return sprintf("\$GLOBALS['civicrm_asset_map'][%s][%s] = %s;\n",
var_export($this->getPackage()->getName(), 1),
var_export('src', 1),
$this->exportPath($this->srcPath))
$this->exportPath($noSlash($this->srcPath)))
. sprintf("\$GLOBALS['civicrm_asset_map'][%s][%s] = %s;\n",
var_export($this->getPackage()->getName(), 1),
var_export('dest', 1),
$this->exportPath($this->getLocalPath($publisher)))
$this->exportPath($noSlash($this->getLocalPath($publisher))))
. sprintf("\$GLOBALS['civicrm_asset_map'][%s][%s] = %s;\n",
var_export($this->getPackage()->getName(), 1),
var_export('url', 1),
var_export($this->getWebPath($publisher), 1));
var_export($noSlash($this->getWebPath($publisher)), 1));
}
/**
......
......@@ -29,16 +29,20 @@ class BasicAssetRule extends AbstractAssetRule {
public function createAssetMap(Publisher $publisher, IOInterface $io) {
// The `$civicrm_path['civicrm.packages'] should point to the original folder b/c PHP files aren't mapped
$withSlash = function($str) {
return rtrim($str, '/' . DIRECTORY_SEPARATOR) . '/';
};
return parent::createAssetMap($publisher, $io)
. sprintf("\$civicrm_paths[%s][%s] = %s;\n",
var_export($this->pathVar, 1),
var_export('path', 1),
$this->exportPath($this->srcPath))
$this->exportPath($withSlash($this->srcPath)))
. sprintf("\$civicrm_paths[%s][%s] = %s;\n",
var_export($this->pathVar, 1),
var_export('url', 1),
// Common default: Relative to web root
var_export($this->getWebPath($publisher), 1));
var_export($withSlash($this->getWebPath($publisher)), 1));
}
}
......@@ -66,10 +66,10 @@ class CustomPathsTest extends \Civi\AssetPlugin\Integration\IntegrationTestCase
// The JS/CSS assets are sync'd to web dir, but the $civicrm_paths should still autoload PHP from the src folder.
$expectPaths = [];
$expectPaths['civicrm.root']['path'] = realpath(self::getTestDir()) . '/vendor/civicrm/civicrm-core';
$expectPaths['civicrm.root']['url'] = 'http://example.com/bar-civi-assets/core';
$expectPaths['civicrm.packages']['path'] = realpath(self::getTestDir()) . '/vendor/civicrm/civicrm-packages';
$expectPaths['civicrm.packages']['url'] = 'http://example.com/bar-civi-assets/packages';
$expectPaths['civicrm.root']['path'] = realpath(self::getTestDir()) . '/vendor/civicrm/civicrm-core/';
$expectPaths['civicrm.root']['url'] = 'http://example.com/bar-civi-assets/core/';
$expectPaths['civicrm.packages']['path'] = realpath(self::getTestDir()) . '/vendor/civicrm/civicrm-packages/';
$expectPaths['civicrm.packages']['url'] = 'http://example.com/bar-civi-assets/packages/';
// FIXME url checks
$count = 0;
......
......@@ -56,10 +56,10 @@ class DefaultPathsTest extends \Civi\AssetPlugin\Integration\IntegrationTestCase
// The JS/CSS assets are sync'd to web dir, but the $civicrm_paths should still autoload PHP from the src folder.
$expectPaths = [];
$expectPaths['civicrm.root']['path'] = realpath(self::getTestDir()) . '/vendor/civicrm/civicrm-core';
$expectPaths['civicrm.root']['url'] = '/civicrm-assets/core';
$expectPaths['civicrm.packages']['path'] = realpath(self::getTestDir()) . '/vendor/civicrm/civicrm-packages';
$expectPaths['civicrm.packages']['url'] = '/civicrm-assets/packages';
$expectPaths['civicrm.root']['path'] = realpath(self::getTestDir()) . '/vendor/civicrm/civicrm-core/';
$expectPaths['civicrm.root']['url'] = '/civicrm-assets/core/';
$expectPaths['civicrm.packages']['path'] = realpath(self::getTestDir()) . '/vendor/civicrm/civicrm-packages/';
$expectPaths['civicrm.packages']['url'] = '/civicrm-assets/packages/';
// FIXME url checks
$count = 0;
......
......@@ -75,10 +75,10 @@ class DrupalProjectPathsTest extends \Civi\AssetPlugin\Integration\IntegrationTe
// The JS/CSS assets are sync'd to web dir, but the $civicrm_paths should still autoload PHP from the src folder.
$expectPaths = [];
$expectPaths['civicrm.root']['path'] = realpath(self::getTestDir()) . '/vendor/civicrm/civicrm-core';
$expectPaths['civicrm.root']['url'] = '/libraries/civicrm/core';
$expectPaths['civicrm.packages']['path'] = realpath(self::getTestDir()) . '/vendor/civicrm/civicrm-packages';
$expectPaths['civicrm.packages']['url'] = '/libraries/civicrm/packages';
$expectPaths['civicrm.root']['path'] = realpath(self::getTestDir()) . '/vendor/civicrm/civicrm-core/';
$expectPaths['civicrm.root']['url'] = '/libraries/civicrm/core/';
$expectPaths['civicrm.packages']['path'] = realpath(self::getTestDir()) . '/vendor/civicrm/civicrm-packages/';
$expectPaths['civicrm.packages']['url'] = '/libraries/civicrm/packages/';
// FIXME url checks
$count = 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment