Skip to content

Commit

Permalink
ENGCOM-1520: Fixed Issue #11354 Merged CSS file name generation #15144
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirZaets authored May 14, 2018
2 parents 7df5e48 + 80f86bf commit c70b7f7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
22 changes: 21 additions & 1 deletion lib/internal/Magento/Framework/View/Asset/Merged.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
namespace Magento\Framework\View\Asset;

use Magento\Framework\App\ObjectManager;

/**
* \Iterator that aggregates one or more assets and provides a single public file with equivalent behavior
*/
Expand Down Expand Up @@ -40,27 +42,39 @@ class Merged implements \Iterator
*/
protected $contentType;

/**
* @var \Magento\Framework\App\View\Deployment\Version\StorageInterface
*/
private $versionStorage;

/**
* @var bool
*/
protected $isInitialized = false;

/**
* Merged constructor.
*
* @param \Psr\Log\LoggerInterface $logger
* @param MergeStrategyInterface $mergeStrategy
* @param \Magento\Framework\View\Asset\Repository $assetRepo
* @param MergeableInterface[] $assets
* @param \Magento\Framework\App\View\Deployment\Version\StorageInterface $versionStorage
* @throws \InvalidArgumentException
*/
public function __construct(
\Psr\Log\LoggerInterface $logger,
MergeStrategyInterface $mergeStrategy,
\Magento\Framework\View\Asset\Repository $assetRepo,
array $assets
array $assets,
\Magento\Framework\App\View\Deployment\Version\StorageInterface $versionStorage = null
) {
$this->logger = $logger;
$this->mergeStrategy = $mergeStrategy;
$this->assetRepo = $assetRepo;
$this->versionStorage = $versionStorage ?: ObjectManager::getInstance()->get(
\Magento\Framework\App\View\Deployment\Version\StorageInterface::class
);

if (!$assets) {
throw new \InvalidArgumentException('At least one asset has to be passed for merging.');
Expand Down Expand Up @@ -116,6 +130,12 @@ private function createMergedAsset(array $assets)
$paths[] = $asset->getPath();
}
$paths = array_unique($paths);

$version = $this->versionStorage->load();
if ($version) {
$paths[] = $version;
}

$filePath = md5(implode('|', $paths)) . '.' . $this->contentType;
return $this->assetRepo->createArbitrary($filePath, self::getRelativeDir());
}
Expand Down
19 changes: 18 additions & 1 deletion lib/internal/Magento/Framework/View/Test/Unit/Asset/MergedTest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Magento\Framework\View\Asset\Repository as AssetRepository;
use Magento\Framework\View\Asset\MergeableInterface;
use Magento\Framework\View\Asset\MergeStrategyInterface;
use Magento\Framework\App\View\Deployment\Version\StorageInterface;

/**
* Class MergedTest
Expand Down Expand Up @@ -43,6 +44,11 @@ class MergedTest extends \PHPUnit\Framework\TestCase
*/
private $assetRepo;

/**
* @var StorageInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $versionStorage;

protected function setUp()
{
$this->assetJsOne = $this->getMockForAbstractClass(MergeableInterface::class);
Expand All @@ -66,6 +72,7 @@ protected function setUp()
$this->assetRepo = $this->getMockBuilder(AssetRepository::class)
->disableOriginalConstructor()
->getMock();
$this->versionStorage = $this->createMock(StorageInterface::class);
}

/**
Expand All @@ -74,7 +81,13 @@ protected function setUp()
*/
public function testConstructorNothingToMerge()
{
new \Magento\Framework\View\Asset\Merged($this->logger, $this->mergeStrategy, $this->assetRepo, []);
new \Magento\Framework\View\Asset\Merged(
$this->logger,
$this->mergeStrategy,
$this->assetRepo,
[],
$this->versionStorage
);
}

/**
Expand All @@ -90,6 +103,7 @@ public function testConstructorRequireMergeInterface()
'mergeStrategy' => $this->mergeStrategy,
'assetRepo' => $this->assetRepo,
'assets' => [$this->assetJsOne, $assetUrl],
'versionStorage' => $this->versionStorage,
]);
}

Expand All @@ -109,6 +123,7 @@ public function testConstructorIncompatibleContentTypes()
'mergeStrategy' => $this->mergeStrategy,
'assetRepo' => $this->assetRepo,
'assets' => [$this->assetJsOne, $assetCss],
'versionStorage' => $this->versionStorage,
]);
}

Expand All @@ -124,6 +139,7 @@ public function testIteratorInterfaceMerge()
'mergeStrategy' => $this->mergeStrategy,
'assetRepo' => $this->assetRepo,
'assets' => $assets,
'versionStorage' => $this->versionStorage,
]);

$mergedAsset = $this->createMock(\Magento\Framework\View\Asset\File::class);
Expand Down Expand Up @@ -158,6 +174,7 @@ public function testIteratorInterfaceMergeFailure()
'mergeStrategy' => $this->mergeStrategy,
'assetRepo' => $this->assetRepo,
'assets' => [$this->assetJsOne, $this->assetJsTwo, $assetBroken],
'versionStorage' => $this->versionStorage,
]);

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

0 comments on commit c70b7f7

Please sign in to comment.