Fixed yii\console\controllers\AssetController looses bundle override configuration, which makes it external one

This commit is contained in:
Klimov Paul
2016-08-31 17:25:52 +03:00
parent 3d49521cba
commit db15c50557
3 changed files with 67 additions and 4 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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']);
}
}
/**