Ejemplo n.º 1
0
 /**
  * Include RequireJs configuration as an asset on the page
  *
  * @return $this
  */
 protected function _prepareLayout()
 {
     $requireJsConfig = $this->fileManager->createRequireJsConfigAsset();
     $requireJsMixinsConfig = $this->fileManager->createRequireJsMixinsAsset();
     $assetCollection = $this->pageConfig->getAssetCollection();
     $after = RequireJsConfig::REQUIRE_JS_FILE_NAME;
     if ($this->minification->isEnabled('js')) {
         $minResolver = $this->fileManager->createMinResolverAsset();
         $assetCollection->insert($minResolver->getFilePath(), $minResolver, $after);
         $after = $minResolver->getFilePath();
     }
     if ($this->bundleConfig->isBundlingJsFiles()) {
         $bundleAssets = $this->fileManager->createBundleJsPool();
         $staticAsset = $this->fileManager->createStaticJsAsset();
         /** @var \Magento\Framework\View\Asset\File $bundleAsset */
         if (!empty($bundleAssets) && $staticAsset !== false) {
             $bundleAssets = array_reverse($bundleAssets);
             foreach ($bundleAssets as $bundleAsset) {
                 $assetCollection->insert($bundleAsset->getFilePath(), $bundleAsset, $after);
             }
             $assetCollection->insert($staticAsset->getFilePath(), $staticAsset, reset($bundleAssets)->getFilePath());
             $after = $staticAsset->getFilePath();
         }
     }
     $assetCollection->insert($requireJsConfig->getFilePath(), $requireJsConfig, $after);
     $assetCollection->insert($requireJsMixinsConfig->getFilePath(), $requireJsMixinsConfig, $after);
     return parent::_prepareLayout();
 }
 public function testCreateMinResolverAsset()
 {
     $this->configMock->expects($this->any())->method('getMinResolverRelativePath')->willReturn('relative path');
     $this->assetRepoMock->expects($this->once())->method('createArbitrary')->with('relative path');
     $this->fileSystem->expects($this->once())->method('getDirectoryWrite')->with(DirectoryList::STATIC_VIEW)->will($this->returnValue($this->dir));
     $this->object->createMinResolverAsset();
 }