示例#1
0
 /**
  * @param array $assets
  * @param string $contentType
  * @param string $appMode
  * @param string $mergeStrategy
  * @dataProvider getMergedAssetsDataProvider
  */
 public function testGetMergedAssets(array $assets, $contentType, $appMode, $mergeStrategy)
 {
     $mergedAsset = $this->getMock('Magento\\Framework\\View\\Asset\\AssetInterface');
     $this->_config->expects($this->once())->method('isMergeCssFiles')->will($this->returnValue(true));
     $this->_config->expects($this->once())->method('isMergeJsFiles')->will($this->returnValue(true));
     $mergeStrategyMock = $this->getMock($mergeStrategy, [], [], '', false);
     $this->_objectManager->expects($this->once())->method('create')->with('Magento\\Framework\\View\\Asset\\Merged', ['assets' => $assets, 'mergeStrategy' => $mergeStrategyMock])->will($this->returnValue($mergedAsset));
     $this->_objectManager->expects($this->once())->method('get')->with($mergeStrategy)->will($this->returnValue($mergeStrategyMock));
     $this->_state->expects($this->once())->method('getMode')->will($this->returnValue($appMode));
     $this->assertSame($mergedAsset, $this->_object->getMergedAssets($assets, $contentType));
 }
示例#2
0
 /**
  * @param array $groupAssets
  * @param \Magento\Framework\View\Asset\PropertyGroup $group
  * @return array
  */
 protected function processMerge($groupAssets, $group)
 {
     if ($group->getProperty(GroupedCollection::PROPERTY_CAN_MERGE) && count($groupAssets) > 1) {
         $groupAssets = $this->assetMergeService->getMergedAssets($groupAssets, $group->getProperty(GroupedCollection::PROPERTY_CONTENT_TYPE));
     }
     return $groupAssets;
 }
示例#3
0
 /**
  * {@inheritdoc}
  */
 public function getMergedAssets(array $assets, $contentType)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getMergedAssets');
     if (!$pluginInfo) {
         return parent::getMergedAssets($assets, $contentType);
     } else {
         return $this->___callPlugins('getMergedAssets', func_get_args(), $pluginInfo);
     }
 }
示例#4
0
文件: Head.php 项目: aiesh/magento2
 /**
  * Render HTML for the added head items
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  *
  * @return string
  */
 public function getCssJsHtml()
 {
     foreach ($this->getLayout()->getChildBlocks($this->getNameInLayout()) as $block) {
         /** @var $block \Magento\Framework\View\Element\AbstractBlock */
         if ($block instanceof \Magento\Theme\Block\Html\Head\AssetBlockInterface) {
             /** @var \Magento\Framework\View\Asset\AssetInterface $asset */
             $asset = $block->getAsset();
             $this->_pageAssets->add($block->getNameInLayout(), $asset, (array) $block->getProperties());
         }
     }
     $result = '';
     /** @var $group \Magento\Framework\View\Asset\PropertyGroup */
     foreach ($this->_pageAssets->getGroups() as $group) {
         $contentType = $group->getProperty(\Magento\Framework\View\Asset\GroupedCollection::PROPERTY_CONTENT_TYPE);
         $canMerge = $group->getProperty(\Magento\Framework\View\Asset\GroupedCollection::PROPERTY_CAN_MERGE);
         $attributes = $group->getProperty('attributes');
         $ieCondition = $group->getProperty('ie_condition');
         $flagName = $group->getProperty('flag_name');
         if ($flagName && !$this->getData($flagName)) {
             continue;
         }
         $groupAssets = $group->getAll();
         $groupAssets = $this->_assetMinifyService->getAssets($groupAssets);
         if ($canMerge && count($groupAssets) > 1) {
             $groupAssets = $this->_assetMergeService->getMergedAssets($groupAssets, $contentType);
         }
         if (!empty($attributes)) {
             if (is_array($attributes)) {
                 $attributesString = '';
                 foreach ($attributes as $name => $value) {
                     $attributesString .= ' ' . $name . '="' . $this->escapeHtml($value) . '"';
                 }
                 $attributes = $attributesString;
             } else {
                 $attributes = ' ' . $attributes;
             }
         }
         if ($contentType == 'js') {
             $groupTemplate = '<script' . $attributes . ' type="text/javascript" src="%s"></script>' . "\n";
         } else {
             if ($contentType == 'css') {
                 $attributes = ' rel="stylesheet" type="text/css"' . ($attributes ?: ' media="all"');
             }
             $groupTemplate = '<link' . $attributes . ' href="%s" />' . "\n";
         }
         $groupHtml = $this->_renderHtml($groupTemplate, $groupAssets);
         if (!empty($ieCondition)) {
             $groupHtml = '<!--[if ' . $ieCondition . ']>' . "\n" . $groupHtml . '<![endif]-->' . "\n";
         }
         $result .= $groupHtml;
     }
     return $result;
 }