protected function configureAdminArea()
 {
     $config = ['test config'];
     $this->configLoaderMock->expects($this->once())->method('load')->with(FrontNameResolver::AREA_CODE)->will($this->returnValue($config));
     $this->objectManager->expects($this->once())->method('configure')->with($config);
     $this->stateMock->expects($this->once())->method('setAreaCode')->with(FrontNameResolver::AREA_CODE);
 }
Beispiel #2
0
 /**
  * Generates config per scope and returns it
  *
  * @param DefinitionsCollection $definitionsCollection
  * @param string $areaCode
  *
  * @return array
  */
 public function generateCachePerScope(DefinitionsCollection $definitionsCollection, $areaCode)
 {
     $areaConfig = clone $this->diContainerConfig;
     if ($areaCode !== App\Area::AREA_GLOBAL) {
         $areaConfig->extend($this->configLoader->load($areaCode));
     }
     $config = [];
     $this->fillThirdPartyInterfaces($areaConfig, $definitionsCollection);
     $config['arguments'] = $this->getConfigForScope($definitionsCollection, $areaConfig);
     foreach ($config['arguments'] as $key => $value) {
         if ($value !== null) {
             $config['arguments'][$key] = serialize($value);
         }
     }
     foreach ($definitionsCollection->getInstancesNamesList() as $instanceName) {
         if (!$areaConfig->isShared($instanceName)) {
             $config['nonShared'][$instanceName] = true;
         }
         $preference = $areaConfig->getPreference($instanceName);
         if ($instanceName !== $preference) {
             $config['preferences'][$instanceName] = $preference;
         }
     }
     foreach (array_keys($areaConfig->getVirtualTypes()) as $virtualType) {
         $config['instanceTypes'][$virtualType] = $areaConfig->getInstanceType($virtualType);
     }
     return $config;
 }
 /**
  * @param $area
  * @dataProvider loadDataProvider
  */
 public function testLoad($area)
 {
     $configData = ['some' => 'config', 'data' => 'value'];
     $this->_cacheMock->expects($this->once())->method('load')->with($area . '::DiConfig')->will($this->returnValue(false));
     $this->_readerMock->expects($this->once())->method('read')->with($area)->will($this->returnValue($configData));
     $this->assertEquals($configData, $this->_model->load($area));
 }
 /**
  * {@inheritdoc}
  **/
 public function launch()
 {
     $areaCode = 'adminhtml';
     $this->appState->setAreaCode($areaCode);
     $this->objectManager->configure($this->configLoader->load($areaCode));
     /** @var \Magento\Tools\SampleData\Logger $sampleDataLogger */
     $sampleDataLogger = $this->objectManager->get('Magento\\Tools\\SampleData\\Logger');
     $sampleDataLogger->setSubject($this->objectManager->get('Magento\\Setup\\Model\\ConsoleLogger'));
     $this->installer->run($this->userFactory->create()->loadByUsername($this->adminUserName));
     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();
 }
 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());
 }
Beispiel #7
0
 /**
  * Run application
  *
  * @return \Magento\Framework\App\ResponseInterface
  */
 public function launch()
 {
     $areaCode = 'install';
     $this->_state->setAreaCode($areaCode);
     $this->_objectManager->configure($this->_loader->load($areaCode));
     if (isset($this->_arguments['uninstall'])) {
         $sessionConsole = $this->_objectManager->create('\\Magento\\Framework\\Session\\SessionConsole');
         $installerModel = $this->_objectManager->create('Magento\\Install\\Model\\Installer', ['session' => $sessionConsole]);
         $installer = $this->_installerFactory->create(['installArgs' => $this->_arguments, 'installer' => $installerModel]);
     } else {
         $installer = $this->_installerFactory->create(array('installArgs' => $this->_arguments));
     }
     if (isset($this->_arguments['show_locales'])) {
         $this->_output->readableOutput($this->_output->prepareArray($installer->getAvailableLocales()));
     } elseif (isset($this->_arguments['show_currencies'])) {
         $this->_output->readableOutput($this->_output->prepareArray($installer->getAvailableCurrencies()));
     } elseif (isset($this->_arguments['show_timezones'])) {
         $this->_output->readableOutput($this->_output->prepareArray($installer->getAvailableTimezones()));
     } elseif (isset($this->_arguments['show_install_options'])) {
         $this->_output->readableOutput(PHP_EOL . 'Required parameters:');
         $this->_output->readableOutput($this->_output->alignArrayKeys($installer->getRequiredParams()));
         $this->_output->readableOutput(PHP_EOL . 'Optional parameters:');
         $this->_output->readableOutput($this->_output->alignArrayKeys($installer->getOptionalParams()));
         $this->_output->readableOutput(PHP_EOL . 'Flag values are considered positive if set to 1, y, true or yes.' . 'Any other value is considered as negative.' . PHP_EOL);
     } else {
         $this->_handleInstall($installer);
     }
     $this->_response->setCode(0);
     return $this->_response;
 }
 /**
  * {@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>");
     }
 }
Beispiel #9
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;
 }
Beispiel #10
0
 /**
  * Run application
  *
  * @return ResponseInterface
  */
 public function launch()
 {
     $areaCode = $this->_areaList->getCodeByFrontName($this->_request->getFrontName());
     $this->_state->setAreaCode($areaCode);
     $this->_objectManager->configure($this->_configLoader->load($areaCode));
     $this->_response = $this->_objectManager->get('Magento\\Framework\\App\\FrontControllerInterface')->dispatch($this->_request);
     // This event gives possibility to launch something before sending output (allow cookie setting)
     $eventParams = array('request' => $this->_request, 'response' => $this->_response);
     $this->_eventManager->dispatch('controller_front_send_response_before', $eventParams);
     return $this->_response;
 }
Beispiel #11
0
 /**
  * Run application
  *
  * @return ResponseInterface
  */
 public function launch()
 {
     try {
         $areaCode = $this->_areaList->getCodeByFrontName($this->_request->getFrontName());
         $this->_state->setAreaCode($areaCode);
         $this->_objectManager->configure($this->_configLoader->load($areaCode));
         $this->_response = $this->_objectManager->get('Magento\\Framework\\App\\FrontControllerInterface')->dispatch($this->_request);
         // This event gives possibility to launch something before sending output (allow cookie setting)
         $eventParams = array('request' => $this->_request, 'response' => $this->_response);
         $this->_eventManager->dispatch('controller_front_send_response_before', $eventParams);
     } catch (\Exception $exception) {
         $message = $exception->getMessage() . "\n";
         try {
             if ($this->_state->getMode() == State::MODE_DEVELOPER) {
                 $message .= '<pre>';
                 $message .= $exception->getMessage() . "\n\n";
                 $message .= $exception->getTraceAsString();
                 $message .= '</pre>';
             } else {
                 $reportData = array($exception->getMessage(), $exception->getTraceAsString());
                 // retrieve server data
                 if (isset($_SERVER)) {
                     if (isset($_SERVER['REQUEST_URI'])) {
                         $reportData['url'] = $_SERVER['REQUEST_URI'];
                     }
                     if (isset($_SERVER['SCRIPT_NAME'])) {
                         $reportData['script_name'] = $_SERVER['SCRIPT_NAME'];
                     }
                 }
                 require_once $this->_filesystem->getPath(Filesystem::PUB_DIR) . '/errors/report.php';
                 $processor = new \Magento\Framework\Error\Processor($this->_response);
                 $processor->saveReport($reportData);
                 $this->_response = $processor->processReport();
             }
         } catch (\Exception $exception) {
             $message .= "Unknown error happened.";
         }
         $this->_response->setHttpResponseCode(500);
         $this->_response->setBody($message);
     }
     return $this->_response;
 }
 /**
  * Launch application
  *
  * @return \Magento\Framework\App\ResponseInterface
  */
 public function launch()
 {
     $this->state->setAreaCode($this->params->getArea());
     $this->objectManager->configure($this->configLoader->load($this->params->getArea()));
     $sourceFileGenerator = $this->sourceFileGeneratorPool->create($this->params->getExt());
     foreach ($this->params->getFiles() as $file) {
         $file .= '.' . $this->params->getExt();
         $this->logger->logMessage("Gathering {$file} sources.");
         $asset = $this->assetRepo->createAsset($file, ['area' => $this->params->getArea(), 'theme' => $this->params->getTheme(), 'locale' => $this->params->getLocale()]);
         $sourceFile = $this->assetSource->findSource($asset);
         $content = \file_get_contents($sourceFile);
         $chain = $this->chainFactory->create(['asset' => $asset, 'origContent' => $content, 'origContentType' => $asset->getContentType()]);
         $processedCoreFile = $sourceFileGenerator->generateFileTree($chain);
         $targetDir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW);
         $rootDir = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT);
         $source = $rootDir->getRelativePath($processedCoreFile);
         $destination = $asset->getPath();
         $rootDir->copyFile($source, $destination, $targetDir);
         $this->logger->logMessage("Done");
     }
     $this->response->setCode(Response::SUCCESS);
     return $this->response;
 }
Beispiel #13
0
 /**
  * Load area configuration
  *
  * @return $this
  */
 protected function _initConfig()
 {
     $this->_objectManager->configure($this->_diConfigLoader->load($this->_code));
     return $this;
 }