From 3f1c369a5ff6ec73f708f43141564500321920b3 Mon Sep 17 00:00:00 2001 From: Jack Wilkinson Date: Tue, 28 Mar 2023 18:10:04 +0100 Subject: [PATCH 1/2] Added fix to ensure multiple assets are included in combination url --- modules/cms/classes/Controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/cms/classes/Controller.php b/modules/cms/classes/Controller.php index db534751d4..90490d51ed 100644 --- a/modules/cms/classes/Controller.php +++ b/modules/cms/classes/Controller.php @@ -1394,7 +1394,7 @@ protected function themeCombineAssets(array $url): string $asset = $source . DIRECTORY_SEPARATOR . $file; if (File::exists($asset)) { $assets[] = $asset; - break 2; + break; } } From 67ada2048ebd9fea6c3bd3e24fee6a8d8d27caf7 Mon Sep 17 00:00:00 2001 From: Jack Wilkinson Date: Tue, 28 Mar 2023 18:25:15 +0100 Subject: [PATCH 2/2] Added test case for combining multiple asset via themeUrl --- modules/cms/tests/classes/ControllerTest.php | 30 ++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/modules/cms/tests/classes/ControllerTest.php b/modules/cms/tests/classes/ControllerTest.php index e888f37462..5341576d99 100644 --- a/modules/cms/tests/classes/ControllerTest.php +++ b/modules/cms/tests/classes/ControllerTest.php @@ -639,4 +639,34 @@ public function testMacro() $response ); } + + public function testThemeCombineAssets(): void + { + $theme = Theme::load('test'); + $controller = new Controller($theme); + + // Generate a url + $url = $controller->themeUrl(['assets/css/style1.css', 'assets/css/style2.css']); + $this->assertIsString($url); + + // Grab the cache key from the url + $cacheKey = 'combiner.' . str_before(basename($url), '-'); + + // Load the cached config + $combinerConfig = \Cache::get($cacheKey); + $this->assertIsString($combinerConfig); + + // Decode the config + $combinerConfig = unserialize(base64_decode($combinerConfig)); + + // Assert the result is an array and includes files + $this->assertIsArray($combinerConfig); + $this->assertArrayHasKey('files', $combinerConfig); + $this->assertCount(2, $combinerConfig['files']); + + // Check our input file names against our output file names + $files = array_map('basename', $combinerConfig['files']); + $this->assertTrue(in_array('style1.css', $files)); + $this->assertTrue(in_array('style2.css', $files)); + } }