public function testGetDirectoryRead() { /** @var \Magento\Framework\Filesystem\Directory\ReadInterface $dirReadMock */ $dirReadMock = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\ReadInterface'); $this->_dirReadFactoryMock->expects($this->once())->method('create')->will($this->returnValue($dirReadMock)); $this->assertEquals($dirReadMock, $this->_filesystem->getDirectoryRead(DirectoryList::ROOT)); }
public function setup() { $this->readFactoryMock = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\ReadFactory', [], [], '', false); $this->readerMock = $this->getMockForAbstractClass('Magento\\Framework\\Filesystem\\Directory\\ReadInterface', [], '', false); $this->readFactoryMock->expects($this->once())->method('create')->willReturn($this->readerMock); $this->basePackageInfo = new BasePackageInfo($this->readFactoryMock); }
protected function setUp() { $this->componentRegistrar = $this->getMock('Magento\\Framework\\Component\\ComponentRegistrar', [], [], '', false); $this->dirRead = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\Read', [], [], '', false); $this->dirReadFactory = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\ReadFactory', [], [], '', false); $this->dirReadFactory->expects($this->any())->method('create')->willReturn($this->dirRead); $this->themePackageInfo = new ThemePackageInfo($this->componentRegistrar, $this->dirReadFactory); }
protected function setUp() { $this->themeDirectory = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\Read', ['getAbsolutePath', 'search'], [], '', false); $this->pathPatternHelperMock = $this->getMockBuilder('Magento\\Framework\\View\\Helper\\PathPattern')->disableOriginalConstructor()->getMock(); $this->fileFactory = $this->getMock('Magento\\Framework\\View\\File\\Factory', [], [], '', false); $this->readDirFactory = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\ReadFactory', [], [], '', false); $this->readDirFactory->expects($this->any())->method('create')->will($this->returnValue($this->themeDirectory)); $this->componentRegistrar = $this->getMockForAbstractClass('Magento\\Framework\\Component\\ComponentRegistrarInterface'); $this->model = new \Magento\Framework\View\File\Collector\Override\Base($this->fileFactory, $this->readDirFactory, $this->componentRegistrar, $this->pathPatternHelperMock, 'override'); }
protected function setUp() { $this->entityFactory = $this->getMockBuilder('Magento\\Framework\\Data\\Collection\\EntityFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->themeConfigFactory = $this->getMockBuilder('Magento\\Framework\\Config\\ThemeFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock(); $this->directory = $this->getMockBuilder('Magento\\Framework\\Filesystem\\Directory\\ReadInterface')->disableOriginalConstructor()->getMock(); $this->themePackageList = $this->getMock('\\Magento\\Framework\\View\\Design\\Theme\\ThemePackageList', [], [], '', false); $this->readDirFactory = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\ReadFactory', [], [], '', false); $this->readDirFactory->expects($this->any())->method('create')->will($this->returnValue($this->directory)); $this->model = new Collection($this->entityFactory, $this->themeConfigFactory, $this->themePackageList, $this->readDirFactory); }
public function setup() { $this->themeDirectoryMock = $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->themeMock->expects($this->once())->method('getFullPath')->will($this->returnValue($this->themePath)); $this->readDirFactory = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\ReadFactory', [], [], '', false); $this->readDirFactory->expects($this->any())->method('create')->will($this->returnValue($this->themeDirectoryMock)); $this->componentRegistrar = $this->getMockForAbstractClass('Magento\\Framework\\Component\\ComponentRegistrarInterface'); $this->themeFileCollector = new Theme($this->fileFactoryMock, $this->readDirFactory, $this->componentRegistrar); }
/** * Initialize testable object */ public function setUp() { $this->htmlDirectory = $this->getMockBuilder('Magento\\Framework\\Filesystem\\Directory\\WriteInterface')->getMock(); $this->appDirectory = $this->getMockBuilder('Magento\\Framework\\Filesystem\\Directory\\ReadInterface')->getMock(); $filesystem = $this->getMockBuilder('Magento\\Framework\\Filesystem')->disableOriginalConstructor()->getMock(); $filesystem->expects($this->once())->method('getDirectoryWrite')->with(DirectoryList::TEMPLATE_MINIFICATION_DIR)->willReturn($this->htmlDirectory); /** @var \Magento\Framework\Filesystem $filesystem */ $this->readFactory = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\ReadFactory', [], [], '', false); $this->readFactory->expects($this->any())->method('create')->willReturn($this->appDirectory); $this->object = new Minifier($filesystem, $this->readFactory); }
/** * @param bool $check */ protected function getContentStep($check = true) { $resultPath = 'adminhtml/path/to/file.xml'; $includeXmlContent = '<config><item id="1"><test/></item><item id="2"></item></config>'; $modulesDirectoryMock = $this->getMockBuilder('Magento\\Framework\\Filesystem\\Directory\\ReadInterface')->getMockForAbstractClass(); $this->readFactoryMock->expects($this->once())->method('create')->willReturn($modulesDirectoryMock); $this->moduleReaderMock->expects($this->once())->method('getModuleDir')->with('etc', 'Module_Name')->willReturn('path/in/application/module'); $modulesDirectoryMock->expects($this->once())->method('isExist')->with($resultPath)->willReturn($check); if ($check) { $modulesDirectoryMock->expects($this->once())->method('isFile')->with($resultPath)->willReturn($check); $modulesDirectoryMock->expects($this->once())->method('readFile')->with($resultPath)->willReturn($includeXmlContent); } }
/** * 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 testResolveNonexistentFile() { $this->readFactoryMock->expects($this->any())->method('create')->willReturn($this->directoryMock); $this->ruleMock->expects($this->once())->method('getPatternDirs')->willReturn(['some/dir']); $this->directoryMock->expects($this->once())->method('isExist')->willReturn(false); $this->assertFalse($this->object->resolve('type', 'file.ext', 'frontend', $this->getMockForTheme('magento_theme'), 'en_US', 'Magento_Module')); }
public function testCollectFilesWithContext() { $componentType = 'component_type'; $componentPaths = ['component1' => 'path1', 'component2' => 'path2']; $pattern = '*/file.xml'; $this->registrar->expects($this->once())->method('getPaths')->with($componentType)->willReturn($componentPaths); $this->readFactory->expects($this->exactly(2))->method('create')->willReturnMap([['path1', DriverPool::FILE, $this->dir], ['path2', DriverPool::FILE, $this->dir]]); $this->dir->method('search')->with($pattern)->willReturnOnConsecutiveCalls(['one/file.xml'], ['two/file.xml']); $actualFiles = $this->object->collectFilesWithContext($componentType, $pattern); $this->assertNotEmpty($actualFiles); /** @var \Magento\Framework\Component\ComponentFile $file */ foreach ($actualFiles as $file) { $this->assertInstanceOf('\\Magento\\Framework\\Component\\ComponentFile', $file); $this->assertSame($componentType, $file->getComponentType()); } $this->assertCount(2, $actualFiles); $this->assertSame('component1', $actualFiles[0]->getComponentName()); $this->assertSame('one/file.xml', $actualFiles[0]->getFullPath()); $this->assertSame('component2', $actualFiles[1]->getComponentName()); $this->assertSame('two/file.xml', $actualFiles[1]->getFullPath()); }
/** * @param string $origFile * @param string $origPath * @param string $origContent * @param bool $isMaterialization * @param bool $isExist * * @dataProvider getFileDataProvider */ public function testGetFile($origFile, $origPath, $origContent, $isMaterialization, $isExist) { $filePath = 'some/file.ext'; $read = $this->getMock('Magento\Framework\Filesystem\Directory\Read', [], [], '', false); $read->expects($this->at(0))->method('readFile')->with($origPath)->willReturn($origContent); $this->readFactory->expects($this->atLeastOnce())->method('create')->willReturn($read); $this->viewFileResolution->expects($this->once()) ->method('getFile') ->with('frontend', $this->theme, 'en_US', $filePath, 'Magento_Module') ->willReturn($origFile); $this->preProcessorPool->expects($this->once()) ->method('process') ->with($this->chain); $this->staticDirRead->expects($this->any()) ->method('isExist') ->willReturn($isExist); if ($isMaterialization || !$isExist) { $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') ->willReturn('var'); $read->expects($this->once()) ->method('getAbsolutePath') ->with('view_preprocessed/source/some/file.ext') ->willReturn('result'); } else { $this->varDir->expects($this->never())->method('writeFile'); $read->expects($this->at(1)) ->method('getAbsolutePath') ->with('file.ext') ->willReturn('result'); } $this->assertSame('result', $this->object->getFile($this->getAsset())); }
/** * * @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 testGetThemeTemplates() { $templates = (require __DIR__ . '/Config/_files/email_templates_merged.php'); $templateId = 'template_one'; $template = $templates[$templateId]; $foundThemePath = 'Vendor/custom_theme'; $theme = $this->getMock('\\Magento\\Framework\\View\\Design\\Theme\\ThemePackage', [], [], '', false); $theme->expects($this->any())->method('getArea')->willReturn('frontend'); $theme->expects($this->any())->method('getVendor')->willReturn('Vendor'); $theme->expects($this->any())->method('getName')->willReturn('custom_theme'); $theme->expects($this->any())->method('getPath')->willReturn('/theme/path'); $this->themePackages->expects($this->once())->method('getThemes')->willReturn([$theme]); $dir = $this->getMockForAbstractClass('\\Magento\\Framework\\Filesystem\\Directory\\ReadInterface'); $this->readDirFactory->expects($this->once())->method('create')->with('/theme/path')->willReturn($dir); $dir->expects($this->once())->method('isExist')->willReturn(true); $actualTemplates = $this->model->getThemeTemplates($templateId); $this->assertNotEmpty($actualTemplates); foreach ($actualTemplates as $templateOptions) { $this->assertEquals(sprintf('%s (%s)', $template['label'], $foundThemePath), $templateOptions['label']); $this->assertEquals(sprintf('%s/%s', $templateId, $foundThemePath), $templateOptions['value']); $this->assertEquals($template['module'], $templateOptions['group']); } }