Ejemplo n.º 1
0
 /**
  * @inheritdoc
  * @throws ContentProcessorException
  */
 public function processContent(File $asset)
 {
     $path = $asset->getPath();
     try {
         $parser = new \Less_Parser(['relativeUrls' => false, 'compress' => $this->appState->getMode() !== State::MODE_DEVELOPER]);
         $content = $this->assetSource->getContent($asset);
         if (trim($content) === '') {
             return '';
         }
         $tmpFilePath = $this->temporaryFile->createFile($path, $content);
         gc_disable();
         $parser->parseFile($tmpFilePath, '');
         $content = $parser->getCss();
         gc_enable();
         if (trim($content) === '') {
             $errorMessage = PHP_EOL . self::ERROR_MESSAGE_PREFIX . PHP_EOL . $path;
             $this->logger->critical($errorMessage);
             throw new ContentProcessorException(new Phrase($errorMessage));
         }
         return $content;
     } catch (\Exception $e) {
         $errorMessage = PHP_EOL . self::ERROR_MESSAGE_PREFIX . PHP_EOL . $path . PHP_EOL . $e->getMessage();
         $this->logger->critical($errorMessage);
         throw new ContentProcessorException(new Phrase($errorMessage));
     }
 }
Ejemplo n.º 2
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());
 }
Ejemplo n.º 3
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>");
     }
 }
Ejemplo n.º 4
0
 /**
  * Process file content
  *
  * @param File $asset
  * @return string
  */
 public function processContent(File $asset)
 {
     $path = $asset->getPath();
     try {
         $compiler = new \scssc();
         $content = $this->assetSource->getContent($asset);
         if (trim($content) === '') {
             return '';
         }
         return $compiler->compile($content);
     } catch (\Exception $e) {
         $errorMessage = PHP_EOL . self::ERROR_MESSAGE_PREFIX . PHP_EOL . $path . PHP_EOL . $e->getMessage();
         $this->logger->critical($errorMessage);
         return $errorMessage;
     }
 }
Ejemplo n.º 5
0
 /**
  * @param $store
  * @param $country
  * @return array
  */
 protected function _fetchHppMethods($store, $country)
 {
     $skinCode = $this->_adyenHelper->getAdyenHppConfigData('skin_code');
     $merchantAccount = $this->_adyenHelper->getAdyenAbstractConfigData('merchant_account');
     if (!$skinCode || !$merchantAccount) {
         return [];
     }
     $adyFields = ["paymentAmount" => (int) $this->_adyenHelper->formatAmount($this->_getCurrentPaymentAmount(), $this->_getCurrentCurrencyCode($store)), "currencyCode" => $this->_getCurrentCurrencyCode($store), "merchantReference" => "Get Payment methods", "skinCode" => $skinCode, "merchantAccount" => $merchantAccount, "sessionValidity" => date(DATE_ATOM, mktime(date("H") + 1, date("i"), date("s"), date("m"), date("j"), date("Y"))), "countryCode" => $this->_getCurrentCountryCode($store, $country), "shopperLocale" => $this->_getCurrentLocaleCode($store)];
     $responseData = $this->_getDirectoryLookupResponse($adyFields, $store);
     $paymentMethods = [];
     if (isset($responseData['paymentMethods'])) {
         foreach ($responseData['paymentMethods'] as $paymentMethod) {
             $paymentMethodCode = $paymentMethod['brandCode'];
             $paymentMethod = $this->_fieldMapPaymentMethod($paymentMethod);
             // check if payment method is an openinvoice method
             $paymentMethod['isPaymentMethodOpenInvoiceMethod'] = $this->_adyenHelper->isPaymentMethodOpenInvoiceMethod($paymentMethodCode);
             // add icon location in result
             if ($this->_adyenHelper->showLogos()) {
                 $params = [];
                 // use frontend area
                 $params = array_merge(['area' => 'frontend', '_secure' => $this->_request->isSecure()], $params);
                 $asset = $this->_assetRepo->createAsset('Adyen_Payment::images/logos/' . $paymentMethodCode . '.png', $params);
                 $placeholder = $this->_assetSource->findSource($asset);
                 $icon = null;
                 if ($placeholder) {
                     list($width, $height) = getimagesize($asset->getSourceFile());
                     $icon = ['url' => $asset->getUrl(), 'width' => $width, 'height' => $height];
                 }
                 $paymentMethod['icon'] = $icon;
             }
             $paymentMethods[$paymentMethodCode] = $paymentMethod;
         }
     }
     return $paymentMethods;
 }
Ejemplo n.º 6
0
 /**
  * Get icons for available payment methods
  *
  * @return array
  */
 protected function getIcons()
 {
     $icons = [];
     $types = $this->ccConfig->getCcAvailableTypes();
     foreach (array_keys($types) as $code) {
         if (!array_key_exists($code, $icons)) {
             $asset = $this->ccConfig->createAsset('Magento_Payment::images/cc/' . strtolower($code) . '.png');
             $placeholder = $this->assetSource->findRelativeSourceFilePath($asset);
             if ($placeholder) {
                 list($width, $height) = getimagesize($asset->getSourceFile());
                 $icons[$code] = ['url' => $asset->getUrl(), 'width' => $width, 'height' => $height];
             }
         }
     }
     return $icons;
 }
Ejemplo n.º 7
0
 /**
  * @expectedException \Magento\Framework\View\Asset\File\NotFoundException
  * @expectedExceptionMessage Unable to get content for 'Magento_Module/dir/file.css'
  */
 public function testGetContentNotFound()
 {
     $this->source->expects($this->once())
         ->method('getContent')
         ->with($this->object)
         ->will($this->returnValue(false));
     $this->object->getContent();
 }
Ejemplo n.º 8
0
 public function testCreateAsset()
 {
     $this->mockDesign();
     $this->baseUrl->expects($this->once())->method('getBaseUrl')->will($this->returnValue('http://example.com/static/'));
     $asset = $this->object->createAsset('test/file.js');
     $this->assertInstanceOf('\\Magento\\Framework\\View\\Asset\\File', $asset);
     $this->assertEquals('area/theme/locale/test/file.js', $asset->getPath());
     $this->assertEquals('test/file.js', $asset->getFilePath());
     $this->assertEquals('js', $asset->getContentType());
     $this->assertInstanceOf('\\Magento\\Framework\\View\\Asset\\File\\FallbackContext', $asset->getContext());
     $this->assertEquals('', $asset->getModule());
     $this->assertEquals('http://example.com/static/area/theme/locale/test/file.js', $asset->getUrl());
     $this->source->expects($this->once())->method('getFile')->with($asset)->will($this->returnValue('source'));
     $this->source->expects($this->once())->method('getContent')->with($asset)->will($this->returnValue('content'));
     $this->assertEquals('source', $asset->getSourceFile());
     $this->assertEquals('content', $asset->getContent());
     $anotherAsset = $this->object->createAsset('another/file.id');
     $this->assertSame($anotherAsset->getContext(), $asset->getContext());
 }
 /**
  * Preparation of content for the destination file
  *
  * @param string $path
  * @param string $content
  * @param string $module
  * @param FallbackContext $context
  * @return string
  */
 private function processContent($path, $content, $module, FallbackContext $context)
 {
     foreach ($this->alternativeSource->getAlternativesExtensionsNames() as $name) {
         $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();
         $processedContent = $this->assetSource->getContent($asset);
         if (trim($processedContent) !== '') {
             return $processedContent;
         }
     }
     return $content;
 }
Ejemplo n.º 10
0
 /**
  * Test for processContent method (not empty content)
  */
 public function testProcessContentNotEmpty()
 {
     $assetMock = $this->getAssetMock();
     $this->appStateMock->expects(self::once())->method('getMode')->willReturn(State::MODE_DEVELOPER);
     $this->assetSourceMock->expects(self::once())->method('getContent')->with($assetMock)->willReturn(self::TEST_CONTENT);
     $this->temporaryFileMock->expects(self::once())->method('createFile')->with(self::ASSET_PATH, self::TEST_CONTENT)->willReturn(__DIR__ . '/' . self::TMP_PATH_LESS);
     $assetMock->expects(self::once())->method('getPath')->willReturn(self::ASSET_PATH);
     $this->loggerMock->expects(self::never())->method('critical');
     $clearSymbol = ["\n", "\r", "\t", ' '];
     self::assertEquals(trim(str_replace($clearSymbol, '', file_get_contents(__DIR__ . '/' . self::TMP_PATH_CSS))), trim(str_replace($clearSymbol, '', $this->processor->processContent($assetMock))));
 }
Ejemplo n.º 11
0
 /**
  * Get image URL of WYSIWYG placeholder image
  *
  * @param string $type
  * @return string
  */
 public function getPlaceholderImageUrl($type)
 {
     $placeholder = false;
     $widget = $this->getWidgetByClassType($type);
     if (is_array($widget) && isset($widget['placeholder_image'])) {
         $placeholder = (string) $widget['placeholder_image'];
     }
     if ($placeholder) {
         $asset = $this->assetRepo->createAsset($placeholder);
         $placeholder = $this->assetSource->getFile($asset);
         if ($placeholder) {
             return $asset->getUrl();
         }
     }
     return $this->assetRepo->getUrl('Magento_Widget::placeholder.gif');
 }
Ejemplo n.º 12
0
 /**
  * Run test for process method
  */
 public function testProcess()
 {
     $this->lockerProcessMock->expects(self::once())->method('lockProcess')->with(self::isType('string'));
     $this->lockerProcessMock->expects(self::once())->method('unlockProcess');
     $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->alternativeSourceMock->expects(self::once())->method('getAlternativesExtensionsNames')->willReturn(['less']);
     $this->assetSourceMock->expects(self::once())->method('getContent')->with($assetMock)->willReturn(self::NEW_CONTENT);
     $frontendCompilation = new FrontendCompilation($this->assetSourceMock, $this->assetBuilderMock, $this->alternativeSourceMock, $this->lockerProcessMock, 'lock');
     $frontendCompilation->process($this->getChainMockExpects());
 }
Ejemplo n.º 13
0
 /**
  * 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;
 }
Ejemplo n.º 14
0
 /**
  * Create a file asset with an arbitrary path
  *
  * This kind of file is not subject of fallback system
  * Client code is responsible for ensuring that the file is in specified directory
  *
  * @param string $filePath
  * @param string $dirPath
  * @param string $baseDirType
  * @param string $baseUrlType
  * @return File
  */
 public function createArbitrary($filePath, $dirPath, $baseDirType = Filesystem::STATIC_VIEW_DIR, $baseUrlType = UrlInterface::URL_TYPE_STATIC)
 {
     $context = $this->getFileContext($baseDirType, $baseUrlType, $dirPath);
     $contentType = $this->assetSource->getContentType($filePath);
     return new File($this->assetSource, $context, $filePath, '', $contentType);
 }
Ejemplo n.º 15
0
 /**
  * Create a file asset with an arbitrary path
  *
  * This kind of file is not subject of fallback system
  * Client code is responsible for ensuring that the file is in specified directory
  *
  * @param string $filePath
  * @param string $dirPath
  * @param string $baseDirType
  * @param string $baseUrlType
  * @return File
  */
 public function createArbitrary($filePath, $dirPath, $baseDirType = DirectoryList::STATIC_VIEW, $baseUrlType = UrlInterface::URL_TYPE_STATIC)
 {
     $context = $this->getFileContext($baseDirType, $baseUrlType, $dirPath);
     $contentType = $this->assetSource->getContentType($filePath);
     return $this->fileFactory->create(['source' => $this->assetSource, 'context' => $context, 'filePath' => $filePath, 'module' => '', 'contentType' => $contentType]);
 }
Ejemplo n.º 16
0
 /**
  * @param string $path
  * @param string $expected
  * @dataProvider getContentTypeDataProvider
  */
 public function testGetContentType($path, $expected)
 {
     $this->assertEquals($expected, $this->object->getContentType($path));
 }
Ejemplo n.º 17
0
 /**
  * @param $customerId
  * @param $storeId
  * @param $grandTotal
  * @param $recurringType
  * @return array
  */
 public function getOneClickPaymentMethods($customerId, $storeId, $grandTotal, $recurringType)
 {
     $billingAgreements = [];
     $baCollection = $this->_billingAgreementCollectionFactory->create();
     $baCollection->addFieldToFilter('customer_id', $customerId);
     $baCollection->addFieldToFilter('store_id', $storeId);
     $baCollection->addFieldToFilter('method_code', 'adyen_oneclick');
     $baCollection->addActiveFilter();
     foreach ($baCollection as $billingAgreement) {
         $agreementData = $billingAgreement->getAgreementData();
         // no agreementData and contractType then ignore
         if (!is_array($agreementData) || !isset($agreementData['contractTypes'])) {
             continue;
         }
         // check if contractType is supporting the selected contractType for OneClick payments
         $allowedContractTypes = $agreementData['contractTypes'];
         if (in_array($recurringType, $allowedContractTypes)) {
             // check if AgreementLabel is set and if contract has an recurringType
             if ($billingAgreement->getAgreementLabel()) {
                 // for Ideal use sepadirectdebit because it is
                 if ($agreementData['variant'] == 'ideal') {
                     $agreementData['variant'] = 'sepadirectdebit';
                 }
                 $data = ['reference_id' => $billingAgreement->getReferenceId(), 'agreement_label' => $billingAgreement->getAgreementLabel(), 'agreement_data' => $agreementData];
                 if ($this->showLogos()) {
                     $logoName = $agreementData['variant'];
                     $asset = $this->createAsset('Adyen_Payment::images/logos/' . $logoName . '.png');
                     $icon = null;
                     $placeholder = $this->_assetSource->findSource($asset);
                     if ($placeholder) {
                         list($width, $height) = getimagesize($asset->getSourceFile());
                         $icon = ['url' => $asset->getUrl(), 'width' => $width, 'height' => $height];
                     }
                     $data['logo'] = $icon;
                 }
                 /**
                  * Check if there are installments for this creditcard type defined
                  */
                 $data['number_of_installments'] = 0;
                 $ccType = $this->getMagentoCreditCartType($agreementData['variant']);
                 $installments = null;
                 $installmentsValue = $this->getAdyenCcConfigData('installments');
                 if ($installmentsValue) {
                     $installments = unserialize($installmentsValue);
                 }
                 if ($installments) {
                     $numberOfInstallments = null;
                     foreach ($installments as $ccTypeInstallment => $installment) {
                         if ($ccTypeInstallment == $ccType) {
                             foreach ($installment as $amount => $installments) {
                                 if ($grandTotal <= $amount) {
                                     $numberOfInstallments = $installments;
                                 }
                             }
                         }
                     }
                     if ($numberOfInstallments) {
                         $data['number_of_installments'] = $numberOfInstallments;
                     }
                 }
                 $billingAgreements[] = $data;
             }
         }
     }
     return $billingAgreements;
 }