Example #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->themeList->getThemeByFullPath($area . '/' . $theme);
         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;
 }
 /**
  * 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->themeList->getThemeByFullPath($context->getAreaCode() . '/' . $context->getThemePath());
     }
     return $this->design->getDesignTheme();
 }
 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->themeList->expects($this->any())->method('getThemeByFullPath')->will($this->returnValue($this->theme));
 }
Example #4
0
 /**
  * @return void
  */
 public function testGetStaticViewFileContext()
 {
     $themeMock = $this->getMock('Magento\\Framework\\View\\Design\\ThemeInterface', [], [], '', false);
     $this->designMock->expects($this->any())->method('getDesignParams')->willReturn(['themeModel' => $themeMock, 'area' => 'area', 'locale' => 'locale']);
     $this->themeProvider->expects($this->any())->method('getThemeByFullPath')->willReturnArgument(0);
     $this->httpMock->expects($this->any())->method('isSecure')->willReturn(false);
     $fallbackContextMock = $this->getMockBuilder('Magento\\Framework\\View\\Asset\\File\\FallbackContex')->disableOriginalConstructor()->getMock();
     $this->fallbackFactoryMock->expects($this->once())->method('create')->with(['baseUrl' => '', 'areaType' => 'area', 'themePath' => '', 'localeCode' => 'locale', 'isSecure' => ''])->willReturn($fallbackContextMock);
     $this->assertEquals($fallbackContextMock, $this->repository->getStaticViewFileContext());
 }
 /**
  * @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->themeList->expects($this->once())->method('getThemeByFullPath')->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());
 }
Example #6
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->themeList->getThemeByFullPath($context->getAreaCode() . '/' . $context->getThemePath());
     $sourceFile = $this->fallback->getFile(
         $context->getAreaCode(),
         $themeModel,
         $context->getLocale(),
         $asset->getFilePath(),
         $asset->getModule()
     );
     return $sourceFile;
 }
Example #7
0
 /**
  * @param FallbackContext $assetContext
  * @return \Magento\Framework\Config\View
  */
 public function getConfig(FallbackContext $assetContext)
 {
     return $this->viewConfig->getViewConfig(['area' => $assetContext->getAreaCode(), 'themeModel' => $this->themeList->getThemeByFullPath($assetContext->getAreaCode() . '/' . $assetContext->getThemePath())]);
 }