/**
  * @inheritdoc
  */
 protected function generateRelatedFile($relatedFileId, LocalInterface $asset)
 {
     $relatedAsset = parent::generateRelatedFile($relatedFileId, $asset);
     if ($this->hasRelatedPublishing || WorkflowType::CLIENT_SIDE_COMPILATION === $this->scopeConfig->getValue(WorkflowType::CONFIG_NAME_PATH)) {
         $this->assetPublisher->publish($relatedAsset);
     }
     return $relatedAsset;
 }
Beispiel #2
0
 public function testPublish()
 {
     $this->staticDirRead->expects($this->once())->method('isExist')->with('some/file.ext')->will($this->returnValue(false));
     $materializationStrategy = $this->getMock('Magento\\Framework\\App\\View\\Asset\\MaterializationStrategy\\StrategyInterface', [], [], '', false);
     $this->materializationStrategyFactory->expects($this->once())->method('create')->with($this->getAsset())->will($this->returnValue($materializationStrategy));
     $materializationStrategy->expects($this->once())->method('publishFile')->with($this->sourceDirWrite, $this->staticDirWrite, 'file.ext', 'some/file.ext')->will($this->returnValue(true));
     $this->assertTrue($this->object->publish($this->getAsset()));
 }
Beispiel #3
0
 public function testPublish()
 {
     $this->appState->expects($this->once())->method('getMode')->will($this->returnValue(\Magento\Framework\App\State::MODE_PRODUCTION));
     $this->staticDirRead->expects($this->once())->method('isExist')->with('some/file.ext')->will($this->returnValue(false));
     $this->rootDirWrite->expects($this->once())->method('getRelativePath')->with('/root/some/file.ext')->will($this->returnValue('some/file.ext'));
     $this->rootDirWrite->expects($this->once())->method('copyFile')->with('some/file.ext', 'some/file.ext', $this->staticDirWrite)->will($this->returnValue(true));
     $this->assertTrue($this->object->publish($this->getAsset()));
 }
 /**
  * Run test for execute method
  */
 public function testExecute()
 {
     /** @var OutputInterface|\PHPUnit_Framework_MockObject_MockObject $outputMock */
     $outputMock = $this->getMockBuilder(OutputInterface::class)->getMockForAbstractClass();
     $assetMock = $this->getMockBuilder(LocalInterface::class)->getMockForAbstractClass();
     $this->validatorMock->expects(self::once())->method('isValid')->with(self::LOCALE_TEST_VALUE)->willReturn(true);
     $message = sprintf('<info>Processed Area: %s, Locale: %s, Theme: %s, File type: %s.</info>', self::AREA_TEST_VALUE, self::LOCALE_TEST_VALUE, self::THEME_TEST_VALUE, self::TYPE_TEST_VALUE);
     $outputMock->expects(self::at(0))->method('writeln')->with($message);
     $outputMock->expects(self::at(1))->method('writeln')->with('<comment>-> file-test-value/test/file</comment>');
     $outputMock->expects(self::at(2))->method('writeln')->with('<info>Successfully processed.</info>');
     $this->assetRepositoryMock->expects(self::once())->method('createAsset')->with('file-test-value/test' . DIRECTORY_SEPARATOR . 'file' . '.' . self::TYPE_TEST_VALUE, ['area' => self::AREA_TEST_VALUE, 'theme' => self::THEME_TEST_VALUE, 'locale' => self::LOCALE_TEST_VALUE])->willReturn($assetMock);
     $this->assetPublisherMock->expects(self::once())->method('publish')->with($assetMock);
     $assetMock->expects(self::once())->method('getFilePath')->willReturn(self::FILE_TEST_VALUE);
     $this->sourceThemeDeployCommand->run($this->getInputMock(), $outputMock);
 }
Beispiel #5
0
 /**
  * Deploy a static view file
  *
  * @param string $filePath
  * @param string $area
  * @param string $themePath
  * @param string $locale
  * @param string $module
  * @return void
  */
 private function deployFile($filePath, $area, $themePath, $locale, $module)
 {
     $requestedPath = $filePath;
     if (substr($filePath, -5) == '.less') {
         $requestedPath = preg_replace('/.less$/', '.css', $filePath);
     }
     $logMessage = "Processing file '{$filePath}' for area '{$area}', theme '{$themePath}', locale '{$locale}'";
     if ($module) {
         $logMessage .= ", module '{$module}'";
     }
     $this->logger->logDebug($logMessage);
     try {
         $asset = $this->assetRepo->createAsset($requestedPath, ['area' => $area, 'theme' => $themePath, 'locale' => $locale, 'module' => $module]);
         $asset = $this->minifyService->getAssets([$asset], true)[0];
         $this->logger->logDebug("\tDeploying the file to '{$asset->getPath()}'", '.');
         if ($this->isDryRun) {
             $asset->getContent();
         } else {
             $this->assetPublisher->publish($asset);
             $this->bundleManager->addAsset($asset);
         }
         $this->count++;
     } catch (\Magento\Framework\View\Asset\File\NotFoundException $e) {
         // File was not found by Fallback (possibly because it's wrong context for it) - there is nothing to publish
         $this->logger->logDebug("\tNotice: Could not find file '{$filePath}'. This file may not be relevant for the theme or area.");
     } catch (\Less_Exception_Compiler $e) {
         $this->logger->logDebug("\tNotice: Could not parse LESS file '{$filePath}'. " . "This may indicate that the file is incomplete, but this is acceptable. " . "The file '{$filePath}' will be combined with another LESS file.");
     } catch (\Exception $e) {
         $this->logger->logError($e->getMessage() . " ({$logMessage})");
         $this->logger->logDebug((string) $e);
         $this->errorCount++;
     }
 }
 /**
  * {@inheritdoc}
  * @throws \InvalidArgumentException
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $area = $input->getOption(self::AREA_OPTION);
     $locale = $input->getOption(self::LOCALE_OPTION);
     $theme = $input->getOption(self::THEME_OPTION);
     $type = $input->getOption(self::TYPE_ARGUMENT);
     $files = $input->getArgument(self::FILE_ARGUMENT);
     if (!$this->validator->isValid($locale)) {
         throw new \InvalidArgumentException($locale . ' argument has invalid value, please run info:language:list for list of available locales');
     }
     if (!preg_match('#^[\\w\\-]+\\/[\\w\\-]+$#', $theme)) {
         throw new \InvalidArgumentException('Value "' . $theme . '" of the option "' . self::THEME_OPTION . '" has invalid format. The format should be "Vendor/theme".');
     }
     $message = sprintf('<info>Processed Area: %s, Locale: %s, Theme: %s, File type: %s.</info>', $area, $locale, $theme, $type);
     $output->writeln($message);
     foreach ($files as $file) {
         $fileInfo = pathinfo($file);
         $asset = $this->assetRepository->createAsset($fileInfo['dirname'] . DIRECTORY_SEPARATOR . $fileInfo['basename'] . '.' . $type, ['area' => $area, 'theme' => $theme, 'locale' => $locale]);
         try {
             $this->assetPublisher->publish($asset);
         } catch (\Magento\Framework\View\Asset\File\NotFoundException $e) {
             throw new \InvalidArgumentException('Verify entered values of the argument and options. ' . $e->getMessage());
         }
         $output->writeln('<comment>-> ' . $asset->getFilePath() . '</comment>');
     }
     $output->writeln('<info>Successfully processed.</info>');
 }
Beispiel #7
0
 /**
  * Finds requested resource and provides it to the client
  *
  * @return \Magento\Framework\App\ResponseInterface
  * @throws \Exception
  */
 public function launch()
 {
     $appMode = $this->state->getMode();
     if ($appMode == \Magento\Framework\App\State::MODE_PRODUCTION) {
         $this->response->setHttpResponseCode(404);
     } else {
         try {
             $path = $this->request->get('resource');
             $params = $this->parsePath($path);
             $this->state->setAreaCode($params['area']);
             $this->objectManager->configure($this->configLoader->load($params['area']));
             $file = $params['file'];
             unset($params['file']);
             $asset = $this->assetRepo->createAsset($file, $params);
             $this->response->setFilePath($asset->getSourceFile());
             $this->publisher->publish($asset);
         } catch (\Exception $e) {
             if ($appMode == \Magento\Framework\App\State::MODE_DEVELOPER) {
                 throw $e;
             }
             $this->response->setHttpResponseCode(404);
         }
     }
     return $this->response;
 }
 /**
  * Run test for execute method with non existing theme
  *
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage Verify entered values of the argument and options.
  */
 public function testExecuteNonExistingValue()
 {
     /** @var OutputInterface|\PHPUnit_Framework_MockObject_MockObject $outputMock */
     $outputMock = $this->getMockBuilder(OutputInterface::class)->getMockForAbstractClass();
     $assetMock = $this->getMockBuilder(LocalInterface::class)->getMockForAbstractClass();
     $this->validatorMock->expects(self::once())->method('isValid')->with(self::LOCALE_TEST_VALUE)->willReturn(true);
     $this->assetRepositoryMock->expects(self::once())->method('createAsset')->with('file-test-value/test' . DIRECTORY_SEPARATOR . 'file' . '.' . self::TYPE_TEST_VALUE, ['area' => self::AREA_TEST_VALUE, 'theme' => self::THEME_NONEXISTING_VALUE, 'locale' => self::LOCALE_TEST_VALUE])->willReturn($assetMock);
     $this->assetPublisherMock->expects(self::once())->method('publish')->with($assetMock)->willThrowException(new \Magento\Framework\View\Asset\File\NotFoundException());
     $valueMap = [['area', self::AREA_TEST_VALUE], ['locale', self::LOCALE_TEST_VALUE], ['theme', self::THEME_NONEXISTING_VALUE], ['type', self::TYPE_TEST_VALUE]];
     $this->sourceThemeDeployCommand->run($this->getInputMock($valueMap), $outputMock);
 }
 /**
  * Finds requested resource and provides it to the client
  *
  * @return \Magento\Framework\App\ResponseInterface
  * @throws \Exception
  */
 public function launch()
 {
     // disabling profiling when retrieving static resource
     \Magento\Framework\Profiler::reset();
     $appMode = $this->state->getMode();
     if ($appMode == \Magento\Framework\App\State::MODE_PRODUCTION) {
         $this->response->setHttpResponseCode(404);
     } else {
         $path = $this->request->get('resource');
         $params = $this->parsePath($path);
         $this->state->setAreaCode($params['area']);
         $this->objectManager->configure($this->configLoader->load($params['area']));
         $file = $params['file'];
         unset($params['file']);
         $asset = $this->assetRepo->createAsset($file, $params);
         $this->response->setFilePath($asset->getSourceFile());
         $this->publisher->publish($asset);
     }
     return $this->response;
 }
 /**
  * @param string $mode
  * @param string $requestedPath
  * @param string $requestedModule
  * @param bool $moduleExists
  * @param string $expectedFile
  * @param array $expectedParams
  *
  * @dataProvider launchDataProvider
  */
 public function testLaunch($mode, $requestedPath, $requestedModule, $moduleExists, $expectedFile, array $expectedParams)
 {
     $this->state->expects($this->once())->method('getMode')->will($this->returnValue($mode));
     $this->state->expects($this->once())->method('setAreaCode')->with('area');
     $this->configLoader->expects($this->once())->method('load')->with('area')->will($this->returnValue(['config']));
     $this->objectManager->expects($this->once())->method('configure')->with(['config']);
     $this->request->expects($this->once())->method('get')->with('resource')->will($this->returnValue($requestedPath));
     $this->moduleList->expects($this->any())->method('has')->with($requestedModule)->will($this->returnValue($moduleExists));
     $asset = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Asset\\LocalInterface');
     $asset->expects($this->once())->method('getSourceFile')->will($this->returnValue('resource/file.css'));
     $this->assetRepo->expects($this->once())->method('createAsset')->with($expectedFile, $expectedParams)->will($this->returnValue($asset));
     $this->publisher->expects($this->once())->method('publish')->with($asset);
     $this->response->expects($this->once())->method('setFilePath')->with('resource/file.css');
     $this->object->launch();
 }
Beispiel #11
0
    /**
     * Deploy a static view file
     *
     * @param string $filePath
     * @param string $area
     * @param string $themePath
     * @param string $locale
     * @param string $module
     * @return void
     * @SuppressWarnings(PHPMD.NPathComplexity)
     */
    private function deployFile($filePath, $area, $themePath, $locale, $module)
    {
        $requestedPath = $filePath;
        if (substr($filePath, -5) == '.less') {
            $requestedPath = preg_replace('/.less$/', '.css', $filePath);
        }
        $logMessage = "Processing file '$filePath' for area '$area', theme '$themePath', locale '$locale'";
        if ($module) {
            $logMessage .= ", module '$module'";
        }

        if ($this->output->isVeryVerbose()) {
            $this->output->writeln($logMessage);
        }

        try {
            $asset = $this->assetRepo->createAsset(
                $requestedPath,
                ['area' => $area, 'theme' => $themePath, 'locale' => $locale, 'module' => $module]
            );
            $asset = $this->minifyService->getAssets([$asset], true)[0];
            if ($this->output->isVeryVerbose()) {
                $this->output->writeln("\tDeploying the file to '{$asset->getPath()}'");
            } else {
                $this->output->write('.');
            }
            if ($this->isDryRun) {
                $asset->getContent();
            } else {
                $this->assetPublisher->publish($asset);
                $this->bundleManager->addAsset($asset);
            }
            $this->count++;
        } catch (\Less_Exception_Compiler $e) {
            $this->verboseLog(
                "\tNotice: Could not parse LESS file '$filePath'. "
                . "This may indicate that the file is incomplete, but this is acceptable. "
                . "The file '$filePath' will be combined with another LESS file."
            );
            $this->verboseLog("\tCompiler error: " . $e->getMessage());
        } catch (\Exception $e) {
            $this->output->writeln($e->getMessage() . " ($logMessage)");
            $this->verboseLog($e->getTraceAsString());
            $this->errorCount++;
        }
    }
Beispiel #12
0
 /**
  * Deploy a static view file
  *
  * @param string $filePath
  * @param string $area
  * @param string $themePath
  * @param string $locale
  * @param string $module
  * @param string|null $fullPath
  * @return string
  * @throws \InvalidArgumentException
  * @throws LocalizedException
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 private function deployFile($filePath, $area, $themePath, $locale, $module, $fullPath = null)
 {
     $compiledFile = '';
     $extension = pathinfo($filePath, PATHINFO_EXTENSION);
     foreach ($this->alternativeSources as $name => $alternative) {
         if (in_array($extension, $alternative->getAlternativesExtensionsNames(), true) && strpos(basename($filePath), '_') !== 0) {
             $compiledFile = substr($filePath, 0, strlen($filePath) - strlen($extension) - 1);
             $compiledFile = $compiledFile . '.' . $name;
         }
     }
     if ($this->output->isVeryVerbose()) {
         $logMessage = "Processing file '{$filePath}' for area '{$area}', theme '{$themePath}', locale '{$locale}'";
         if ($module) {
             $logMessage .= ", module '{$module}'";
         }
         $this->output->writeln($logMessage);
     }
     try {
         $asset = $this->assetRepo->createAsset($filePath, ['area' => $area, 'theme' => $themePath, 'locale' => $locale, 'module' => $module]);
         if ($this->output->isVeryVerbose()) {
             $this->output->writeln("\tDeploying the file to '{$asset->getPath()}'");
         } else {
             $this->output->write('.');
         }
         if ($this->getOption(Options::DRY_RUN)) {
             $asset->getContent();
         } else {
             $this->assetPublisher->publish($asset);
             $this->bundleManager->addAsset($asset);
         }
         $this->count++;
     } catch (ContentProcessorException $exception) {
         $pathInfo = $fullPath ?: $filePath;
         $errorMessage = __('Compilation from source: ') . $pathInfo . PHP_EOL . $exception->getMessage();
         $this->errorCount++;
         $this->output->write(PHP_EOL . PHP_EOL . $errorMessage . PHP_EOL, true);
         $this->getLogger()->critical($errorMessage);
     } catch (\Exception $exception) {
         $this->output->write('.');
         $this->verboseLog($exception->getTraceAsString());
         $this->errorCount++;
     }
     return $compiledFile;
 }
 /**
  * @inheritdoc
  * @throws \InvalidArgumentException
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $area = $input->getOption(self::AREA_OPTION);
     $locale = $input->getOption(self::LOCALE_OPTION);
     $theme = $input->getOption(self::THEME_OPTION);
     $type = $input->getOption(self::TYPE_ARGUMENT);
     $files = $input->getArgument(self::FILE_ARGUMENT);
     if (!$this->validator->isValid($locale)) {
         throw new \InvalidArgumentException($locale . ' argument has invalid value, please run info:language:list for list of available locales');
     }
     $message = sprintf('<info>Processed Area: %s, Locale: %s, Theme: %s, File type: %s.</info>', $area, $locale, $theme, $type);
     $output->writeln($message);
     foreach ($files as $file) {
         $fileInfo = pathinfo($file);
         $asset = $this->assetRepository->createAsset($fileInfo['dirname'] . DIRECTORY_SEPARATOR . $fileInfo['basename'] . '.' . $type, ['area' => $area, 'theme' => $theme, 'locale' => $locale]);
         $this->assetPublisher->publish($asset);
         $output->writeln('<comment>-> ' . $asset->getFilePath() . '</comment>');
     }
     $output->writeln('<info>Successfully processed.</info>');
 }
Beispiel #14
0
 /**
  * Deploy a static view file
  *
  * @param string $filePath
  * @param string $area
  * @param string $themePath
  * @param string $locale
  * @param string $module
  * @return void
  */
 private function deployFile($filePath, $area, $themePath, $locale, $module)
 {
     $requestedPath = $filePath;
     if (substr($filePath, -5) == '.less') {
         $requestedPath = preg_replace('/.less$/', '.css', $filePath);
     }
     $logModule = $module ? "<{$module}>" : (null === $module ? '<lib>' : '<theme>');
     try {
         $asset = $this->assetRepo->createAsset($requestedPath, ['area' => $area, 'theme' => $themePath, 'locale' => $locale, 'module' => $module]);
         $this->logger->logDebug("{$logModule} {$filePath} -> {$asset->getPath()}");
         if ($this->isDryRun) {
             $asset->getContent();
         } else {
             $this->assetPublisher->publish($asset);
         }
         $this->count++;
     } catch (\Exception $e) {
         $this->logger->logError("{$logModule} {$filePath}");
         $this->logger->logDebug((string) $e);
         $this->errorCount++;
     }
 }
 /**
  * {inheritdoc}
  */
 protected function generateRelatedFile($relatedFileId, LocalInterface $asset)
 {
     $relatedAsset = parent::generateRelatedFile($relatedFileId, $asset);
     $this->publisher->publish($relatedAsset);
     return $relatedAsset;
 }