Esempio n. 1
0
    /**
     * @param array $files
     * @param string $filePath
     * @param string $pathPattern
     *
     * @dataProvider getFilesDataProvider
     */
    public function testGetFiles($files, $filePath, $pathPattern)
    {
        $theme = $this->getMockForAbstractClass('Magento\Framework\View\Design\ThemeInterface');
        $theme->expects($this->once())->method('getFullPath')->willReturn('area/theme/path');

        $handlePath = 'design/area/theme/path/%s/subdir/%s';
        $returnKeys = [];
        foreach ($files as $file) {
            $returnKeys[] = sprintf($handlePath, $file['module'], $file['handle']);
        }

        $this->pathPatternHelperMock->expects($this->any())
            ->method('translatePatternFromGlob')
            ->with($filePath)
            ->willReturn($pathPattern);
        $this->directory->expects($this->once())
            ->method('search')
            ->willReturn($returnKeys);
        $this->directory->expects($this->any())
            ->method('getAbsolutePath')
            ->willReturnArgument(0);

        $checkResult = [];
        foreach ($files as $key => $file) {
            $checkResult[$key] = new \Magento\Framework\View\File($file['handle'], $file['module'], $theme);
            $this->fileFactory
                ->expects($this->at($key))
                ->method('create')
                ->with(sprintf($handlePath, $file['module'], $file['handle']), $file['module'], $theme)
                ->willReturn($checkResult[$key]);
        }
        $this->assertSame($checkResult, $this->model->getFiles($theme, $filePath));
    }
 public function testGetFilesWrongAncestor()
 {
     $themePath = 'area/theme_path';
     $inputPath = '*.xml';
     $filePath = 'design/area/theme_path/Module_One/override/theme/vendor/parent_theme/1.xml';
     $expectedMessage = "Trying to override modular view file '{$filePath}' for theme 'vendor/parent_theme'" . ", which is not ancestor of theme 'vendor/theme_path'";
     $this->setExpectedException('Magento\\Framework\\Exception\\LocalizedException', $expectedMessage);
     $theme = $this->getMockForAbstractClass('Magento\\Framework\\View\\Design\\ThemeInterface');
     $theme->expects($this->once())->method('getFullPath')->willReturn($themePath);
     $theme->expects($this->once())->method('getParentTheme')->willReturn(null);
     $theme->expects($this->once())->method('getCode')->willReturn('vendor/theme_path');
     $this->themeDirectory->expects($this->once())->method('search')->with('*_*/override/theme/*/*/*.xml')->willReturn([$filePath]);
     $this->pathPatternHelperMock->expects($this->any())->method('translatePatternFromGlob')->with($inputPath)->willReturn('[^/]*\\.xml');
     $this->componentRegistrar->expects($this->once())->method('getPath')->with(ComponentRegistrar::THEME, $themePath)->will($this->returnValue('/full/theme/path'));
     $this->model->getFiles($theme, $inputPath);
 }
Esempio n. 3
0
    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]);
    }