25 private $explicitFallback;
45 private $alternativeResolver;
52 private $simpleFactory;
61 $om = \Magento\TestFramework\Helper\Bootstrap::getObjectmanager();
62 $this->fallback =
$om->get(\
Magento\Framework\View\Design\FileResolution\Fallback\StaticFile::class);
63 $this->explicitFallback =
$om->get(
64 \
Magento\Framework\View\Design\FileResolution\Fallback\Resolver\Simple::class
66 $this->themeRepo =
$om->get(\
Magento\Framework\View\Design\Theme\FlyweightFactory::class);
67 $this->design =
$om->get(\
Magento\Framework\View\DesignInterface::class);
68 $this->baseTheme =
$om->get(\
Magento\Framework\View\Design\ThemeInterface::class);
69 $this->alternativeResolver =
$om->get(
70 \
Magento\Framework\View\Design\FileResolution\Fallback\Resolver\Alternative::class
72 $this->simpleFactory =
$om->get(\
Magento\Framework\View\Design\Fallback\Rule\SimpleFactory::class);
73 $this->filesystem =
$om->get(\
Magento\Framework\Filesystem::class);
95 \
Magento\Framework\View\Url\CssResolver::REGEX_CSS_RELATIVE_URLS,
99 foreach ($matches[1] as $relatedResource) {
100 if (
false !== strpos($relatedResource,
'@')) {
103 list($relatedModule, $relatedPath) =
104 \Magento\Framework\View\Asset\Repository::extractModule($relatedResource);
105 if ($relatedModule) {
106 $fallbackModule = $relatedModule;
108 if (
'less' == pathinfo($filePath, PATHINFO_EXTENSION)) {
115 $this->markTestSkipped(
"Due to LESS library specifics, the '{$relatedResource}' cannot be tested.");
117 $fallbackModule = $module;
121 $staticFile = $this->getStaticFile($area, $themePath, $locale, $relatedPath, $fallbackModule);
122 if (empty($staticFile) && substr($relatedPath, 0, 2) ===
'..') {
124 $path = substr($relatedPath, 2);
126 $rule = $this->simpleFactory->create([
'pattern' => $libDir]);
127 $params = [
'area' => $area,
'theme' => $themePath,
'locale' => $locale];
130 $this->assertNotEmpty(
132 "The related resource cannot be resolved through fallback: '{$relatedResource}'" 144 private function getDefaultThemePath($area)
148 return $this->design->getConfigurationDesignTheme($area);
150 return 'Magento/backend';
152 return 'Magento/blank';
154 throw new \LogicException(
'Unable to determine theme path');
169 private function getStaticFile($area,
$theme, $locale, $filePath, $module =
null, $isExplicit =
false)
171 if ($area ==
'base') {
172 $theme = $this->baseTheme;
175 $themePath =
$theme ?: $this->getDefaultThemePath($area);
176 $theme = $this->themeRepo->create($themePath, $area);
180 return $this->explicitFallback->resolve(
$type, $filePath, $area,
$theme, $locale, $module);
182 return $this->fallback->getFile($area,
$theme, $locale, $filePath, $module);
190 return \Magento\Framework\App\Utility\Files::init()->getStaticPreProcessingFiles(
'*.{less,css}');
205 if (
false !== strpos($filePath,
'widgets.css')) {
208 $fileName = pathinfo($filePath, PATHINFO_FILENAME);
209 $dirName = dirname($filePath);
210 if (
'.' == $dirName) {
215 $cssPath = $dirName .
$fileName .
'.css';
216 $lessPath = $dirName .
$fileName .
'.less';
217 $cssFile = $this->getStaticFile($area, $themePath, $locale, $cssPath, $module,
true);
218 $lessFile = $this->getStaticFile($area, $themePath, $locale, $lessPath, $module,
true);
220 $cssFile && $lessFile,
221 "A resource file of only one type must exist. Both found: '$cssFile' and '$lessFile'" 230 return \Magento\Framework\App\Utility\Files::init()->getStaticPreProcessingFiles(
'*.{less,css}');
244 list($module, $filePath) = \Magento\Framework\View\Asset\Repository::extractModule($fileId);
245 $this->assertNotEmpty(
246 $this->getStaticFile($area, $themePath,
'en_US', $filePath, $module),
247 "Unable to locate '{$fileId}' reference from {$phtmlFile}" 258 list($area, $themePath, , , $file) =
$info;
259 foreach ($this->collectGetViewFileUrl($file) as $fileId) {
260 $result[] = [$file, $area, $themePath, $fileId];
272 private function collectGetViewFileUrl($file)
275 if (preg_match_all(
'/\$block->getViewFileUrl\(\'([^\']+?)\'\)/',
file_get_contents($file), $matches)) {
276 foreach ($matches[1] as $fileId) {
292 list($module, $filePath) = \Magento\Framework\View\Asset\Repository::extractModule($fileId);
293 $this->assertNotEmpty(
294 $this->getStaticFile($area, $themePath,
'en_US', $filePath, $module),
295 "Unable to locate '{$fileId}' reference from layout XML in {$layoutFile}" 306 foreach (
$files as $metaInfo) {
307 list($area, $themePath, , , $file) = $metaInfo;
308 foreach ($this->collectFileIdsFromLayout($file) as $fileId) {
309 $result[] = [$file, $area, $themePath, $fileId];
321 private function collectFileIdsFromLayout($file)
323 $xml = simplexml_load_file($file);
324 $elements = $xml->xpath(
'//head/css|link|script');
327 foreach ($elements as $node) {
referencesFromStaticFilesDataProvider()
referencesFromLayoutFilesDataProvider()
testReferencesFromStaticFiles($area, $themePath, $locale, $module, $filePath, $absolutePath)
testReferencesFromLayoutFiles($layoutFile, $area, $themePath, $fileId)
testReferencesFromPhtmlFiles($phtmlFile, $area, $themePath, $fileId)
referencesFromPhtmlFilesDataProvider()
lessNotConfusedWithCssDataProvider()
testLessNotConfusedWithCss($area, $themePath, $locale, $module, $filePath)
foreach( $_productCollection as $_product)() ?>" class $info
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
foreach($appDirs as $dir) $files
static getRelatedPath($relativeTo, $path)