Skip to content

Commit c70b7f7

Browse files
ENGCOM-1520: Fixed Issue #11354 Merged CSS file name generation #15144
2 parents 7df5e48 + 80f86bf commit c70b7f7

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

lib/internal/Magento/Framework/View/Asset/Merged.php

100644100755
Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Framework\View\Asset;
77

8+
use Magento\Framework\App\ObjectManager;
9+
810
/**
911
* \Iterator that aggregates one or more assets and provides a single public file with equivalent behavior
1012
*/
@@ -40,27 +42,39 @@ class Merged implements \Iterator
4042
*/
4143
protected $contentType;
4244

45+
/**
46+
* @var \Magento\Framework\App\View\Deployment\Version\StorageInterface
47+
*/
48+
private $versionStorage;
49+
4350
/**
4451
* @var bool
4552
*/
4653
protected $isInitialized = false;
4754

4855
/**
56+
* Merged constructor.
57+
*
4958
* @param \Psr\Log\LoggerInterface $logger
5059
* @param MergeStrategyInterface $mergeStrategy
5160
* @param \Magento\Framework\View\Asset\Repository $assetRepo
5261
* @param MergeableInterface[] $assets
62+
* @param \Magento\Framework\App\View\Deployment\Version\StorageInterface $versionStorage
5363
* @throws \InvalidArgumentException
5464
*/
5565
public function __construct(
5666
\Psr\Log\LoggerInterface $logger,
5767
MergeStrategyInterface $mergeStrategy,
5868
\Magento\Framework\View\Asset\Repository $assetRepo,
59-
array $assets
69+
array $assets,
70+
\Magento\Framework\App\View\Deployment\Version\StorageInterface $versionStorage = null
6071
) {
6172
$this->logger = $logger;
6273
$this->mergeStrategy = $mergeStrategy;
6374
$this->assetRepo = $assetRepo;
75+
$this->versionStorage = $versionStorage ?: ObjectManager::getInstance()->get(
76+
\Magento\Framework\App\View\Deployment\Version\StorageInterface::class
77+
);
6478

6579
if (!$assets) {
6680
throw new \InvalidArgumentException('At least one asset has to be passed for merging.');
@@ -116,6 +130,12 @@ private function createMergedAsset(array $assets)
116130
$paths[] = $asset->getPath();
117131
}
118132
$paths = array_unique($paths);
133+
134+
$version = $this->versionStorage->load();
135+
if ($version) {
136+
$paths[] = $version;
137+
}
138+
119139
$filePath = md5(implode('|', $paths)) . '.' . $this->contentType;
120140
return $this->assetRepo->createArbitrary($filePath, self::getRelativeDir());
121141
}

lib/internal/Magento/Framework/View/Test/Unit/Asset/MergedTest.php

100644100755
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\View\Asset\Repository as AssetRepository;
1313
use Magento\Framework\View\Asset\MergeableInterface;
1414
use Magento\Framework\View\Asset\MergeStrategyInterface;
15+
use Magento\Framework\App\View\Deployment\Version\StorageInterface;
1516

1617
/**
1718
* Class MergedTest
@@ -43,6 +44,11 @@ class MergedTest extends \PHPUnit\Framework\TestCase
4344
*/
4445
private $assetRepo;
4546

47+
/**
48+
* @var StorageInterface|\PHPUnit_Framework_MockObject_MockObject
49+
*/
50+
private $versionStorage;
51+
4652
protected function setUp()
4753
{
4854
$this->assetJsOne = $this->getMockForAbstractClass(MergeableInterface::class);
@@ -66,6 +72,7 @@ protected function setUp()
6672
$this->assetRepo = $this->getMockBuilder(AssetRepository::class)
6773
->disableOriginalConstructor()
6874
->getMock();
75+
$this->versionStorage = $this->createMock(StorageInterface::class);
6976
}
7077

7178
/**
@@ -74,7 +81,13 @@ protected function setUp()
7481
*/
7582
public function testConstructorNothingToMerge()
7683
{
77-
new \Magento\Framework\View\Asset\Merged($this->logger, $this->mergeStrategy, $this->assetRepo, []);
84+
new \Magento\Framework\View\Asset\Merged(
85+
$this->logger,
86+
$this->mergeStrategy,
87+
$this->assetRepo,
88+
[],
89+
$this->versionStorage
90+
);
7891
}
7992

8093
/**
@@ -90,6 +103,7 @@ public function testConstructorRequireMergeInterface()
90103
'mergeStrategy' => $this->mergeStrategy,
91104
'assetRepo' => $this->assetRepo,
92105
'assets' => [$this->assetJsOne, $assetUrl],
106+
'versionStorage' => $this->versionStorage,
93107
]);
94108
}
95109

@@ -109,6 +123,7 @@ public function testConstructorIncompatibleContentTypes()
109123
'mergeStrategy' => $this->mergeStrategy,
110124
'assetRepo' => $this->assetRepo,
111125
'assets' => [$this->assetJsOne, $assetCss],
126+
'versionStorage' => $this->versionStorage,
112127
]);
113128
}
114129

@@ -124,6 +139,7 @@ public function testIteratorInterfaceMerge()
124139
'mergeStrategy' => $this->mergeStrategy,
125140
'assetRepo' => $this->assetRepo,
126141
'assets' => $assets,
142+
'versionStorage' => $this->versionStorage,
127143
]);
128144

129145
$mergedAsset = $this->createMock(\Magento\Framework\View\Asset\File::class);
@@ -158,6 +174,7 @@ public function testIteratorInterfaceMergeFailure()
158174
'mergeStrategy' => $this->mergeStrategy,
159175
'assetRepo' => $this->assetRepo,
160176
'assets' => [$this->assetJsOne, $this->assetJsTwo, $assetBroken],
177+
'versionStorage' => $this->versionStorage,
161178
]);
162179

163180
$this->logger->expects($this->once())->method('critical')->with($this->identicalTo($mergeError));

0 commit comments

Comments
 (0)