From 23fb566cb9db20660f76366c62e2a56683ad0564 Mon Sep 17 00:00:00 2001 From: Artur Date: Thu, 24 Sep 2020 12:59:02 +0200 Subject: [PATCH 1/2] For compattibility with Url::asset() and Html::style/script() Why? Because when we install Laravel in to a sub folder (ex: /laravelapp) we need to refer all our assets urls to this subfolder. And laravel stuff yet do this in example `Html::script('')` return `http://domain.com/laravelapp` because it look what is set in `app.asset_url` Also all other `Theme::style/script/image/linkAsset()` will return url with subfolder included `http://domain.com/laravelapp` But not for `Theme::url()` that use `url() helper` of Laravel that generate url from root and not in accord of condif `app.asset_url` so we need to replace it to `asset()` that work with asset and not app url's --- src/Stylist/Html/ThemeHtmlBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Stylist/Html/ThemeHtmlBuilder.php b/src/Stylist/Html/ThemeHtmlBuilder.php index 0d8bb21..edf1d70 100644 --- a/src/Stylist/Html/ThemeHtmlBuilder.php +++ b/src/Stylist/Html/ThemeHtmlBuilder.php @@ -91,7 +91,7 @@ public function image($url, $alt = null, $attributes = array(), $secure = null) */ public function url($file = '') { - return url($this->assetUrl($file)); + return asset($this->assetUrl($file)); } /** From df646d21b84d7eaf60334c50d87ebfe01e589c99 Mon Sep 17 00:00:00 2001 From: Artur Date: Fri, 25 Sep 2020 09:55:33 +0200 Subject: [PATCH 2/2] Added tests for check Subfolder Assets Set root url to `/subfolder` and check if theme builder return correct path to assets also in it --- tests/Html/ThemeHtmlBuilderTest.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/Html/ThemeHtmlBuilderTest.php b/tests/Html/ThemeHtmlBuilderTest.php index 5432c32..3e4a0fe 100644 --- a/tests/Html/ThemeHtmlBuilderTest.php +++ b/tests/Html/ThemeHtmlBuilderTest.php @@ -50,4 +50,28 @@ public function testAssetUrlResponse() $this->assertEquals(url('themes/parent-theme/'), $this->builder->url()); $this->assertEquals(url('themes/parent-theme/favicon.ico'), $this->builder->url('favicon.ico')); } + + public function testSubfolderAssets() + { + // set subfolder + config(['app.url' => 'http://localhost/subfolder']); + config(['app.asset_url' => 'http://localhost/subfolder']); + $this->app['url']->forceRootUrl('/subfolder'); + + // check script in subfolder + $script = $this->builder->script('js/app.js'); + $this->assertContains('/subfolder/themes/parent-theme/js/app.js', (string) $script); + + // check style in subfolder + $style = $this->builder->style('css/app.css'); + $this->assertContains('/subfolder/themes/parent-theme/css/app.css', (string) $style); + + // check asset url in subfolder + $url = $this->builder->url('css/app.css'); + $this->assertContains('/subfolder/themes/parent-theme/css/app.css', (string) $url); + + // check link in subfolder + $link = $this->builder->linkAsset('css/app.css'); + $this->assertContains('/subfolder/themes/parent-theme/css/app.css', (string) $link); + } }