public function testGetFiles() { $directory = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\Read', [], [], '', false); $filesystem = $this->getMock('Magento\\Framework\\Filesystem', ['getDirectoryRead'], [], '', false); $filesystem->expects($this->once())->method('getDirectoryRead')->with(DirectoryList::MODULES)->will($this->returnValue($directory)); $globalFiles = ['Namespace/One/view/base/layout/one.xml', 'Namespace/Two/view/base/layout/two.xml']; $areaFiles = ['Namespace/Two/view/frontend/layout/four.txt', 'Namespace/Two/view/frontend/layout/three.xml']; $directory->expects($this->at(0))->method('search')->with('*/*/view/base/layout/*.xml')->will($this->returnValue($globalFiles)); $directory->expects($this->at(3))->method('search')->with('*/*/view/frontend/layout/*.xml')->will($this->returnValue($areaFiles)); $directory->expects($this->atLeastOnce())->method('getAbsolutePath')->will($this->returnArgument(0)); $objectManager = $this->getMock('Magento\\Framework\\ObjectManagerInterface'); $objectManager->expects($this->atLeastOnce())->method('create')->with('Magento\\Framework\\View\\File', $this->anything())->will($this->returnCallback([$this, 'createFileCallback'])); $fileFactory = new \Magento\Framework\View\File\Factory($objectManager); $theme = $this->getMock('Magento\\Framework\\View\\Design\\ThemeInterface', ['getArea', 'getThemePath', 'getFullPath', 'getParentTheme', 'getCode', 'isPhysical', 'getInheritedThemes', 'getId', 'getData']); $theme->expects($this->once())->method('getData')->with('area')->will($this->returnValue('frontend')); $model = new Base($filesystem, $fileFactory, 'layout'); $result = $model->getFiles($theme, '*.xml'); for ($i = 0; $i <= 2; $i++) { $this->assertArrayHasKey($i, $result); $this->assertInstanceOf('\\Magento\\Framework\\View\\File', $result[$i]); } $this->assertEquals($globalFiles[0], $result[0]->getFilename()); $this->assertEquals($globalFiles[1], $result[1]->getFilename()); $this->assertEquals($areaFiles[1], $result[2]->getFilename()); }
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 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]); }