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')); }
public function testGetFilesWithPreset() { $inputPath = 'preset/3.xml'; $grandparentTheme = $this->getMockForAbstractClass('Magento\Framework\View\Design\ThemeInterface'); $grandparentTheme->expects($this->once())->method('getCode')->willReturn('vendor/grand_parent_theme'); $parentTheme = $this->getMockForAbstractClass('Magento\Framework\View\Design\ThemeInterface'); $parentTheme->expects($this->once())->method('getCode')->willReturn('vendor/parent_theme'); $parentTheme->expects($this->once())->method('getParentTheme')->willReturn($grandparentTheme); $theme = $this->getMockForAbstractClass('Magento\Framework\View\Design\ThemeInterface'); $theme->expects($this->once())->method('getFullPath')->willReturn('area/theme_path'); $theme->expects($this->once())->method('getParentTheme')->willReturn($parentTheme); $filePathOne = 'design/area/theme_path/Module_Two/override/theme/vendor/grand_parent_theme/preset/3.xml'; $this->directory->expects($this->once()) ->method('search') ->with('area/theme_path/*_*/override/theme/*/*/preset/3.xml') ->willReturn([$filePathOne]); $fileOne = new \Magento\Framework\View\File('3.xml', 'Module_Two', $grandparentTheme); $this->fileFactory ->expects($this->once()) ->method('create') ->with($filePathOne, 'Module_Two', $grandparentTheme) ->willReturn($fileOne); $this->pathPatternHelperMock->expects($this->any()) ->method('translatePatternFromGlob') ->with($inputPath) ->willReturn('preset/3.xml'); $this->assertSame([$fileOne], $this->model->getFiles($theme, $inputPath)); }
public function testGetFiles() { $files = []; foreach (['shared', 'theme'] as $fileType) { for ($i = 0; $i < 2; $i++) { $file = $this->getMock('\\Magento\\Framework\\Component\\ComponentFile', [], [], '', false); $file->expects($this->once())->method('getFullPath')->will($this->returnValue("{$fileType}/module/{$i}/path")); $file->expects($this->once())->method('getComponentName')->will($this->returnValue('Module_' . $i)); $files[$fileType][] = $file; } } $this->dirSearch->expects($this->any())->method('collectFilesWithContext')->willReturnMap([[ComponentRegistrar::MODULE, 'view/base/layout/*.xml', $files['shared']], [ComponentRegistrar::MODULE, 'view/frontend/layout/*.xml', $files['theme']]]); $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(4, $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]); $this->assertInstanceOf('Magento\\Framework\\View\\File', $result[3]); }
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)); }
public function testGetFilesWithPreset() { $themePath = 'area/theme_path'; $inputPath = 'preset/3.xml'; $grandparentTheme = $this->getMockForAbstractClass('Magento\\Framework\\View\\Design\\ThemeInterface'); $grandparentTheme->expects($this->once())->method('getCode')->willReturn('vendor/grand_parent_theme'); $parentTheme = $this->getMockForAbstractClass('Magento\\Framework\\View\\Design\\ThemeInterface'); $parentTheme->expects($this->once())->method('getCode')->willReturn('vendor/parent_theme'); $parentTheme->expects($this->once())->method('getParentTheme')->willReturn($grandparentTheme); $theme = $this->getMockForAbstractClass('Magento\\Framework\\View\\Design\\ThemeInterface'); $theme->expects($this->once())->method('getFullPath')->willReturn($themePath); $theme->expects($this->once())->method('getParentTheme')->willReturn($parentTheme); $filePathOne = 'design/area/theme_path/Module_Two/override/theme/vendor/grand_parent_theme/preset/3.xml'; $this->themeDirectory->expects($this->once())->method('search')->with('*_*/override/theme/*/*/preset/3.xml')->willReturn([$filePathOne]); $fileOne = $this->getMock('Magento\\Framework\\View\\File', [], [], '', false); $this->fileFactory->expects($this->once())->method('create')->with($filePathOne, 'Module_Two', $grandparentTheme)->willReturn($fileOne); $this->pathPatternHelperMock->expects($this->any())->method('translatePatternFromGlob')->with($inputPath)->willReturn('preset/3.xml'); $this->componentRegistrar->expects($this->once())->method('getPath')->with(ComponentRegistrar::THEME, $themePath)->will($this->returnValue('/full/theme/path')); $this->assertSame([$fileOne], $this->model->getFiles($theme, $inputPath)); }
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]); }