コード例 #1
0
 /**
  * Update required parameters with default values if custom not specified
  *
  * @param array &$params
  * @throws \UnexpectedValueException
  * @return $this
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function updateDesignParams(array &$params)
 {
     $defaults = $this->design->getDesignParams();
     // Set area
     if (empty($params['area'])) {
         $params['area'] = $defaults['area'];
     }
     // Set themeModel
     $theme = null;
     $area = $params['area'];
     if (!empty($params['themeId'])) {
         $theme = $params['themeId'];
     } elseif (isset($params['theme'])) {
         $theme = $params['theme'];
     } elseif (empty($params['themeModel']) && $area !== $defaults['area']) {
         $theme = $this->design->getConfigurationDesignTheme($area);
     }
     if ($theme) {
         $params['themeModel'] = $this->themeProvider->getThemeModel($theme, $area);
         if (!$params['themeModel']) {
             throw new \UnexpectedValueException("Could not find theme '{$theme}' for area '{$area}'");
         }
     } elseif (empty($params['themeModel'])) {
         $params['themeModel'] = $defaults['themeModel'];
     }
     // Set module
     if (!array_key_exists('module', $params)) {
         $params['module'] = false;
     }
     // Set locale
     if (empty($params['locale'])) {
         $params['locale'] = $defaults['locale'];
     }
     return $this;
 }
コード例 #2
0
 private function mockDesign()
 {
     $params = array('area' => 'area', 'themeModel' => $this->theme, 'locale' => 'locale');
     $this->design->expects($this->atLeastOnce())->method('getDesignParams')->will($this->returnValue($params));
     $this->design->expects($this->any())->method('getConfigurationDesignTheme')->with('area')->will($this->returnValue($this->theme));
     $this->design->expects($this->any())->method('getThemePath')->with($this->theme)->will($this->returnValue('theme'));
     $this->themeProvider->expects($this->any())->method('getThemeModel')->will($this->returnValue($this->theme));
 }
コード例 #3
0
 /**
  * Get theme model based on the information from asset
  *
  * @param LocalInterface $asset
  * @return \Magento\Framework\View\Design\ThemeInterface
  */
 protected function getTheme(LocalInterface $asset)
 {
     $context = $asset->getContext();
     if ($context instanceof FallbackContext) {
         return $this->themeProvider->getThemeModel($context->getThemePath(), $context->getAreaCode());
     }
     return $this->design->getDesignTheme();
 }
コード例 #4
0
 /**
  * @param string $originalContent
  * @param string $foundPath
  * @param string $resolvedPath
  * @param array $foundFiles
  * @param string $expectedContent
  *
  * @dataProvider processDataProvider
  */
 public function testProcess($originalContent, $foundPath, $resolvedPath, $foundFiles, $expectedContent)
 {
     $chain = new \Magento\Framework\View\Asset\PreProcessor\Chain($this->asset, $originalContent, 'css');
     $relatedAsset = $this->getMock('\\Magento\\Framework\\View\\Asset\\File', [], [], '', false);
     $relatedAsset->expects($this->once())->method('getFilePath')->will($this->returnValue($resolvedPath));
     $context = $this->getMock('\\Magento\\Framework\\View\\Asset\\File\\FallbackContext', [], [], '', false);
     $this->assetRepo->expects($this->once())->method('createRelated')->with($foundPath, $this->asset)->will($this->returnValue($relatedAsset));
     $relatedAsset->expects($this->once())->method('getContext')->will($this->returnValue($context));
     $theme = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Design\\ThemeInterface');
     $this->themeProvider->expects($this->once())->method('getThemeModel')->will($this->returnValue($theme));
     $files = [];
     foreach ($foundFiles as $file) {
         $fileObject = $this->getMock('Magento\\Framework\\View\\File', [], [], '', false);
         $fileObject->expects($this->any())->method('getModule')->will($this->returnValue($file['module']));
         $fileObject->expects($this->any())->method('getFilename')->will($this->returnValue($file['filename']));
         $files[] = $fileObject;
     }
     $this->fileSource->expects($this->once())->method('getFiles')->with($theme, $resolvedPath)->will($this->returnValue($files));
     $this->object->process($chain);
     $this->assertEquals($expectedContent, $chain->getContent());
     $this->assertEquals('css', $chain->getContentType());
 }
コード例 #5
0
 /**
  * Find asset file via fallback mechanism
  *
  * @param LocalInterface $asset
  * @param \Magento\Framework\View\Asset\File\FallbackContext $context
  * @return bool|string
  */
 private function findFileThroughFallback(LocalInterface $asset, \Magento\Framework\View\Asset\File\FallbackContext $context)
 {
     $themeModel = $this->themeProvider->getThemeModel($context->getThemePath(), $context->getAreaCode());
     $sourceFile = $this->fallback->getFile($context->getAreaCode(), $themeModel, $context->getLocaleCode(), $asset->getFilePath(), $asset->getModule());
     return $sourceFile;
 }