From 132fa01cfd78dfff49535197aeb408bbfd5a7bc7 Mon Sep 17 00:00:00 2001 From: Lee Rowlands <lee.rowlands@previousnext.com.au> Date: Mon, 12 Jun 2023 11:17:25 +1000 Subject: [PATCH] Issue #3354090 by catch, longwave, smustgrave, mas5d2: Better default base path in assets stream wrapper --- .../Core/StreamWrapper/AssetsStream.php | 2 +- .../Asset/AssetOptimizationTest.php | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/core/lib/Drupal/Core/StreamWrapper/AssetsStream.php b/core/lib/Drupal/Core/StreamWrapper/AssetsStream.php index 9e29c0b8a934..85944dd110be 100644 --- a/core/lib/Drupal/Core/StreamWrapper/AssetsStream.php +++ b/core/lib/Drupal/Core/StreamWrapper/AssetsStream.php @@ -41,7 +41,7 @@ public function getDescription(): string { public static function basePath($site_path = NULL): string { return Settings::get( 'file_assets_path', - Settings::get('file_public_path', 'sites/default/files') + parent::basePath($site_path) ); } diff --git a/core/tests/Drupal/FunctionalTests/Asset/AssetOptimizationTest.php b/core/tests/Drupal/FunctionalTests/Asset/AssetOptimizationTest.php index 48337977968d..47bdd8ab081f 100644 --- a/core/tests/Drupal/FunctionalTests/Asset/AssetOptimizationTest.php +++ b/core/tests/Drupal/FunctionalTests/Asset/AssetOptimizationTest.php @@ -33,11 +33,36 @@ class AssetOptimizationTest extends BrowserTestBase { * Tests that asset aggregates are rendered and created on disk. */ public function testAssetAggregation(): void { + // Test aggregation with a custom file_assets_path. $this->fileAssetsPath = $this->publicFilesDirectory . '/test-assets'; $settings['settings']['file_assets_path'] = (object) [ 'value' => $this->fileAssetsPath, 'required' => TRUE, ]; + $this->doTestAggregation($settings); + + // Test aggregation with no configured file_assets_path or file_public_path, + // since tests run in a multisite, this tests multisite installs where + // settings.php is the default. + $this->fileAssetsPath = $this->publicFilesDirectory; + $settings['settings']['file_public_path'] = (object) [ + 'value' => NULL, + 'required' => TRUE, + ]; + $settings['settings']['file_assets_path'] = (object) [ + 'value' => NULL, + 'required' => TRUE, + ]; + $this->doTestAggregation($settings); + } + + /** + * Helper to test aggregate file URLs. + * + * @param array $settings + * A settings array to pass to ::writeSettings() + */ + protected function doTestAggregation(array $settings): void { $this->writeSettings($settings); $this->rebuildAll(); $this->config('system.performance')->set('css', [ -- GitLab