public function testExecute()
    {
        $omFactory = $this->getMock('Magento\Framework\App\ObjectManagerFactory', [], [], '', false);
        $this->objectManagerProvider->expects($this->any())
            ->method('get')
            ->will($this->returnValue($this->objectManager));

        $this->objectManagerProvider->expects($this->once())
            ->method('getObjectManagerFactory')
            ->with([])
            ->willReturn($omFactory);

        $this->deployer->expects($this->once())->method('deploy');

        $this->objectManager->expects($this->at(0))
            ->method('create')
            ->willReturn($this->filesUtil);

        $this->objectManager->expects($this->at(1))
            ->method('create')
            ->willReturn($this->deployer);

        $this->validator->expects($this->once())->method('isValid')->with('en_US')->willReturn(true);

        $this->deploymentConfig->expects($this->once())
            ->method('isAvailable')
            ->will($this->returnValue(true));
        $tester = new CommandTester($this->command);
        $tester->execute([]);
    }
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage --language (-l) and --exclude-language cannot be used at the same tim
  */
 public function testExecuteIncludedExcludedLanguages()
 {
     $this->filesUtil->expects(self::any())->method('getStaticPreProcessingFiles')->willReturn([]);
     $this->objectManager->expects($this->at(0))->method('create')->willReturn($this->filesUtil);
     $this->validator->expects(self::exactly(2))->method('isValid')->willReturnMap([['en_US', true], ['uk_UA', true]]);
     $tester = new CommandTester($this->command);
     $tester->execute(['--language' => ['en_US', 'uk_UA'], '--exclude-language' => 'ru_RU']);
 }
 public function testExecute()
 {
     $this->deployer->expects($this->once())->method('deploy');
     $this->objectManager->expects($this->at(0))->method('create')->willReturn($this->filesUtil);
     $this->objectManager->expects($this->at(1))->method('create')->willReturn($this->deployer);
     $this->validator->expects($this->once())->method('isValid')->with('en_US')->willReturn(true);
     $tester = new CommandTester($this->command);
     $tester->execute([]);
 }
Ejemplo n.º 4
0
 /**
  * Set locale
  *
  * @param string $locale
  * @return $this
  */
 public function setLocale($locale = null)
 {
     $forceLocale = $this->_request->getParam('locale', null);
     if (!$this->_localeValidator->isValid($forceLocale)) {
         $forceLocale = false;
     }
     $sessionLocale = $this->_session->getSessionLocale();
     $userLocale = $this->_localeManager->getUserInterfaceLocale();
     $localeCodes = array_filter([$forceLocale, $sessionLocale, $userLocale]);
     if (count($localeCodes)) {
         $locale = reset($localeCodes);
     }
     return parent::setLocale($locale);
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $options = $input->getOptions();
     $languages = $input->getArgument(self::LANGUAGE_OPTION);
     foreach ($languages as $lang) {
         if (!$this->validator->isValid($lang)) {
             throw new \InvalidArgumentException($lang . ' argument has invalid value, please run info:language:list for list of available locales');
         }
     }
     // run the deployment logic
     $filesUtil = $this->objectManager->create(Files::class);
     $deployer = $this->objectManager->create('Magento\\Deploy\\Model\\Deployer', ['filesUtil' => $filesUtil, 'output' => $output, 'isDryRun' => $options[self::DRY_RUN_OPTION]]);
     $deployer->deploy($this->objectManagerFactory, $languages);
 }
Ejemplo n.º 6
0
 public function testExecute()
 {
     $file = 'css/styles-m' . '.less';
     $this->configLoader->expects($this->once())->method('load')->with('frontend')->willReturn([]);
     $this->objectManager->expects($this->once())->method('configure');
     $this->sourceFileGeneratorPool->expects($this->once())->method('create')->with('less')->willReturn($this->getMock('Magento\\Framework\\Less\\FileGenerator', [], [], '', false));
     $this->assetRepo->expects($this->once())->method('createAsset')->with($file, ['area' => 'frontend', 'theme' => 'Magento/blank', 'locale' => 'en_US'])->willReturn($this->getMockForAbstractClass('Magento\\Framework\\View\\Asset\\LocalInterface'));
     $this->assetSource->expects($this->once())->method('findSource')->willReturn('/dev/null');
     $this->chainFactory->expects($this->once())->method('create')->willReturn($this->getMock('Magento\\Framework\\View\\Asset\\PreProcessor\\Chain', [], [], '', false));
     $this->filesystem->expects($this->atLeastOnce())->method('getDirectoryWrite')->willReturn($this->getMock('\\Magento\\Framework\\Filesystem\\Directory\\WriteInterface', [], [], '', false));
     $this->validator->expects($this->once())->method('isValid')->with('en_US')->willReturn(true);
     $commandTester = new CommandTester($this->command);
     $commandTester->execute(['type' => 'less']);
     $this->assertContains('Successfully processed LESS and/or SASS files', $commandTester->getDisplay());
 }
 /**
  * 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);
 }
 /**
  * {@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>');
 }
Ejemplo n.º 9
0
 /**
  * {@inheritdoc}
  * @throws \InvalidArgumentException
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $locale = $input->getOption(self::LOCALE_OPTION);
     if (!$this->validator->isValid($locale)) {
         throw new \InvalidArgumentException($locale . ' argument has invalid value, please run info:language:list for list of available locales');
     }
     $area = $input->getOption(self::AREA_OPTION);
     $theme = $input->getOption(self::THEME_OPTION);
     $type = $input->getArgument(self::TYPE_ARGUMENT);
     $this->state->setAreaCode($area);
     $this->objectManager->configure($this->configLoader->load($area));
     $sourceFileGenerator = $this->sourceFileGeneratorPool->create($type);
     foreach ($input->getArgument(self::FILE_ARGUMENT) as $file) {
         $file .= '.' . $type;
         $output->writeln("<info>Gathering {$file} sources.</info>");
         $asset = $this->assetRepo->createAsset($file, ['area' => $area, 'theme' => $theme, 'locale' => $locale]);
         $rootDir = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT);
         $sourceFile = $this->assetSource->findSource($asset);
         $relativePath = $rootDir->getRelativePath($sourceFile);
         $content = $rootDir->readFile($relativePath);
         $chain = $this->chainFactory->create(['asset' => $asset, 'origContent' => $content, 'origContentType' => $asset->getContentType(), 'origAssetPath' => $relativePath]);
         $processedCoreFile = $sourceFileGenerator->generateFileTree($chain);
         $targetDir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW);
         $source = $rootDir->getRelativePath($processedCoreFile);
         $destination = $asset->getPath();
         $rootDir->copyFile($source, $destination, $targetDir);
         $output->writeln("<info>Successfully processed dynamic stylesheet into CSS</info>");
     }
 }
 /**
  * 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);
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $options = $input->getOptions();
     $languages = $input->getArgument(self::LANGUAGE_OPTION);
     foreach ($languages as $lang) {
         if (!$this->validator->isValid($lang)) {
             throw new \InvalidArgumentException($lang . ' argument has invalid value, please run info:language:list for list of available locales');
         }
     }
     try {
         // run the deployment logic
         $filesUtil = $this->objectManager->create('\\Magento\\Framework\\App\\Utility\\Files');
         $deployer = $this->objectManager->create('Magento\\Deploy\\Model\\Deployer', ['filesUtil' => $filesUtil, 'output' => $output, 'isDryRun' => $options[self::DRY_RUN_OPTION]]);
         $deployer->deploy($this->objectManagerFactory, $languages);
     } catch (\Exception $e) {
         $output->writeln('<error>' . $e->getMessage() . '</error>>');
         if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
             $output->writeln($e->getTraceAsString());
         }
         return;
     }
 }
 /**
  * {@inheritdoc}
  * @param $languagesInclude array
  * @param $languagesExclude array
  * @throws \InvalidArgumentException
  */
 private function checkLanguagesInput($languagesInclude, $languagesExclude)
 {
     if ($languagesInclude[0] != 'all') {
         foreach ($languagesInclude as $lang) {
             if (!$this->validator->isValid($lang)) {
                 throw new \InvalidArgumentException($lang . ' argument has invalid value, please run info:language:list for list of available locales');
             }
         }
     }
     if ($languagesInclude[0] != 'all' && $languagesExclude[0] != 'none') {
         throw new \InvalidArgumentException('--language (-l) and --exclude-language cannot be used at the same time');
     }
 }
Ejemplo n.º 13
0
    /**
     * {@inheritdoc}
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        if (!$this->deploymentConfig->isAvailable()) {
            $output->writeln("<info>You need to install the Magento application before running this utility.</info>");
            return;
        }

        $options = $input->getOptions();

        $languages = $input->getArgument(self::LANGUAGE_OPTION);
        foreach ($languages as $lang) {

            if (!$this->validator->isValid($lang)) {
                throw new \InvalidArgumentException(
                    $lang . ' argument has invalid value, please run info:language:list for list of available locales'
                );
            }
        }

        try {
            $objectManager = $this->objectManagerProvider->get();

            // run the deployment logic
            $filesUtil = $objectManager->create(
                '\Magento\Framework\App\Utility\Files',
                ['pathToSource' => BP]
            );

            $objectManagerFactory = $this->objectManagerProvider->getObjectManagerFactory();

            /** @var \Magento\Setup\Model\Deployer $deployer */
            $deployer = $objectManager->create(
                'Magento\Setup\Model\Deployer',
                ['filesUtil' => $filesUtil, 'output' => $output, 'isDryRun' => $options[self::DRY_RUN_OPTION]]
            );
            $deployer->deploy($objectManagerFactory, $languages);

        } catch (\Exception $e) {
            $output->writeln('<error>' . $e->getMessage() . '</error>>');
            if ($output->isVerbose()) {
                $output->writeln($e->getTraceAsString());
            }
            return;
        }
    }
 /**
  * @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>');
 }
 /**
  * Validate codes for languages, currencies or timezones
  *
  * @param Locale|Timezone|Currency  $lists
  * @param string  $code
  * @param string  $type
  * @return string
  */
 private function validateCodes($lists, $code, $type)
 {
     $errorMsg = '';
     if (!$lists->isValid($code)) {
         $errorMsg = '<error>' . 'Command option \'' . $type . '\': Invalid value. To see possible values, ' . "run command 'bin/magento info:" . $type . ':list\'.</error>';
     }
     return $errorMsg;
 }