コード例 #1
0
 public function testGetDesign()
 {
     $expected = new \StdClass();
     $this->componentDirSearch->expects($this->once())->method('collectFiles')->with(ComponentRegistrar::THEME, 'etc/file')->will($this->returnValue(['test']));
     $this->factory->expects($this->once())->method('create')->with(['test'])->willReturn($expected);
     $this->assertSame($expected, $this->object->get('file', 'design'));
 }
コード例 #2
0
ファイル: FilesTest.php プロジェクト: tingyeeh/magento2
 public function testGetLayoutConfigFiles()
 {
     $this->dirSearch->expects($this->once())->method('collectFiles')->with(ComponentRegistrar::THEME, '/etc/some.file')->willReturn(['/one/some.file', '/two/some.file']);
     $expected = ['/one/some.file', '/two/some.file'];
     $actual = Files::init()->getLayoutConfigFiles('some.file', false);
     $this->assertSame($expected, $actual);
     // Check that the result is cached (collectFiles() is called only once)
     $this->assertSame($expected, $actual);
 }
コード例 #3
0
ファイル: Base.php プロジェクト: kidaa30/magento2-platformsh
 /**
  * Retrieve files
  *
  * @param \Magento\Framework\View\Design\ThemeInterface $theme
  * @param string $filePath
  * @return \Magento\Framework\View\File[]
  */
 public function getFiles(ThemeInterface $theme, $filePath)
 {
     $result = [];
     $sharedFiles = $this->componentDirSearch->collectFilesWithContext(ComponentRegistrar::MODULE, "view/base/{$this->subDir}{$filePath}");
     foreach ($sharedFiles as $file) {
         $result[] = $this->fileFactory->create($file->getFullPath(), $file->getComponentName(), null, true);
     }
     $area = $theme->getData('area');
     $themeFiles = $this->componentDirSearch->collectFilesWithContext(ComponentRegistrar::MODULE, "view/{$area}/{$this->subDir}{$filePath}");
     foreach ($themeFiles as $file) {
         $result[] = $this->fileFactory->create($file->getFullPath(), $file->getComponentName());
     }
     return $result;
 }
コード例 #4
0
 /**
  * {@inheritdoc}
  */
 public function get($filename, $scope)
 {
     switch ($scope) {
         case 'global':
             $iterator = $this->_moduleReader->getConfigurationFiles($filename);
             break;
         case 'design':
             $themePaths = $this->componentDirSearch->collectFiles(ComponentRegistrar::THEME, 'etc/' . $filename);
             $iterator = $this->iteratorFactory->create($themePaths);
             break;
         default:
             $iterator = $this->iteratorFactory->create([]);
             break;
     }
     return $iterator;
 }
コード例 #5
0
 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]);
 }
コード例 #6
0
 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());
 }
コード例 #7
0
ファイル: Files.php プロジェクト: Doability/magento2dev
 /**
  * Get paths by pattern for specified component component
  *
  * @param string $componentType
  * @param string $componentName
  * @param string $pathPattern
  * @return array
  */
 private function getPathByComponentPattern($componentType, $componentName, $pathPattern)
 {
     $files = [];
     if ($componentType == '*') {
         $componentTypes = [ComponentRegistrar::MODULE, ComponentRegistrar::LIBRARY, ComponentRegistrar::THEME, ComponentRegistrar::LANGUAGE];
     } else {
         $componentTypes = [$componentType];
     }
     foreach ($componentTypes as $type) {
         if ($componentName == '*') {
             $files = array_merge($files, $this->dirSearch->collectFiles($type, $pathPattern));
         } else {
             $componentDir = $this->componentRegistrar->getPath($type, $componentName);
             if (!empty($componentDir)) {
                 $files = array_merge($files, Glob::glob($componentDir . '/' . $pathPattern, Glob::GLOB_BRACE));
             }
         }
     }
     return $files;
 }
コード例 #8
0
 /**
  * {@inheritdoc}
  */
 public function get($filename, $scope)
 {
     $iterator = $this->iteratorFactory->create($this->dirSearch->collectFiles(ComponentRegistrar::MODULE, 'etc/' . $filename));
     return $iterator;
 }
コード例 #9
0
ファイル: Reader.php プロジェクト: whoople/magento2-testing
 /**
  * Get list of xsd files
  *
  * @param string $filename
  * @return array
  */
 public function getListXsdFiles($filename)
 {
     return $this->iteratorFactory->create(array_merge($this->componentDirSearch->collectFiles(ComponentRegistrar::MODULE, 'etc/' . $filename), $this->componentDirSearch->collectFiles(ComponentRegistrar::LIBRARY, '*/etc/' . $filename)));
 }