diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 19064e5c09..124664b912 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -10,6 +10,7 @@ Yii Framework 2 Change Log - Bug #7670: Added `UrlNormalizer` for normalizing requests with and without trailing slashes (rob006, cronfy, klimov-paul) - Bug #9277: Fixed `yii\console\controllers\AssetController` looses custom options of 'target' bundles (petrabarus, klimov-paul) - Bug #9561: Fixed `canGetProperty()` and `canSetProperty()` returns `false` for `yii\db\BaseActiveRecord` attributes (klimov-paul) +- Bug #10567: Fixed `yii\console\controllers\AssetController` looses bundle override configuration, which makes it external one (klimov-paul) - Bug #11990: Fixed `yii\db\BaseActiveRecord::refresh()` may set incorrect `oldAttributes` values at some cases (only-victor) - Bug #12009: Do not render "for" field label attribute for active form RadioList and CheckboxList (shevchik87, samdark) - Bug #12068: Added missing 'LEVEL_PROFILE' for the syslog target (Mak-Di) diff --git a/framework/console/controllers/AssetController.php b/framework/console/controllers/AssetController.php index 783750c612..bd98555ecc 100644 --- a/framework/console/controllers/AssetController.php +++ b/framework/console/controllers/AssetController.php @@ -418,10 +418,9 @@ class AssetController extends Controller if (!$this->isBundleExternal($sourceBundle)) { $depends[] = $target; } - $targets[$bundle] = Yii::createObject([ - 'class' => strpos($bundle, '\\') !== false ? $bundle : 'yii\\web\\AssetBundle', - 'depends' => $depends, - ]); + $targetBundle = clone $sourceBundle; + $targetBundle->depends = $depends; + $targets[$bundle] = $targetBundle; } return $targets; diff --git a/tests/framework/console/controllers/AssetControllerTest.php b/tests/framework/console/controllers/AssetControllerTest.php index 8cc2b9888c..0517f717e9 100644 --- a/tests/framework/console/controllers/AssetControllerTest.php +++ b/tests/framework/console/controllers/AssetControllerTest.php @@ -671,6 +671,69 @@ EOL; ]); $this->assertEmpty($files); } + + /** + * @depends testActionCompress + * + * @see https://github.com/yiisoft/yii2/issues/10567 + */ + public function testActionCompressOverrideAsExternal() + { + // Given : + $cssFiles = [ + 'css/override_external.css' => 'body { + padding-top: 20px; + padding-bottom: 60px; + }', + ]; + $this->createAssetSourceFiles($cssFiles); + + $jsFiles = [ + 'js/override_external.js' => "function test() { + alert('Test message'); + }", + ]; + //$this->createAssetSourceFiles($cssFiles, $sourcePath); + //$this->createAssetSourceFiles($jsFiles, $sourcePath); + $assetBundleClassName = $this->declareAssetBundleClass([ + 'class' => 'AssetOverrideExternal', + 'css' => array_keys($cssFiles), + 'js' => array_keys($jsFiles), + ]); + + $bundles = [ + $assetBundleClassName + ]; + $bundleFile = $this->testFilePath . DIRECTORY_SEPARATOR . 'bundle_override_as_external.php'; + + // Keep source : + $configFile = $this->testFilePath . DIRECTORY_SEPARATOR . 'config_override_as_external.php'; + $assetBundleOverrideConfig = [ + 'sourcePath' => null, + 'basePath' => null, + 'baseUrl' => null, + 'css' => [ + '//some.cdn.com/js/override_external.css' + ], + 'js' => [ + '//some.cdn.com/js/override_external.js' + ], + ]; + $this->createCompressConfigFile($configFile, $bundles, [ + 'assetManager' => [ + 'bundles' => [ + $assetBundleClassName => $assetBundleOverrideConfig, + ], + ] + ]); + + $this->runAssetControllerAction('compress', [$configFile, $bundleFile]); + + $bundlesConfig = require $bundleFile; + + $this->assertEquals($assetBundleOverrideConfig['css'], $bundlesConfig[$assetBundleClassName]['css']); + $this->assertEquals($assetBundleOverrideConfig['js'], $bundlesConfig[$assetBundleClassName]['js']); + } } /**