/** * @param Context $context * @param StoreManagerInterface $storeManager * @param Filesystem $filesystem * @param string $imageDir */ public function __construct(Context $context, StoreManagerInterface $storeManager, Filesystem $filesystem, $imageDir = 'design/image') { parent::__construct($context); $this->storeManager = $storeManager; $this->mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA); $this->imageDir = $imageDir; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $this->updateMemoryLimit(); $sampleDataPackages = $this->sampleDataDependency->getSampleDataPackages(); if (!empty($sampleDataPackages)) { $baseDir = $this->filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath(); $commonArgs = ['--working-dir' => $baseDir, '--no-progress' => 1]; $packages = []; foreach ($sampleDataPackages as $name => $version) { $packages[] = "{$name}:{$version}"; } $commonArgs = array_merge(['packages' => $packages], $commonArgs); $arguments = array_merge(['command' => 'require'], $commonArgs); /** @var ArrayInput $commandInput */ $commandInput = $this->arrayInputFactory->create(['parameters' => $arguments]); /** @var Application $application */ $application = $this->applicationFactory->create(); $application->setAutoExit(false); $result = $application->run($commandInput, $output); if ($result !== 0) { $output->writeln('<info>' . 'There is an error during sample data deployment.' . '</info>'); } } else { $output->writeln('<info>' . 'There is no sample data for current set of modules.' . '</info>'); } }
/** * Constructor * * @param MagentoComposerApplicationFactory $applicationFactory * @param \Magento\Framework\Filesystem $filesystem * @param ComposerInformation $composerInformation * @param ObjectManagerProvider $objectManagerProvider * @throws \Exception */ public function __construct(MagentoComposerApplicationFactory $applicationFactory, Filesystem $filesystem, ComposerInformation $composerInformation, ObjectManagerProvider $objectManagerProvider) { $this->application = $applicationFactory->create(); $this->directory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR); $this->objectManager = $objectManagerProvider->get(); $this->composerInformation = $composerInformation; }
/** * Constructor * @param Filesystem $filesystem * @param string $logFile */ public function __construct(Filesystem $filesystem, $logFile = null) { $this->directory = $filesystem->getDirectoryWrite(DirectoryList::LOG); if ($logFile) { $this->logFile = $logFile; } }
/** * Constructor * * @param \Magento\Framework\Filesystem $filesystem * @param ComponentRegistrarInterface $componentRegistrar * @param string $filename */ public function __construct(\Magento\Framework\Filesystem $filesystem, ComponentRegistrarInterface $componentRegistrar, $filename = \Magento\Framework\View\ConfigInterface::CONFIG_FILE_NAME) { $this->filesystem = $filesystem; $this->filename = $filename; $this->mediaDirectoryRead = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA); $this->componentRegistrar = $componentRegistrar; }
protected function setUp() { $this->requestMock = $this->getMock( '\Magento\Framework\App\Request\Http', ['getBasePath', 'isSecure', 'getHttpHost'], [], '', false, false ); $this->requestMock->expects($this->atLeastOnce())->method('getBasePath')->will($this->returnValue('/')); $this->requestMock->expects($this->atLeastOnce()) ->method('getHttpHost') ->will($this->returnValue('init.host')); $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->validatorFactory = $this->getMockBuilder('Magento\Framework\ValidatorFactory') ->disableOriginalConstructor() ->getMock(); $backendUrl = $this->getMock('\Magento\Backend\Model\Url', [], [], '', false); $backendUrl->expects($this->once())->method('getBaseUrl')->will($this->returnValue('/')); $this->backendUrlFactory = $this->getMock('Magento\Backend\Model\UrlFactory', ['create'], [], '', false); $this->backendUrlFactory->expects($this->any())->method('create')->willReturn($backendUrl); $this->filesystemMock = $this->getMock('\Magento\Framework\Filesystem', [], [], '', false); $dirMock = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\WriteInterface'); $this->filesystemMock->expects($this->any()) ->method('getDirectoryWrite') ->will($this->returnValue($dirMock)); }
/** * @param \Magento\Backend\Block\Context $context * @param \Magento\Framework\Filesystem $filesystem * @param \Magento\Framework\Filesystem\Directory\ReadFactory $directoryRead * @param \Magento\Framework\Stdlib\DateTime\DateTime $coreDate * @param array $data */ public function __construct(\Magento\Backend\Block\Context $context, \Magento\Framework\Filesystem $filesystem, \Magento\Framework\Filesystem\Directory\ReadFactory $directoryRead, \Magento\Framework\Stdlib\DateTime\DateTime $coreDate, array $data = []) { parent::__construct($context, $data); $this->_ioRead = $filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::ROOT); $this->_coreDate = $coreDate; $this->_directoryRead = $directoryRead->create(""); }
/** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry * @param \Magento\Tax\Helper\Data $taxData * @param \Magento\Framework\Filesystem $filesystem , * @param \Magento\Framework\Filter\FilterManager $filterManager * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data */ public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Tax\Helper\Data $taxData, \Magento\Framework\Filesystem $filesystem, \Magento\Framework\Filter\FilterManager $filterManager, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = []) { $this->filterManager = $filterManager; $this->_taxData = $taxData; $this->_rootDirectory = $filesystem->getDirectoryRead(DirectoryList::ROOT); parent::__construct($context, $registry, $resource, $resourceCollection, $data); }
/** * Check JSON file created by Setup cron command and Updater cron script * * @param string $type * @return array */ private function checkJson($type) { $read = $this->filesystem->getDirectoryRead(DirectoryList::VAR_DIR); try { switch ($type) { case self::SETUP: $key = ReadinessCheck::KEY_DB_WRITE_PERMISSION_VERIFIED; $jsonData = json_decode($read->readFile(ReadinessCheck::SETUP_CRON_JOB_STATUS_FILE), true); break; case self::UPDATER: $key = self::UPDATER_KEY_FILE_PERMISSIONS_VERIFIED; $jsonData = json_decode($read->readFile(self::UPDATER_CRON_JOB_STATS_FILE), true); break; default: return ['success' => false, 'error' => 'Internal Error']; } } catch (\Magento\Framework\Exception\FileSystemException $e) { $error = 'Cron job has not been configured yet'; if ($type == self::SETUP) { $error .= self::OTHER_CHECKS_WILL_FAIL_MSG; } return ['success' => false, 'error' => $error]; } if (isset($jsonData[ReadinessCheck::KEY_READINESS_CHECKS]) && isset($jsonData[ReadinessCheck::KEY_READINESS_CHECKS][$key])) { if ($jsonData[ReadinessCheck::KEY_READINESS_CHECKS][$key]) { return $this->checkCronTime($jsonData); } return ['success' => false, 'error' => $jsonData[ReadinessCheck::KEY_READINESS_CHECKS]['error']]; } $error = 'Cron job has not been configured yet'; if ($type == self::SETUP) { $error .= self::OTHER_CHECKS_WILL_FAIL_MSG; } return ['success' => false, 'error' => $error]; }
/** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Framework\Filesystem $filesystem * @param \Magento\Framework\Image\Factory $imageFactory * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data * @SuppressWarnings(PHPMD.ExcessiveParameterList) * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ public function __construct(\Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Filesystem $filesystem, \Magento\Framework\Image\Factory $imageFactory, \Magento\Framework\ObjectManagerInterface $objectManager, array $data = []) { $this->_mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA); $this->_imageFactory = $imageFactory; $this->_storeManager = $storeManager; $this->_objectManager = $objectManager; }
public function setUp() { $this->filesystem = $this->getMock('Magento\\Framework\\Filesystem', [], [], '', false); $this->varReaderWriter = $this->getMockForAbstractClass('Magento\\Framework\\Filesystem\\Directory\\WriteInterface', [], '', false); $this->filesystem->expects($this->once())->method('getDirectoryWrite')->will($this->returnValue($this->varReaderWriter)); $this->status = new Status($this->filesystem); }
/** * @param Dir $moduleDirs * @param ModuleListInterface $moduleList * @param Filesystem $filesystem * @param FileIteratorFactory $fileIteratorFactory */ public function __construct(Dir $moduleDirs, ModuleListInterface $moduleList, Filesystem $filesystem, FileIteratorFactory $fileIteratorFactory) { $this->moduleDirs = $moduleDirs; $this->modulesList = $moduleList; $this->fileIteratorFactory = $fileIteratorFactory; $this->modulesDirectory = $filesystem->getDirectoryRead(DirectoryList::MODULES); }
/** * @param State $appState * @param Config $config * @param Filesystem $filesystem * @param Files $filesUtility */ public function __construct(State $appState, Config $config, Filesystem $filesystem, Files $filesUtility = null) { $this->appState = $appState; $this->config = $config; $this->rootDirectory = $filesystem->getDirectoryRead(DirectoryList::ROOT); $this->filesUtility = null !== $filesUtility ? $filesUtility : new Files(BP); }
/** * Save uploaded file and set its name to category * * @param \Magento\Framework\DataObject $object * @return \Magento\Catalog\Model\Category\Attribute\Backend\Image */ public function afterSave($object) { $value = $object->getData($this->getAttribute()->getName() . '_additional_data'); // if no image was set - nothing to do if (empty($value) && empty($_FILES)) { return $this; } if (is_array($value) && !empty($value['delete'])) { $object->setData($this->getAttribute()->getName(), ''); $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName()); return $this; } $path = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath('catalog/category/'); try { /** @var $uploader \Magento\MediaStorage\Model\File\Uploader */ $uploader = $this->_fileUploaderFactory->create(['fileId' => $this->getAttribute()->getName()]); $uploader->setAllowedExtensions(['jpg', 'jpeg', 'gif', 'png']); $uploader->setAllowRenameFiles(true); $result = $uploader->save($path); $object->setData($this->getAttribute()->getName(), $result['file']); $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName()); } catch (\Exception $e) { if ($e->getCode() != \Magento\MediaStorage\Model\File\Uploader::TMP_NAME_EMPTY) { $this->_logger->critical($e); } } return $this; }
/** * @covers \Magento\Shipping\Model\Shipping\LabelGenerator * @param array $info * @dataProvider labelInfoDataProvider */ public function testAddTrackingNumbersToShipment(array $info) { $order = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock(); $order->expects(static::once())->method('getShippingMethod')->with(true)->willReturn($this->getShippingMethodMock()); /** * @var $shipmentMock \Magento\Sales\Model\Order\Shipment|\PHPUnit_Framework_MockObject_MockObject */ $shipmentMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Shipment')->disableOriginalConstructor()->getMock(); $shipmentMock->expects(static::once())->method('getOrder')->willReturn($order); $this->carrierFactory->expects(static::once())->method('create')->with(self::CARRIER_CODE)->willReturn($this->getCarrierMock()); $labelsMock = $this->getMockBuilder('\\Magento\\Shipping\\Model\\Shipping\\Labels')->disableOriginalConstructor()->getMock(); $labelsMock->expects(static::once())->method('requestToShipment')->with($shipmentMock)->willReturn($this->getResponseMock($info)); $this->labelsFactory->expects(static::once())->method('create')->willReturn($labelsMock); $this->filesystem->expects(static::once())->method('getDirectoryWrite')->willReturn($this->getMock('Magento\\Framework\\Filesystem\\Directory\\WriteInterface')); $this->scopeConfig->expects(static::once())->method('getValue')->with('carriers/' . self::CARRIER_CODE . '/title', ScopeInterface::SCOPE_STORE, null)->willReturn(self::CARRIER_TITLE); $this->labelsFactory->expects(static::once())->method('create')->willReturn($labelsMock); $trackMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Shipment\\Track')->setMethods(['setNumber', 'setCarrierCode', 'setTitle'])->disableOriginalConstructor()->getMock(); $i = 0; $trackingNumbers = is_array($info['tracking_number']) ? $info['tracking_number'] : [$info['tracking_number']]; foreach ($trackingNumbers as $trackingNumber) { $trackMock->expects(static::at($i++))->method('setNumber')->with($trackingNumber)->willReturnSelf(); $trackMock->expects(static::at($i++))->method('setCarrierCode')->with(self::CARRIER_CODE)->willReturnSelf(); $trackMock->expects(static::at($i++))->method('setTitle')->with(self::CARRIER_TITLE)->willReturnSelf(); } $this->trackFactory->expects(static::any())->method('create')->willReturn($trackMock); /** * @var $requestMock \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */ $requestMock = $this->getMock('Magento\\Framework\\App\\RequestInterface'); $this->labelGenerator->create($shipmentMock, $requestMock); }
public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Filesystem $filesystem, \Magento\Framework\Filesystem\File\ReadFactory $readFactory) { $this->_scopeConfig = $scopeConfig; $this->_filesystem = $filesystem; $this->_directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT); $this->_readFactory = $readFactory; }
/** * After save * * @param \Magento\Framework\DataObject $object * @return $this|void */ public function afterSave($object) { $value = $object->getData($this->getAttribute()->getName()); if (is_array($value) && !empty($value['delete'])) { $object->setData($this->getAttribute()->getName(), ''); $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName()); return; } try { /** @var $uploader \Magento\MediaStorage\Model\File\Uploader */ $uploader = $this->_fileUploaderFactory->create(['fileId' => $this->getAttribute()->getName()]); $uploader->setAllowedExtensions(['jpg', 'jpeg', 'gif', 'png']); $uploader->setAllowRenameFiles(true); $uploader->setFilesDispersion(true); } catch (\Exception $e) { return $this; } $path = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath('catalog/product/'); $uploader->save($path); $fileName = $uploader->getUploadedFileName(); if ($fileName) { $object->setData($this->getAttribute()->getName(), $fileName); $this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName()); } return $this; }
public function testToHtml() { $fieldSet = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\Fieldset', [], [], '', false); $form = $this->getMock('Magento\\Framework\\Data\\Form', [], [], '', false); $attributeModel = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', [], [], '', false); $entityType = $this->getMock('Magento\\Eav\\Model\\Entity\\Type', [], [], '', false); $formElement = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\Text', ['setDisabled'], [], '', false); $directoryReadInterface = $this->getMock('\\Magento\\Framework\\Filesystem\\Directory\\ReadInterface'); $this->registry->expects($this->any())->method('registry')->with('entity_attribute')->willReturn($attributeModel); $this->formFactory->expects($this->any())->method('create')->willReturn($form); $form->expects($this->any())->method('addFieldset')->willReturn($fieldSet); $form->expects($this->any())->method('getElement')->willReturn($formElement); $fieldSet->expects($this->any())->method('addField')->willReturnSelf(); $attributeModel->expects($this->any())->method('getDefaultValue')->willReturn('default_value'); $attributeModel->expects($this->any())->method('setDisabled')->willReturnSelf(); $attributeModel->expects($this->any())->method('getId')->willReturn(1); $attributeModel->expects($this->any())->method('getEntityType')->willReturn($entityType); $attributeModel->expects($this->any())->method('getIsUserDefined')->willReturn(false); $attributeModel->expects($this->any())->method('getAttributeCode')->willReturn('attribute_code'); $this->localeDate->expects($this->any())->method('getDateFormat')->willReturn('mm/dd/yy'); $entityType->expects($this->any())->method('getEntityTypeCode')->willReturn('entity_type_code'); $this->eavData->expects($this->any())->method('getFrontendClasses')->willReturn([]); $formElement->expects($this->exactly(3))->method('setDisabled')->willReturnSelf(); $this->yesNo->expects($this->any())->method('toOptionArray')->willReturn(['yes', 'no']); $this->filesystem->expects($this->any())->method('getDirectoryRead')->willReturn($directoryReadInterface); $directoryReadInterface->expects($this->any())->method('getRelativePath')->willReturn('relative_path'); $this->block->setData(['action' => 'save']); $this->block->toHtml(); }
/** * Constructor * * @param MagentoComposerApplicationFactory $applicationFactory * @param \Magento\Framework\Filesystem $filesystem * @param \Magento\Framework\Stdlib\DateTime $dateTime * @param ComposerInformation $composerInformation * @throws \Exception */ public function __construct(MagentoComposerApplicationFactory $applicationFactory, Filesystem $filesystem, DateTime $dateTime, ComposerInformation $composerInformation) { $this->application = $applicationFactory->create(); $this->directory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR); $this->dateTime = $dateTime; $this->composerInformation = $composerInformation; }
public function setUp() { $this->directoryReadMock = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\Read', [], [], '', false); $this->filesystemMock = $this->getMock('Magento\\Framework\\Filesystem', [], [], '', false); $this->filesystemMock->expects($this->any())->method('getDirectoryRead')->will($this->returnValue($this->directoryReadMock)); $this->ioMock = $this->getMock('Composer\\IO\\BufferIO', [], [], '', false); }
/** * @magentoAppArea adminhtml * @magentoDbIsolation enabled * @magentoAppIsolation enabled * @magentoDataFixture Magento/Catalog/_files/product_simple.php */ public function testExport() { $productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class); $index = 0; $ids = []; $origPricingData = []; while (isset($skus[$index])) { $ids[$index] = $productRepository->get($skus[$index])->getId(); $origPricingData[$index] = $this->objectManager->create(\Magento\Catalog\Model\Product::class)->load($ids[$index])->getTierPrices(); $index++; } $csvfile = uniqid('importexport_') . '.csv'; $this->model->setWriter(\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\ImportExport\Model\Export\Adapter\Csv::class, ['fileSystem' => $this->fileSystem, 'destination' => $csvfile])); $this->assertNotEmpty($this->model->export()); /** @var \Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing $importModel */ $importModel = $this->objectManager->create(\Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing::class); $directory = $this->fileSystem->getDirectoryWrite(DirectoryList::VAR_DIR); $source = $this->objectManager->create(\Magento\ImportExport\Model\Import\Source\Csv::class, ['file' => $csvfile, 'directory' => $directory]); $errors = $importModel->setParameters(['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND, 'entity' => 'advanced_pricing'])->setSource($source)->validateData(); $this->assertTrue($errors->getErrorsCount() == 0, 'Advanced Pricing import error, imported from file:' . $csvfile); $importModel->importData(); while ($index > 0) { $index--; $newPricingData = $this->objectManager->create(\Magento\Catalog\Model\Product::class)->load($ids[$index])->getTierPrices(); $this->assertEquals(count($origPricingData[$index]), count($newPricingData)); $this->assertEqualsOtherThanSkippedAttributes($origPricingData[$index], $newPricingData, []); } }
public function setUp() { $this->filesystem = $this->getMock('Magento\\Framework\\Filesystem', [], [], '', false); $this->directoryRead = $this->getMockForAbstractClass('Magento\\Framework\\Filesystem\\Directory\\ReadInterface', [], '', false); $this->filesystem->expects($this->once())->method('getDirectoryRead')->willReturn($this->directoryRead); $this->reader = new Reader($this->filesystem); }
/** * Image upload action in iframe * * @return string */ public function execute() { try { $uploader = $this->uploaderFactory->create(['fileId' => 'datafile']); $uploader->setAllowedExtensions(['jpg', 'jpeg', 'gif', 'png']); /** @var \Magento\Framework\Image\Adapter\AdapterInterface $imageAdapter */ $imageAdapter = $this->adapterFactory->create(); $uploader->addValidateCallback('catalog_product_image', $imageAdapter, 'validateUploadFile'); $uploader->setAllowRenameFiles(true); $uploader->setFilesDispersion(true); /** @var \Magento\Framework\Filesystem\Directory\Read $mediaDirectory */ $mediaDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA); $config = $this->config; $result = $uploader->save($mediaDirectory->getAbsolutePath($config->getBaseTmpMediaPath())); $this->_eventManager->dispatch('swatch_gallery_upload_image_after', ['result' => $result, 'action' => $this]); unset($result['tmp_name']); unset($result['path']); $result['url'] = $this->config->getTmpMediaUrl($result['file']); $result['file'] = $result['file'] . '.tmp'; $newFile = $this->swatchHelper->moveImageFromTmp($result['file']); $this->swatchHelper->generateSwatchVariations($newFile); $fileData = ['swatch_path' => $this->swatchHelper->getSwatchMediaUrl(), 'file_path' => $newFile]; $this->getResponse()->setBody(json_encode($fileData)); } catch (\Exception $e) { $result = ['error' => $e->getMessage(), 'errorcode' => $e->getCode()]; $this->getResponse()->setBody(json_encode($result)); } }
/** * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate * @param \Psr\Log\LoggerInterface $logger * @param \Magento\Framework\Locale\ResolverInterface $localeResolver * @param \Magento\Framework\Url\EncoderInterface $urlEncoder * @param \Magento\MediaStorage\Model\File\Validator\NotProtectedExtension $fileValidator * @param \Magento\Framework\Filesystem $filesystem * @codeCoverageIgnore */ public function __construct(\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Locale\ResolverInterface $localeResolver, \Magento\Framework\Url\EncoderInterface $urlEncoder, \Magento\MediaStorage\Model\File\Validator\NotProtectedExtension $fileValidator, \Magento\Framework\Filesystem $filesystem) { parent::__construct($localeDate, $logger, $localeResolver); $this->urlEncoder = $urlEncoder; $this->_fileValidator = $fileValidator; $this->_directory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA); }
/** * @param \Magento\Framework\RequireJs\Config\File\Collector\Aggregated $fileSource * @param \Magento\Framework\View\DesignInterface $design * @param \Magento\Framework\Filesystem $appFilesystem * @param \Magento\Framework\View\Asset\Repository $assetRepo */ public function __construct(\Magento\Framework\RequireJs\Config\File\Collector\Aggregated $fileSource, \Magento\Framework\View\DesignInterface $design, \Magento\Framework\Filesystem $appFilesystem, \Magento\Framework\View\Asset\Repository $assetRepo) { $this->fileSource = $fileSource; $this->design = $design; $this->baseDir = $appFilesystem->getDirectoryRead(DirectoryList::ROOT); $this->staticContext = $assetRepo->getStaticViewFileContext(); }
/** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry * @param \Magento\Framework\Filesystem $filesystem * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Framework\Model\Resource\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data */ public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Filesystem $filesystem, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Model\Resource\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = []) { $this->_tmpDirectory = $filesystem->getDirectoryWrite(DirectoryList::SYS_TMP); $this->_storeManager = $storeManager; $this->_scopeConfig = $scopeConfig; parent::__construct($context, $registry, $resource, $resourceCollection, $data); }
/** * Validate image size. * * @param $filePath * * @throws LocalizedException */ public function sizeValidate($filePath) { $directory = $this->_filesystem->getDirectoryRead(DirectoryList::SYS_TMP); if ($this->_maxSize > 0 && $directory->stat($directory->getRelativePath($filePath))['size'] > $this->_maxSize * 1024) { throw new LocalizedException(__('The file you\'re uploading exceeds the server size limit of %1 kilobytes.', $this->_maxSize)); } }
/** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry * @param \Magento\Framework\App\Config\ScopeConfigInterface $config * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList * @param \Magento\Paypal\Model\CertFactory $certFactory * @param \Magento\Framework\Encryption\EncryptorInterface $encryptor * @param \Magento\Framework\Filesystem $filesystem * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data */ public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, \Magento\Paypal\Model\CertFactory $certFactory, \Magento\Framework\Encryption\EncryptorInterface $encryptor, \Magento\Framework\Filesystem $filesystem, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = []) { $this->_certFactory = $certFactory; $this->_encryptor = $encryptor; $this->_tmpDirectory = $filesystem->getDirectoryRead(DirectoryList::SYS_TMP); parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data); }
/** * @param Filesystem $filesystem * @param Filter $filter * @param MetadataProvider $metadataProvider * @param int $pageSize */ public function __construct(Filesystem $filesystem, Filter $filter, MetadataProvider $metadataProvider, $pageSize = 200) { $this->filter = $filter; $this->directory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR); $this->metadataProvider = $metadataProvider; $this->pageSize = $pageSize; }
public function setup() { $this->filesystemMock = $this->getMockBuilder('Magento\Framework\Filesystem') ->disableOriginalConstructor() ->getMock(); $this->directoryMock = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\ReadInterface') ->getMock(); $this->fileFactoryMock = $this->getMockBuilder('Magento\Framework\View\File\Factory') ->disableOriginalConstructor() ->getMock(); $this->themeMock = $this->getMockBuilder('Magento\Framework\View\Design\ThemeInterface') ->getMock(); $this->filesystemMock->expects($this->any()) ->method('getDirectoryRead') ->willReturn($this->directoryMock); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->themeFileCollector = $this->objectManagerHelper->getObject( 'Magento\Framework\View\File\Collector\Theme', [ 'filesystem' => $this->filesystemMock, 'fileFactory' => $this->fileFactoryMock ] ); }