20 private $themeDirectory;
35 private $readDirFactory;
40 private $componentRegistrar;
44 $this->themeDirectory = $this->createMock(\
Magento\Framework\
Filesystem\Directory\Read::class);
45 $this->themeDirectory->expects($this->any())
46 ->method(
'getAbsolutePath')
47 ->willReturnArgument(0);
48 $this->pathPatternHelperMock = $this->getMockBuilder(\
Magento\Framework\View\Helper\PathPattern::class)
49 ->disableOriginalConstructor()
52 $this->fileFactory = $this->createMock(\
Magento\Framework\View\
File\Factory::class);
53 $this->readDirFactory = $this->createMock(\
Magento\Framework\
Filesystem\Directory\ReadFactory::class);
54 $this->readDirFactory->expects($this->any())
56 ->will($this->returnValue($this->themeDirectory));
57 $this->componentRegistrar = $this->getMockForAbstractClass(
58 \
Magento\Framework\Component\ComponentRegistrarInterface::class
60 $this->model = new \Magento\Framework\View\File\Collector\Override\ThemeModular(
62 $this->readDirFactory,
63 $this->componentRegistrar,
64 $this->pathPatternHelperMock,
71 $this->componentRegistrar->expects($this->once())
73 ->will($this->returnValue(
''));
74 $theme = $this->getMockForAbstractClass(\
Magento\Framework\View\Design\ThemeInterface::class);
75 $theme->expects($this->once())
76 ->method(
'getFullPath')
77 ->will($this->returnValue(
'area/Vendor/theme'));
78 $this->assertSame([], $this->model->getFiles(
$theme,
''));
83 $themePath =
'area/theme_path';
85 $grandparentTheme = $this->getMockForAbstractClass(\
Magento\Framework\View\Design\ThemeInterface::class);
86 $grandparentTheme->expects($this->once())->method(
'getCode')->willReturn(
'vendor/grand_parent_theme');
88 $parentTheme = $this->getMockForAbstractClass(\
Magento\Framework\View\Design\ThemeInterface::class);
89 $parentTheme->expects($this->once())->method(
'getCode')->willReturn(
'vendor/parent_theme');
90 $parentTheme->expects($this->once())->method(
'getParentTheme')->willReturn($grandparentTheme);
92 $theme = $this->getMockForAbstractClass(\
Magento\Framework\View\Design\ThemeInterface::class);
93 $theme->expects($this->once())->method(
'getFullPath')->willReturn($themePath);
94 $theme->expects($this->once())->method(
'getParentTheme')->willReturn($parentTheme);
96 $filePathOne =
'design/area/theme_path/Module_One/override/theme/vendor/parent_theme/1.xml';
97 $filePathTwo =
'design/area/theme_path/Module_Two/override/theme/vendor/grand_parent_theme/2.xml';
98 $this->themeDirectory->expects($this->once())
100 ->with(
'*_*/override/theme/*/*/*.xml')
101 ->willReturn([$filePathOne, $filePathTwo]);
102 $this->pathPatternHelperMock->expects($this->any())
103 ->method(
'translatePatternFromGlob')
105 ->willReturn(
'[^/]*\\.xml');
107 $fileOne = $this->createMock(\
Magento\Framework\View\File::class);
108 $fileTwo = $this->createMock(\
Magento\Framework\View\File::class);
110 ->expects($this->exactly(2))
114 [$filePathOne,
'Module_One', $parentTheme,
false, $fileOne],
115 [$filePathTwo,
'Module_Two', $grandparentTheme,
false, $fileTwo],
118 $this->componentRegistrar->expects($this->once())
121 ->will($this->returnValue(
'/full/theme/path'));
123 $this->assertSame([$fileOne, $fileTwo], $this->model->getFiles(
$theme, $inputPath));
128 $themePath =
'area/theme_path';
129 $inputPath =
'preset/3.xml';
130 $grandparentTheme = $this->getMockForAbstractClass(\
Magento\Framework\View\Design\ThemeInterface::class);
131 $grandparentTheme->expects($this->once())->method(
'getCode')->willReturn(
'vendor/grand_parent_theme');
133 $parentTheme = $this->getMockForAbstractClass(\
Magento\Framework\View\Design\ThemeInterface::class);
134 $parentTheme->expects($this->once())->method(
'getCode')->willReturn(
'vendor/parent_theme');
135 $parentTheme->expects($this->once())->method(
'getParentTheme')->willReturn($grandparentTheme);
137 $theme = $this->getMockForAbstractClass(\
Magento\Framework\View\Design\ThemeInterface::class);
138 $theme->expects($this->once())->method(
'getFullPath')->willReturn($themePath);
139 $theme->expects($this->once())->method(
'getParentTheme')->willReturn($parentTheme);
141 $filePathOne =
'design/area/theme_path/Module_Two/override/theme/vendor/grand_parent_theme/preset/3.xml';
142 $this->themeDirectory->expects($this->once())
144 ->with(
'*_*/override/theme/*/*/preset/3.xml')
145 ->willReturn([$filePathOne]);
147 $fileOne = $this->createMock(\
Magento\Framework\View\File::class);
149 ->expects($this->once())
151 ->with($filePathOne,
'Module_Two', $grandparentTheme)
152 ->willReturn($fileOne);
153 $this->pathPatternHelperMock->expects($this->any())
154 ->method(
'translatePatternFromGlob')
156 ->willReturn(
'preset/3.xml');
157 $this->componentRegistrar->expects($this->once())
160 ->will($this->returnValue(
'/full/theme/path'));
162 $this->assertSame([$fileOne], $this->model->getFiles(
$theme, $inputPath));
167 $themePath =
'area/theme_path';
168 $inputPath =
'*.xml';
169 $filePath =
'design/area/theme_path/Module_One/override/theme/vendor/parent_theme/1.xml';
170 $expectedMessage =
"Trying to override modular view file '$filePath' for theme 'vendor/parent_theme'" 171 .
", which is not ancestor of theme 'vendor/theme_path'";
172 $this->expectException(\
Magento\Framework\Exception\LocalizedException::class);
173 $this->expectExceptionMessage($expectedMessage);
175 $theme = $this->getMockForAbstractClass(\
Magento\Framework\View\Design\ThemeInterface::class);
176 $theme->expects($this->once())->method(
'getFullPath')->willReturn($themePath);
177 $theme->expects($this->once())->method(
'getParentTheme')->willReturn(
null);
178 $theme->expects($this->once())->method(
'getCode')->willReturn(
'vendor/theme_path');
180 $this->themeDirectory->expects($this->once())
182 ->with(
'*_*/override/theme/*/*/*.xml')
183 ->willReturn([$filePath]);
184 $this->pathPatternHelperMock->expects($this->any())
185 ->method(
'translatePatternFromGlob')
187 ->willReturn(
'[^/]*\\.xml');
188 $this->componentRegistrar->expects($this->once())
191 ->will($this->returnValue(
'/full/theme/path'));
193 $this->model->getFiles(
$theme, $inputPath);
testGetFilesWrongAncestor()