public function testGetConfig() { $this->baseDir->expects($this->any())->method('getRelativePath')->will($this->returnCallback(function ($path) { return 'relative/' . $path; })); $this->baseDir->expects($this->any())->method('readFile')->will($this->returnCallback(function ($file) { return $file . ' content'; })); $fileOne = $this->getMock('\\Magento\\Framework\\View\\File', [], [], '', false); $fileOne->expects($this->once())->method('getFilename')->will($this->returnValue('file_one.js')); $fileOne->expects($this->once())->method('getModule')->will($this->returnValue('Module_One')); $fileTwo = $this->getMock('\\Magento\\Framework\\View\\File', [], [], '', false); $fileTwo->expects($this->once())->method('getFilename')->will($this->returnValue('file_two.js')); $theme = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\Design\\ThemeInterface'); $this->design->expects($this->once())->method('getDesignTheme')->will($this->returnValue($theme)); $this->fileSource->expects($this->once())->method('getFiles')->with($theme, Config::CONFIG_FILE_NAME)->will($this->returnValue([$fileOne, $fileTwo])); $expected = <<<expected (function(require){ require.config({"baseUrl":""}); (function() { relative/file_one.js content require.config(config); })(); (function() { relative/file_two.js content require.config(config); })(); })(require); expected; $actual = $this->object->getConfig(); $this->assertStringMatchesFormat($expected, $actual); }
/** * @test * @return void */ public function testLoadData() { $fileContent = 'content file'; $media = ['preview_image' => 'preview.jpg']; $themeTitle = 'Theme title'; $themeConfigFile = 'theme.xml'; $themeConfig = $this->getMockBuilder('Magento\\Framework\\Config\\Theme')->disableOriginalConstructor()->getMock(); $theme = $this->getMockBuilder('Magento\\Theme\\Model\\Theme')->disableOriginalConstructor()->getMock(); $parentTheme = ['parentThemeCode']; $parentThemePath = 'frontend/parent/theme'; $themePackage = $this->getMock('\\Magento\\Framework\\View\\Design\\Theme\\ThemePackage', [], [], '', false); $themePackage->expects($this->any())->method('getArea')->will($this->returnValue('frontend')); $themePackage->expects($this->any())->method('getVendor')->will($this->returnValue('theme')); $themePackage->expects($this->any())->method('getName')->will($this->returnValue('code')); $this->themePackageList->expects($this->once())->method('getThemes')->will($this->returnValue([$themePackage])); $this->directory->expects($this->once())->method('isExist')->with($themeConfigFile)->willReturn(true); $this->directory->expects($this->once())->method('readFile')->with($themeConfigFile)->willReturn($fileContent); $this->themeConfigFactory->expects($this->once())->method('create')->with(['configContent' => $fileContent])->willReturn($themeConfig); $this->entityFactory->expects($this->any())->method('create')->with('Magento\\Theme\\Model\\Theme')->willReturn($theme); $themeConfig->expects($this->once())->method('getMedia')->willReturn($media); $themeConfig->expects($this->once())->method('getParentTheme')->willReturn($parentTheme); $themeConfig->expects($this->once())->method('getThemeTitle')->willReturn($themeTitle); $theme->expects($this->once())->method('addData')->with(['parent_id' => null, 'type' => ThemeInterface::TYPE_PHYSICAL, 'area' => 'frontend', 'theme_path' => 'theme/code', 'code' => 'theme/code', 'theme_title' => $themeTitle, 'preview_image' => $media['preview_image'], 'parent_theme_path' => 'theme/parentThemeCode'])->willReturnSelf(); $theme->expects($this->once())->method('getData')->with('parent_theme_path')->willReturn($parentThemePath); $theme->expects($this->once())->method('getArea')->willReturn('frontend'); $this->assertInstanceOf(get_class($this->model), $this->model->loadData()); }
/** * @param string $area * @param bool $forceReload * @param array $cachedData * @dataProvider dataProviderForTestLoadData * @SuppressWarnings(PHPMD.NPathComplexity) */ public function testLoadData($area, $forceReload, $cachedData) { $this->expectsSetConfig('themeId'); $this->cache->expects($this->exactly($forceReload ? 0 : 1))->method('load')->will($this->returnValue(serialize($cachedData))); if (!$forceReload && $cachedData !== false) { $this->translate->loadData($area, $forceReload); $this->assertEquals($cachedData, $this->translate->getData()); return; } $this->directory->expects($this->any())->method('isExist')->will($this->returnValue(true)); // _loadModuleTranslation() $this->moduleList->expects($this->once())->method('getNames')->will($this->returnValue(['name'])); $moduleData = ['module original' => 'module translated', 'module theme' => 'module-theme original translated', 'module pack' => 'module-pack original translated', 'module db' => 'module-db original translated']; $this->modulesReader->expects($this->any())->method('getModuleDir')->will($this->returnValue('/app/module')); $themeData = ['theme original' => 'theme translated', 'module theme' => 'theme translated overwrite', 'module pack' => 'theme-pack translated overwrite', 'module db' => 'theme-db translated overwrite']; $this->csvParser->expects($this->any())->method('getDataPairs')->will($this->returnValueMap([['/app/module/en_US.csv', 0, 1, $moduleData], ['/app/module/en_GB.csv', 0, 1, $moduleData], ['/theme.csv', 0, 1, $themeData]])); // _loadThemeTranslation() $this->viewFileSystem->expects($this->any())->method('getLocaleFileName')->will($this->returnValue('/theme.csv')); // _loadPackTranslation $packData = ['pack original' => 'pack translated', 'module pack' => 'pack translated overwrite', 'module db' => 'pack-db translated overwrite']; $this->packDictionary->expects($this->once())->method('getDictionary')->will($this->returnValue($packData)); // _loadDbTranslation() $dbData = ['db original' => 'db translated', 'module db' => 'db translated overwrite']; $this->resource->expects($this->any())->method('getTranslationArray')->will($this->returnValue($dbData)); $this->cache->expects($this->exactly(1))->method('save'); $this->translate->loadData($area, $forceReload); $expected = ['module original' => 'module translated', 'module theme' => 'theme translated overwrite', 'module pack' => 'pack translated overwrite', 'module db' => 'db translated overwrite', 'theme original' => 'theme translated', 'pack original' => 'pack translated', 'db original' => 'db translated']; $this->assertEquals($expected, $this->translate->getData()); }
protected function setUp() { $this->registrar = $this->getMockForAbstractClass('\\Magento\\Framework\\Component\\ComponentRegistrarInterface'); $this->readFactory = $this->getMock('\\Magento\\Framework\\Filesystem\\Directory\\ReadFactory', [], [], '', false); $this->dir = $this->getMockForAbstractClass('\\Magento\\Framework\\Filesystem\\Directory\\ReadInterface'); $this->dir->expects($this->any())->method('getAbsolutePath')->willReturnArgument(0); $this->object = new DirSearch($this->registrar, $this->readFactory); }
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())); }
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())); }
public function testBasePackageInfo() { $this->readerMock->expects($this->once())->method('isExist')->willReturn(true); $this->readerMock->expects($this->once())->method('isReadable')->willReturn(true); $jsonData = json_encode([BasePackageInfo::COMPOSER_KEY_EXTRA => [BasePackageInfo::COMPOSER_KEY_MAP => [[__FILE__, __FILE__], [__DIR__, __DIR__]]]]); $this->readerMock->expects($this->once())->method('readFile')->willReturn($jsonData); $expectedList = [__FILE__, __DIR__]; $actualList = $this->basePackageInfo->getPaths(); $this->assertEquals($expectedList, $actualList); }
protected function prepareAttemptToMinifyMock($fileExists, $rootDirExpectations = true, $originalExists = true) { $this->asset->expects($this->atLeastOnce())->method('getPath')->will($this->returnValue('test/admin.js')); $this->asset->expects($this->atLeastOnce())->method('getSourceFile')->will($this->returnValue('/foo/bar/test/admin.js')); if ($rootDirExpectations) { $this->rootDir->expects($this->once())->method('getRelativePath')->with('/foo/bar/test/admin.min.js')->will($this->returnValue('test/admin.min.js')); $this->rootDir->expects($this->once())->method('isExist')->with('test/admin.min.js')->will($this->returnValue(false)); } $this->baseUrl->expects($this->once())->method('getBaseUrl')->will($this->returnValue('http://example.com/')); $this->staticViewDir->expects($this->exactly(2 - intval($originalExists)))->method('isExist')->will($this->returnValue($fileExists)); }
/** * Create mocks of assets to merge, as well as a few related necessary mocks * * @return array */ private function getAssetsToMerge() { $one = $this->getMock('\\Magento\\Framework\\View\\Asset\\File', [], [], '', false); $one->expects($this->once())->method('getSourceFile')->will($this->returnValue('/dir/file/one.txt')); $two = $this->getMock('\\Magento\\Framework\\View\\Asset\\File', [], [], '', false); $two->expects($this->once())->method('getSourceFile')->will($this->returnValue('/dir/file/two.txt')); $this->sourceDir->expects($this->exactly(2))->method('getRelativePath')->will($this->onConsecutiveCalls('file/one.txt', 'file/two.txt')); $this->sourceDir->expects($this->exactly(2))->method('stat')->will($this->returnValue(['mtime' => '1'])); $this->resultAsset->expects($this->once())->method('getPath')->will($this->returnValue('merged/result.txt')); return [$one, $two]; }
public function testCopyQuoteToOrder() { $optionMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product\\Configuration\\Item\\Option\\OptionInterface')->disableOriginalConstructor()->setMethods(['getValue'])->getMockForAbstractClass(); $quotePath = '/quote/path/path/uploaded.file'; $orderPath = '/order/path/path/uploaded.file'; $optionMock->expects($this->any())->method('getValue')->will($this->returnValue(['quote_path' => $quotePath, 'order_path' => $orderPath])); $this->rootDirectory->expects($this->any())->method('isFile')->with($this->equalTo($quotePath))->will($this->returnValue(true)); $this->rootDirectory->expects($this->any())->method('isReadable')->with($this->equalTo($quotePath))->will($this->returnValue(true)); $this->rootDirectory->expects($this->any())->method('getAbsolutePath')->will($this->returnValue('/file.path')); $this->coreFileStorageDatabase->expects($this->any())->method('copyFile')->will($this->returnValue('true')); $fileObject = $this->getFileObject(); $fileObject->setData('configuration_item_option', $optionMock); $this->assertInstanceOf('Magento\\Catalog\\Model\\Product\\Option\\Type\\File', $fileObject->copyQuoteToOrder()); }
protected function setUp() { $this->tmpDirectory = $this->getMockForAbstractClass('\\Magento\\Framework\\Filesystem\\Directory\\WriteInterface'); $this->rootDirectory = $this->getMockForAbstractClass('\\Magento\\Framework\\Filesystem\\Directory\\ReadInterface'); $this->rootDirectory->expects($this->any())->method('getRelativePath')->will($this->returnArgument(0)); $this->rootDirectory->expects($this->any())->method('readFile')->will($this->returnCallback(function ($file) { return "content of '{$file}'"; })); $filesystem = $this->getMock('\\Magento\\Framework\\App\\Filesystem', array(), array(), '', false); $filesystem->expects($this->once())->method('getDirectoryWrite')->with(\Magento\Framework\App\Filesystem::VAR_DIR)->will($this->returnValue($this->tmpDirectory)); $this->assetRepo = $this->getMock('\\Magento\\Framework\\View\\Asset\\Repository', array(), array(), '', false); $this->magentoImport = $this->getMock('\\Magento\\Framework\\Less\\PreProcessor\\Instruction\\MagentoImport', array(), array(), '', false); $this->import = $this->getMock('\\Magento\\Framework\\Less\\PreProcessor\\Instruction\\Import', array(), array(), '', false); $this->object = new \Magento\Framework\Less\FileGenerator($filesystem, $this->assetRepo, $this->magentoImport, $this->import); }
/** * @return void */ public function testGetData() { $themePath = 'blank'; $areaCode = 'adminhtml'; $files = [['path1'], ['path2']]; $relativePathMap = [['path1' => 'relativePath1'], ['path2' => 'relativePath2']]; $contentsMap = [['relativePath1' => 'content1$.mage.__("hello1")content1'], ['relativePath2' => 'content2$.mage.__("hello2")content2']]; $patterns = ['~\\$\\.mage\\.__\\([\'|\\"](.+?)[\'|\\"]\\)~']; $this->appStateMock->expects($this->once())->method('getAreaCode')->willReturn($areaCode); $this->filesUtilityMock->expects($this->once())->method('getJsFiles')->with($areaCode, $themePath)->willReturn($files); $this->rootDirectoryMock->expects($this->any())->method('getRelativePath')->willReturnMap($relativePathMap); $this->rootDirectoryMock->expects($this->any())->method('readFile')->willReturnMap($contentsMap); $this->configMock->expects($this->any())->method('getPatterns')->willReturn($patterns); $this->assertEquals([], $this->model->getData($themePath)); }
/** * Initialize testable object */ protected function setUp() { $this->htmlDirectoryMock = $this->getMockBuilder(Filesystem\Directory\WriteInterface::class)->getMockForAbstractClass(); $this->appDirectoryMock = $this->getMockBuilder(ReadInterface::class)->getMockForAbstractClass(); $this->rootDirectoryMock = $this->getMockBuilder(ReadInterface::class)->getMockForAbstractClass(); $this->filesystemMock = $this->getMockBuilder(Filesystem::class)->disableOriginalConstructor()->getMock(); $this->readFactoryMock = $this->getMockBuilder(Filesystem\Directory\ReadFactory::class)->disableOriginalConstructor()->getMock(); $this->filesystemMock->expects($this->once())->method('getDirectoryWrite')->with(DirectoryList::TEMPLATE_MINIFICATION_DIR)->willReturn($this->htmlDirectoryMock); $this->filesystemMock->expects($this->any())->method('getDirectoryRead')->with(DirectoryList::ROOT, DriverPool::FILE)->willReturn($this->rootDirectoryMock); $this->rootDirectoryMock->expects($this->any())->method('getRelativePath')->willReturnCallback(function ($value) { return ltrim($value, '/'); }); $this->readFactoryMock->expects($this->any())->method('create')->willReturn($this->appDirectoryMock); $this->object = (new ObjectManager($this))->getObject(Minifier::class, ['filesystem' => $this->filesystemMock, 'readFactory' => $this->readFactoryMock]); }
public function testGetFilesMultiple() { $dirPath = '/Magento_Customer/css/'; $themePath = '/opt/magento2/app/design/frontend/Magento/blank'; $searchPath = 'css/*.test'; $this->themeMock->expects($this->any())->method('getFullPath')->will($this->returnValue($themePath)); $this->themesDirectoryMock->expects($this->any())->method('getAbsolutePath')->will($this->returnValueMap([['fileA.test', $dirPath . 'fileA.test'], ['fileB.tst', $dirPath . 'fileB.tst'], ['fileC.test', $dirPath . 'fileC.test']])); $fileMock = $this->getMockBuilder('Magento\\Framework\\View\\File')->disableOriginalConstructor()->getMock(); // Verifies correct files are searched for $this->themesDirectoryMock->expects($this->once())->method('search')->with($themePath . '/' . $searchPath)->will($this->returnValue(['fileA.test', 'fileC.test'])); // Verifies Magento_Customer was correctly produced from directory path $this->fileFactoryMock->expects($this->any())->method('create')->with($this->isType('string'), null, $this->equalTo($this->themeMock))->will($this->returnValue($fileMock)); $theme = new Theme($this->filesystemMock, $this->fileFactoryMock); // Only two files should be in array, which were returned from search $this->assertEquals([$fileMock, $fileMock], $theme->getFiles($this->themeMock, 'css/*.test')); }
/** * cover positive case for getFaviconFile and checkIsFile */ public function testGetFaviconFile() { $scopeConfigValue = 'path'; $urlToMediaDir = 'http://magento.url/pub/media/'; $expectedFile = ImageFavicon::UPLOAD_DIR . '/' . $scopeConfigValue; $expectedUrl = $urlToMediaDir . $expectedFile; $this->scopeManager->expects($this->once())->method('getValue')->with('design/head/shortcut_icon', ScopeInterface::SCOPE_STORE)->willReturn($scopeConfigValue); $this->store->expects($this->once())->method('getBaseUrl')->with(UrlInterface::URL_TYPE_MEDIA)->willReturn($urlToMediaDir); $this->fileStorageDatabase->expects($this->once())->method('checkDbUsage')->willReturn(true); $this->fileStorageDatabase->expects($this->once())->method('saveFileToFilesystem')->willReturn(true); $this->mediaDir->expects($this->at(0))->method('isFile')->with($expectedFile)->willReturn(false); $this->mediaDir->expects($this->at(1))->method('isFile')->with($expectedFile)->willReturn(true); $results = $this->object->getFaviconFile(); $this->assertEquals($expectedUrl, $results); $this->assertNotFalse($results); }
/** * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Please specify product's required option(s). */ public function testValidateWithUnreadableFile() { $relativePath = '/custom_options/quote/file'; $optionValues = ['quote_path' => '/custom_options/quote/file', 'title' => 'File Title']; $this->prepare(); $this->directoryRead->expects($this->once())->method('isReadable')->with($relativePath)->willReturn(false); $this->validator->validate($optionValues, $this->option); }
protected function _setupFileMocks($doesExist = true, $size = self::FILE_SIZE, $path = self::FILE_PATH) { $this->_handleMock->expects($this->any())->method('stat')->will($this->returnValue(['size' => $size])); $this->_downloadableFileMock->expects($this->any())->method('ensureFileInFilesystem')->with($path)->will($this->returnValue($doesExist)); $this->_workingDirectoryMock->expects($doesExist ? $this->once() : $this->never())->method('openFile')->will($this->returnValue($this->_handleMock)); $this->_filesystemMock->expects($this->any())->method('getDirectoryRead')->with(DirectoryList::MEDIA)->will($this->returnValue($this->_workingDirectoryMock)); $this->_helper->setResource($path, DownloadHelper::LINK_TYPE_FILE); }
/** * @test * @return void */ public function testLoadData() { $relativeDir = 'dir'; $fileContent = 'content file'; $media = ['preview_image' => 'preview.jpg']; $themeTitle = 'Theme title'; $themeConfigs = ['frontend/theme/code']; $themeConfig = $this->getMockBuilder('Magento\\Framework\\Config\\Theme')->disableOriginalConstructor()->getMock(); $theme = $this->getMockBuilder('Magento\\Theme\\Model\\Theme')->disableOriginalConstructor()->getMock(); $parentTheme = ['parentThemeCode']; $parentThemePath = 'frontend/parent/theme'; $this->directory->expects($this->once())->method('search')->with($relativeDir)->willReturn($themeConfigs); $this->directory->expects($this->any())->method('isExist')->with($themeConfigs[0])->willReturn(true); $this->directory->expects($this->any())->method('readFile')->with($themeConfigs[0])->willReturn($fileContent); $this->directory->expects($this->any())->method('getRelativePath')->with($themeConfigs[0])->willReturn($themeConfigs[0]); $this->directory->expects($this->any())->method('getAbsolutePath')->willReturnMap([[$themeConfigs[0], $themeConfigs[0]], [null, '']]); $this->themeConfigFactory->expects($this->once())->method('create')->with(['configContent' => $fileContent])->willReturn($themeConfig); $this->directory->expects($this->at(1))->method('getAbsolutePath')->willReturn(''); $this->entityFactory->expects($this->any())->method('create')->with('Magento\\Theme\\Model\\Theme')->willReturn($theme); $themeConfig->expects($this->once())->method('getMedia')->willReturn($media); $themeConfig->expects($this->once())->method('getParentTheme')->willReturn($parentTheme); $themeConfig->expects($this->once())->method('getThemeTitle')->willReturn($themeTitle); $theme->expects($this->once())->method('addData')->with(['parent_id' => null, 'type' => ThemeInterface::TYPE_PHYSICAL, 'area' => 'frontend', 'theme_path' => 'theme', 'code' => 'theme', 'theme_title' => $themeTitle, 'preview_image' => $media['preview_image'], 'parent_theme_path' => $parentTheme[0]])->willReturnSelf(); $theme->expects($this->once())->method('getData')->with('parent_theme_path')->willReturn($parentThemePath); $theme->expects($this->once())->method('getArea')->willReturn('frontend'); $this->model->addTargetPattern($relativeDir); $this->assertInstanceOf(get_class($this->model), $this->model->loadData()); }
/** * @param $origFile * @param $origPath * @param $origContent * @param $isMaterialization * * @dataProvider getFileDataProvider */ public function testGetFile($origFile, $origPath, $origContent, $isMaterialization) { $filePath = 'some/file.ext'; $this->viewFileResolution->expects($this->once())->method('getFile')->with('frontend', $this->theme, 'en_US', $filePath, 'Magento_Module')->will($this->returnValue($origFile)); $this->rootDirRead->expects($this->once())->method('getRelativePath')->with($origFile)->will($this->returnValue($origPath)); $this->rootDirRead->expects($this->once())->method('readFile')->with($origPath)->will($this->returnValue($origContent)); $this->preProcessorPool->expects($this->once())->method('process')->with($this->chain); if ($isMaterialization) { $this->chain->expects($this->once())->method('isChanged')->willReturn(true); $this->chain->expects($this->once())->method('getContent')->willReturn('processed'); $this->chain->expects($this->once())->method('getTargetAssetPath')->willReturn($filePath); $this->varDir->expects($this->once())->method('writeFile')->with('view_preprocessed/source/some/file.ext', 'processed'); $this->varDir->expects($this->once())->method('getAbsolutePath')->with('view_preprocessed/source/some/file.ext')->will($this->returnValue('result')); } else { $this->varDir->expects($this->never())->method('writeFile'); $this->rootDirRead->expects($this->once())->method('getAbsolutePath')->with('source/some/file.ext')->will($this->returnValue('result')); } $this->assertSame('result', $this->object->getFile($this->getAsset())); }
protected function setUp() { $this->tmpDirectory = $this->getMockForAbstractClass('Magento\\Framework\\Filesystem\\Directory\\WriteInterface'); $this->rootDirectory = $this->getMockForAbstractClass('Magento\\Framework\\Filesystem\\Directory\\ReadInterface'); $this->rootDirectory->expects($this->any())->method('getRelativePath')->will($this->returnArgument(0)); $this->rootDirectory->expects($this->any())->method('readFile')->will($this->returnCallback(function ($file) { return "content of '{$file}'"; })); $filesystem = $this->getMock('\\Magento\\Framework\\Filesystem', [], [], '', false); $filesystem->expects($this->once())->method('getDirectoryWrite')->will($this->returnValue($this->tmpDirectory)); $this->assetRepo = $this->getMock('\\Magento\\Framework\\View\\Asset\\Repository', [], [], '', false); $this->magentoImport = $this->getMock('Magento\\Framework\\Less\\PreProcessor\\Instruction\\MagentoImport', [], [], '', false); $this->import = $this->getMock('Magento\\Framework\\Less\\PreProcessor\\Instruction\\Import', [], [], '', false); $assetSource = $this->getMock('Magento\\Framework\\View\\Asset\\Source', [], [], '', false); $this->relatedGenerator = $this->getMockBuilder('Magento\\Framework\\Less\\FileGenerator\\RelatedGenerator')->disableOriginalConstructor()->setMethods([])->getMock(); $this->config = $this->getMockBuilder('Magento\\Framework\\Less\\Config')->disableOriginalConstructor()->setMethods([])->getMock(); $this->temporaryFile = $this->getMockBuilder('Magento\\Framework\\Less\\File\\Temporary')->disableOriginalConstructor()->setMethods([])->getMock(); $this->object = new \Magento\Framework\Less\FileGenerator($filesystem, $this->assetRepo, $this->magentoImport, $this->import, $assetSource, $this->relatedGenerator, $this->config, $this->temporaryFile); }
public function testGetViewConfig() { $themeMock = $this->getMock('Magento\\Theme\\Model\\Theme', ['getId', 'getCustomization', 'getCustomViewConfigPath'], [], '', false); $themeMock->expects($this->atLeastOnce())->method('getId')->will($this->returnValue(2)); $themeMock->expects($this->once())->method('getCustomization')->will($this->returnSelf()); $themeMock->expects($this->once())->method('getCustomViewConfigPath')->will($this->returnValue('')); $params = ['themeModel' => $themeMock]; $configFile = 'config.xml'; $this->repositoryMock->expects($this->atLeastOnce())->method('updateDesignParams')->with($this->equalTo($params))->will($this->returnSelf()); $iterator = $this->getMock('Magento\\Framework\\Config\\FileIterator', [], [], '', false); $iterator->expects($this->once())->method('toArray')->will($this->returnValue([])); $this->readerMock->expects($this->once())->method('getConfigurationFiles')->with($this->equalTo(basename(\Magento\Framework\View\ConfigInterface::CONFIG_FILE_NAME)))->will($this->returnValue($iterator)); $this->directoryReadMock->expects($this->once())->method('isExist')->with($this->anything())->will($this->returnValue(true)); $this->fileSystemMock->expects($this->once())->method('getFilename')->with($this->equalTo(\Magento\Framework\View\ConfigInterface::CONFIG_FILE_NAME), $params)->will($this->returnValue($configFile)); $this->directoryReadMock->expects($this->any())->method('getRelativePath')->with($this->equalTo($configFile))->will($this->returnArgument(0)); $xmlData = '<view><vars module="Magento_Catalog"><var name="test">1</var></vars></view>'; $this->directoryReadMock->expects($this->once())->method('readFile')->with($this->equalTo($configFile))->will($this->returnValue($xmlData)); $this->assertInstanceOf('Magento\\Framework\\Config\\View', $this->config->getViewConfig($params)); // lazy load test $this->assertInstanceOf('Magento\\Framework\\Config\\View', $this->config->getViewConfig($params)); }
public function testGetFilesMultiple() { $dirPath = '/Magento_Customer/css/'; $searchPath = 'css/*.test'; $this->componentRegistrar->expects($this->once())->method('getPath')->with(ComponentRegistrar::THEME, $this->themePath)->will($this->returnValue(self::FULL_THEME_PATH)); $fileMock = $this->getMockBuilder('Magento\\Framework\\View\\File')->disableOriginalConstructor()->getMock(); $this->themeDirectoryMock->expects($this->any())->method('getAbsolutePath')->willReturnMap([['fileA.test', $dirPath . 'fileA.test'], ['fileB.tst', $dirPath . 'fileB.tst'], ['fileC.test', $dirPath . 'fileC.test']]); // Verifies correct files are searched for $this->themeDirectoryMock->expects($this->once())->method('search')->with($searchPath)->willReturn(['fileA.test', 'fileC.test']); // Verifies Magento_Customer was correctly produced from directory path $this->fileFactoryMock->expects($this->any())->method('create')->with($this->isType('string'), null, $this->themeMock)->willReturn($fileMock); // Only two files should be in array, which were returned from search $this->assertEquals([$fileMock, $fileMock], $this->themeFileCollector->getFiles($this->themeMock, $searchPath)); }
/** * * @dataProvider getFilesDataProvider * * @param $libraryFiles array Files in lib directory * @param $themeFiles array Files in theme * * * @return void */ public function testGetFiles($libraryFiles, $themeFiles) { $this->fileListMock->expects($this->any())->method('getAll')->will($this->returnValue(['returnedFile'])); $this->libraryDirectoryMock->expects($this->any())->method('search')->will($this->returnValue($libraryFiles)); $this->libraryDirectoryMock->expects($this->any())->method('getAbsolutePath')->will($this->returnCallback(function ($file) { return '/opt/Magneto/lib/' . $file; })); $themePath = '/var/Magento/ATheme'; $subPath = '*'; $this->themesDirectoryMock->expects($this->any())->method('search')->with($themePath . '/web/' . $subPath)->will($this->returnValue($themeFiles)); $library = new Library($this->fileListFactoryMock, $this->fileSystemMock, $this->fileFactoryMock); $inheritedThemeMock = $this->getMockBuilder('\\Magento\\Framework\\View\\Design\\ThemeInterface')->getMock(); $inheritedThemeMock->expects($this->any())->method('getFullPath')->will($this->returnValue($themePath)); $this->themeMock->expects($this->any())->method('getInheritedThemes')->will($this->returnValue([$inheritedThemeMock])); $this->assertEquals(['returnedFile'], $library->getFiles($this->themeMock, $subPath)); }
/** * @param int $mtimeOrig * @param int $mtimeMinified * @param bool $isMinifyExpected * @dataProvider minifyMtimeDataProvider */ public function testMinifyMtime($mtimeOrig, $mtimeMinified, $isMinifyExpected) { $this->prepareAttemptToMinifyMock(true, false); $model = new Minified($this->_asset, $this->_logger, $this->_filesystem, $this->_baseUrl, $this->_adapter, Minified::MTIME); $this->_rootDir->expects($this->any())->method('getRelativePath')->will($this->returnValueMap([['/foo/bar/test/library.min.js', 'test/library.min.js'], ['/foo/bar/test/library.js', 'test/library.js']])); $this->_rootDir->expects($this->once())->method('isExist')->with('test/library.min.js')->will($this->returnValue(false)); $this->_rootDir->expects($this->once())->method('stat')->with('test/library.js')->will($this->returnValue(['mtime' => $mtimeOrig])); $this->_staticViewDir->expects($this->once())->method('stat')->with($this->anything())->will($this->returnValue(['mtime' => $mtimeMinified])); if ($isMinifyExpected) { $this->_asset->expects($this->once())->method('getContent')->will($this->returnValue('content')); $this->_adapter->expects($this->once())->method('minify')->with('content')->will($this->returnValue('mini')); $this->_staticViewDir->expects($this->once())->method('writeFile')->with($this->anything(), 'mini'); } else { $this->_adapter->expects($this->never())->method('minify'); } $this->assertStringMatchesFormat('%s_library.min.js', $model->getFilePath()); }
/** * * @dataProvider getFilesDataProvider * * @param $libraryFiles array Files in lib directory * @param $themeFiles array Files in theme * * * @return void */ public function testGetFiles($libraryFiles, $themeFiles) { $this->fileListMock->expects($this->any())->method('getAll')->will($this->returnValue(['returnedFile'])); $this->libraryDirectoryMock->expects($this->any())->method('search')->will($this->returnValue($libraryFiles)); $this->libraryDirectoryMock->expects($this->any())->method('getAbsolutePath')->will($this->returnCallback(function ($file) { return '/opt/Magento/lib/' . $file; })); $themePath = '/var/Magento/ATheme'; $subPath = '*'; $readerMock = $this->getMockBuilder('Magento\\Framework\\Filesystem\\Directory\\ReadInterface')->getMock(); $this->readFactoryMock->expects($this->once())->method('create')->will($this->returnValue($readerMock)); $this->componentRegistrarMock->expects($this->once())->method('getPath')->with(ComponentRegistrar::THEME, $themePath)->will($this->returnValue(['/path/to/theme'])); $readerMock->expects($this->once())->method('search')->will($this->returnValue($themeFiles)); $inheritedThemeMock = $this->getMockBuilder('\\Magento\\Framework\\View\\Design\\ThemeInterface')->getMock(); $inheritedThemeMock->expects($this->any())->method('getFullPath')->will($this->returnValue($themePath)); $this->themeMock->expects($this->any())->method('getInheritedThemes')->will($this->returnValue([$inheritedThemeMock])); $this->assertEquals(['returnedFile'], $this->library->getFiles($this->themeMock, $subPath)); }
public function testGetFiles() { $sharedFiles = [ 'Namespace/One/view/base/layout/one.xml', 'Namespace/Two/view/base/layout/two.xml' ]; $themeFiles = [ 'Namespace/Two/view/frontend/layout/four.txt', 'Namespace/Two/view/frontend/layout/three.xml' ]; $this->directoryMock->expects($this->any()) ->method('search') ->willReturnMap( [ ['*/*/view/base/layout/*.xml', null, $sharedFiles], ['*/*/view/frontend/layout/*.xml', null, $themeFiles] ] ); $this->pathPatternHelperMock->expects($this->once()) ->method('translatePatternFromGlob') ->with('*.xml') ->willReturn('[^/]*\\.xml'); $this->directoryMock->expects($this->atLeastOnce()) ->method('getAbsolutePath') ->willReturnArgument(0); $this->fileFactoryMock->expects($this->atLeastOnce()) ->method('create') ->willReturn($this->createFileMock()); $this->themeMock->expects($this->once()) ->method('getData') ->with('area') ->willReturn('frontend'); $result = $this->fileCollector->getFiles($this->themeMock, '*.xml'); $this->assertCount(3, $result); $this->assertInstanceOf('Magento\Framework\View\File', $result[0]); $this->assertInstanceOf('Magento\Framework\View\File', $result[1]); $this->assertInstanceOf('Magento\Framework\View\File', $result[2]); }
/** * @param string $origFile * @param string $origPath * @param string $origContentType * @param string $origContent * @param string $isMaterialization * @dataProvider getFileDataProvider */ public function testGetFile($origFile, $origPath, $origContentType, $origContent, $isMaterialization) { $filePath = 'some/file.ext'; $cacheValue = "{$origPath}:{$filePath}"; $this->viewFileResolution->expects($this->once())->method('getFile')->with('frontend', $this->theme, 'en_US', $filePath, 'Magento_Module')->will($this->returnValue($origFile)); $this->rootDirRead->expects($this->once())->method('getRelativePath')->with($origFile)->will($this->returnValue($origPath)); $this->cache->expects($this->once())->method('load')->will($this->returnValue(false)); $this->rootDirRead->expects($this->once())->method('readFile')->with($origPath)->will($this->returnValue($origContent)); $processor = $this->getMockForAbstractClass('Magento\\Framework\\View\\Asset\\PreProcessorInterface'); $this->preProcessorPool->expects($this->once())->method('getPreProcessors')->with($origContentType, 'ext')->will($this->returnValue([$processor])); $processor->expects($this->once())->method('process')->will($this->returnCallback(array($this, 'chainTestCallback'))); if ($isMaterialization) { $this->varDir->expects($this->once())->method('writeFile')->with('view_preprocessed/source/some/file.ext', 'processed'); $this->cache->expects($this->once())->method('save')->with(serialize([\Magento\Framework\App\Filesystem::VAR_DIR, 'view_preprocessed/source/some/file.ext']), $cacheValue); $this->varDir->expects($this->once())->method('getAbsolutePath')->with('view_preprocessed/source/some/file.ext')->will($this->returnValue('result')); } else { $this->varDir->expects($this->never())->method('writeFile'); $this->cache->expects($this->once())->method('save')->with(serialize([\Magento\Framework\App\Filesystem::ROOT_DIR, 'source/some/file.ext']), $cacheValue); $this->rootDirRead->expects($this->once())->method('getAbsolutePath')->with('source/some/file.ext')->will($this->returnValue('result')); } $this->assertSame('result', $this->object->getFile($this->getAsset())); }
public function testExecuteGetParamImage() { $decodedFile = 'decoded_file'; $file = 'file'; $fileName = 'customer/' . $file; $path = 'path'; $stat = ['size' => 10, 'mtime' => 10]; $this->requestMock->expects($this->any())->method('getParam')->willReturnMap([['file', null, null], ['image', null, $decodedFile]]); $this->directoryMock->expects($this->once())->method('getAbsolutePath')->with($fileName)->willReturn($path); $this->directoryMock->expects($this->once())->method('stat')->with($path)->willReturn($stat); $this->fileSystemMock->expects($this->once())->method('getDirectoryRead')->with(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA)->willReturn($this->directoryMock); $this->storage->expects($this->once())->method('processStorageFile')->with($path)->willReturn(true); $this->objectManager->expects($this->any())->method('get')->willReturnMap([['Magento\\Framework\\Filesystem', $this->fileSystemMock], ['Magento\\MediaStorage\\Helper\\File\\Storage', $this->storage]]); $this->urlDecoderMock->expects($this->once())->method('decode')->with($decodedFile)->willReturn($file); $this->resultRawMock->expects($this->once())->method('setHttpResponseCode')->with(200)->willReturnSelf(); $this->resultRawMock->expects($this->any())->method('setHeader')->willReturnMap([['Pragma', 'public', true, $this->resultRawMock], ['Content-type', 'application/octet-stream', true, $this->resultRawMock], ['Content-Length', $stat['size'], false, $this->resultRawMock], ['Pragma', 'public', true, $this->resultRawMock]]); $this->resultRawFactoryMock = $this->getMock('Magento\\Framework\\Controller\\Result\\RawFactory', ['create'], [], '', false); $this->resultRawFactoryMock->expects($this->once())->method('create')->willReturn($this->resultRawMock); /** @var \Magento\Customer\Controller\Adminhtml\Index\Viewfile $controller */ $controller = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject('Magento\\Customer\\Controller\\Adminhtml\\Index\\Viewfile', ['context' => $this->contextMock, 'urlDecoder' => $this->urlDecoderMock, 'resultRawFactory' => $this->resultRawFactoryMock]); $this->assertSame($this->resultRawMock, $controller->execute()); }
public function testGetDirModuleSubDir() { $this->directoryMock->expects($this->once())->method('getAbsolutePath')->with('Test/Module/etc')->will($this->returnValue('/Test/Module/etc')); $this->assertEquals('/Test/Module/etc', $this->_model->getDir('Test_Module', 'etc')); }
/** * Test is file valid * * @param string $file * @param bool $expectedResult * * @dataProvider testIsValidDataProvider * * @return void */ public function testIsValid($file, $expectedResult) { $this->rootDirectoryMock->expects($this->any())->method('isFile')->will($this->returnValue(true)); $this->assertEquals($expectedResult, $this->_validator->isValid($file)); }