Skip to content

Commit daf9f90

Browse files
committed
MAGETWO-91262: Fix static test to check files in the lib directory
1 parent 61814ad commit daf9f90

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

dev/tests/integration/testsuite/Magento/Test/Integrity/StaticFilesTest.php

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace Magento\Test\Integrity;
88

9+
use Magento\Framework\App\Filesystem\DirectoryList;
10+
911
/**
1012
* An integrity test that searches for references to static files and asserts that they are resolved via fallback
1113
*/
@@ -36,6 +38,24 @@ class StaticFilesTest extends \PHPUnit\Framework\TestCase
3638
*/
3739
private $baseTheme;
3840

41+
/**
42+
* @var \Magento\Framework\View\Design\FileResolution\Fallback\Resolver\Alternative
43+
*/
44+
private $alternativeResolver;
45+
46+
/**
47+
* Factory for simple rule
48+
*
49+
* @var \Magento\Framework\View\Design\Fallback\Rule\SimpleFactory
50+
*/
51+
private $simpleFactory;
52+
53+
/**
54+
* @var \Magento\Framework\Filesystem
55+
*/
56+
private $filesystem;
57+
58+
3959
protected function setUp()
4060
{
4161
$om = \Magento\TestFramework\Helper\Bootstrap::getObjectmanager();
@@ -46,6 +66,11 @@ protected function setUp()
4666
$this->themeRepo = $om->get(\Magento\Framework\View\Design\Theme\FlyweightFactory::class);
4767
$this->design = $om->get(\Magento\Framework\View\DesignInterface::class);
4868
$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
71+
);
72+
$this->simpleFactory = $om->get(\Magento\Framework\View\Design\Fallback\Rule\SimpleFactory::class);
73+
$this->filesystem = $om->get(\Magento\Framework\Filesystem::class);
4974
}
5075

5176
/**
@@ -93,8 +118,17 @@ public function testReferencesFromStaticFiles($area, $themePath, $locale, $modul
93118
$relatedPath = \Magento\Framework\View\FileSystem::getRelatedPath($filePath, $relatedResource);
94119
}
95120
// the $relatedPath will be suitable for feeding to the fallback system
121+
$staticFile = $this->getStaticFile($area, $themePath, $locale, $relatedPath, $fallbackModule);
122+
if (empty($staticFile) && substr($relatedPath, 0, 2) === '..') {
123+
//check if static file exists on lib level
124+
$path = substr($relatedPath, 2);
125+
$libDir = rtrim($this->filesystem->getDirectoryRead(DirectoryList::LIB_WEB)->getAbsolutePath(), '/');
126+
$rule = $this->simpleFactory->create(['pattern' => $libDir]);
127+
$params = ['area' => $area, 'theme' => $themePath, 'locale' => $locale];
128+
$staticFile = $this->alternativeResolver->resolveFile($rule, $path, $params);
129+
}
96130
$this->assertNotEmpty(
97-
$this->getStaticFile($area, $themePath, $locale, $relatedPath, $fallbackModule),
131+
$staticFile,
98132
"The related resource cannot be resolved through fallback: '{$relatedResource}'"
99133
);
100134
}
@@ -132,7 +166,7 @@ private function getDefaultThemePath($area)
132166
* @param bool $isExplicit
133167
* @return bool|string
134168
*/
135-
private function getStaticFile($area, $theme, $locale, $filePath, $module, $isExplicit = false)
169+
private function getStaticFile($area, $theme, $locale, $filePath, $module = null, $isExplicit = false)
136170
{
137171
if ($area == 'base') {
138172
$theme = $this->baseTheme;

0 commit comments

Comments
 (0)