Пример #1
0
 /**
  * Run test for process method (exception)
  *
  * @expectedException \UnexpectedValueException
  * @expectedExceptionMessage "stdClass" has to implement the PreProcessorInterface.
  */
 public function testProcessBadInterface()
 {
     $preprocessors = [self::CONTENT_TYPE => ['test' => [Pool::PREPROCESSOR_CLASS => 'stdClass']]];
     $pool = new Pool($this->objectManagerMock, $this->sorterMock, self::DEFAULT_PREPROCESSOR, $preprocessors);
     $this->sorterMock->expects(self::once())->method('sort')->with($preprocessors[self::CONTENT_TYPE])->willReturn($preprocessors[self::CONTENT_TYPE]);
     $chainMock = $this->getChainMock(self::CONTENT_TYPE);
     $this->objectManagerMock->expects(self::once())->method('get')->with('stdClass')->willReturn(new \stdClass());
     $pool->process($chainMock);
 }
Пример #2
0
 /**
  * Retrieve preProcessors by types
  *
  * @param string $type
  * @return PreProcessorInterface[]
  * @throws \UnexpectedValueException
  */
 private function getPreProcessors($type)
 {
     if (isset($this->instances[$type])) {
         return $this->instances[$type];
     }
     if (isset($this->preprocessors[$type])) {
         $preprocessors = $this->sorter->sort($this->preprocessors[$type]);
     } else {
         $preprocessors = ['default' => [self::PREPROCESSOR_CLASS => $this->defaultPreprocessor]];
     }
     $this->instances[$type] = [];
     foreach ($preprocessors as $preprocessor) {
         $instance = $this->objectManager->get($preprocessor[self::PREPROCESSOR_CLASS]);
         if (!$instance instanceof PreProcessorInterface) {
             throw new \UnexpectedValueException('"' . $preprocessor[self::PREPROCESSOR_CLASS] . '" has to implement the PreProcessorInterface.');
         }
         $this->instances[$type][] = $instance;
     }
     return $this->instances[$type];
 }
 /**
  * Run test for process method
  */
 public function testProcess()
 {
     $alternatives = ['processor' => [AlternativeSource::PROCESSOR_CLASS => 'Magento\\Framework\\View\\Asset\\ContentProcessorInterface']];
     $this->lockerProcessMock->expects(self::once())->method('lockProcess')->with(self::isType('string'));
     $this->lockerProcessMock->expects(self::once())->method('unlockProcess');
     $this->sorterMock->expects(self::once())->method('sort')->with($alternatives)->willReturn($alternatives);
     $assetMock = $this->getAssetNew();
     $this->assetBuilderMock->expects(self::once())->method('setArea')->with(self::AREA)->willReturnSelf();
     $this->assetBuilderMock->expects(self::once())->method('setTheme')->with(self::THEME)->willReturnSelf();
     $this->assetBuilderMock->expects(self::once())->method('setLocale')->with(self::LOCALE)->willReturnSelf();
     $this->assetBuilderMock->expects(self::once())->method('setModule')->with(self::MODULE)->willReturnSelf();
     $this->assetBuilderMock->expects(self::once())->method('setPath')->with(self::FILE_PATH)->willReturnSelf();
     $this->assetBuilderMock->expects(self::once())->method('build')->willReturn($assetMock);
     $this->objectManagerMock->expects(self::once())->method('get')->with('Magento\\Framework\\View\\Asset\\ContentProcessorInterface')->willReturn($this->getProcessorMock($assetMock));
     $alternativeSource = new AlternativeSource($this->objectManagerMock, $this->lockerProcessMock, $this->sorterMock, $this->assetBuilderMock, 'lock', $alternatives);
     $alternativeSource->process($this->getChainMockExpects());
 }
 /**
  * Preparation of content for the destination file
  *
  * @param string $path
  * @param string $content
  * @param string $module
  * @param FallbackContext $context
  * @return string
  * @throws \UnexpectedValueException
  */
 private function processContent($path, $content, $module, FallbackContext $context)
 {
     if ($this->alternativesSorted === null) {
         $this->alternativesSorted = $this->sorter->sort($this->alternatives);
     }
     foreach ($this->alternativesSorted as $name => $alternative) {
         $asset = $this->assetBuilder->setArea($context->getAreaCode())->setTheme($context->getThemePath())->setLocale($context->getLocale())->setModule($module)->setPath(preg_replace('#\\.' . preg_quote(pathinfo($path, PATHINFO_EXTENSION)) . '$#', '.' . $name, $path))->build();
         $processor = $this->objectManager->get($alternative[self::PROCESSOR_CLASS]);
         if (!$processor instanceof ContentProcessorInterface) {
             throw new \UnexpectedValueException('"' . $alternative[self::PROCESSOR_CLASS] . '" has to implement the ContentProcessorInterface.');
         }
         $content = $processor->processContent($asset);
         if (trim($content) !== '') {
             return $content;
         }
     }
     return $content;
 }