Skip to content

Commit fa18a02

Browse files
committed
Merge remote-tracking branch 'obsessive-owls/MAGETWO-95620' into 2.3.0-qwerty-bugs
2 parents a2270eb + 0fc8a1f commit fa18a02

File tree

2 files changed

+34
-19
lines changed

2 files changed

+34
-19
lines changed

lib/internal/Magento/Framework/View/Element/Template/File/Validator.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
use \Magento\Framework\App\Filesystem\DirectoryList;
99
use Magento\Framework\Component\ComponentRegistrar;
10+
use \Magento\Framework\Filesystem\Driver\File as FileDriver;
1011

1112
/**
1213
* Class Validator
13-
* @package Magento\Framework\View\Element\Template\File
1414
*/
1515
class Validator
1616
{
@@ -68,26 +68,34 @@ class Validator
6868
*/
6969
protected $_compiledDir;
7070

71+
/**
72+
* @var FileDriver
73+
*/
74+
private $fileDriver;
75+
7176
/**
7277
* Class constructor
7378
*
7479
* @param \Magento\Framework\Filesystem $filesystem
7580
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfigInterface
7681
* @param ComponentRegistrar $componentRegistrar
7782
* @param string|null $scope
83+
* @param FileDriver|null $fileDriver
7884
*/
7985
public function __construct(
8086
\Magento\Framework\Filesystem $filesystem,
8187
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfigInterface,
8288
ComponentRegistrar $componentRegistrar,
83-
$scope = null
89+
$scope = null,
90+
?FileDriver $fileDriver = null
8491
) {
8592
$this->_filesystem = $filesystem;
8693
$this->_isAllowSymlinks = $scopeConfigInterface->getValue(self::XML_PATH_TEMPLATE_ALLOW_SYMLINK, $scope);
8794
$this->_themesDir = $componentRegistrar->getPaths(ComponentRegistrar::THEME);
8895
$this->moduleDirs = $componentRegistrar->getPaths(ComponentRegistrar::MODULE);
8996
$this->_compiledDir = $this->_filesystem->getDirectoryRead(DirectoryList::TMP_MATERIALIZATION_DIR)
9097
->getAbsolutePath();
98+
$this->fileDriver = $fileDriver ?: \Magento\Framework\App\ObjectManager::getInstance()->get(FileDriver::class);
9199
}
92100

93101
/**
@@ -128,7 +136,7 @@ protected function isPathInDirectories($path, $directories)
128136
$directories = (array)$directories;
129137
}
130138
foreach ($directories as $directory) {
131-
if (0 === strpos($path, $directory)) {
139+
if (0 === strpos($this->fileDriver->getRealPath($path), $directory)) {
132140
return true;
133141
}
134142
}

lib/internal/Magento/Framework/View/Test/Unit/Element/Template/File/ValidatorTest.php

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ class ValidatorTest extends \PHPUnit\Framework\TestCase
2020
*
2121
* @var \Magento\Framework\View\Element\Template\File\Validator
2222
*/
23-
private $_validator;
23+
private $validator;
2424

2525
/**
2626
* Mock for view file system
2727
*
2828
* @var \Magento\Framework\FileSystem|\PHPUnit_Framework_MockObject_MockObject
2929
*/
30-
private $_fileSystemMock;
30+
private $fileSystemMock;
3131

3232
/**
3333
* Mock for scope config
3434
*
3535
* @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
3636
*/
37-
private $_scopeConfigMock;
37+
private $scopeConfigMock;
3838

3939
/**
4040
* Mock for root directory reader
@@ -62,12 +62,12 @@ class ValidatorTest extends \PHPUnit\Framework\TestCase
6262
*/
6363
protected function setUp()
6464
{
65-
$this->_fileSystemMock = $this->createMock(\Magento\Framework\Filesystem::class);
66-
$this->_scopeConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
65+
$this->fileSystemMock = $this->createMock(\Magento\Framework\Filesystem::class);
66+
$this->scopeConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
6767
$this->rootDirectoryMock = $this->createMock(\Magento\Framework\Filesystem\Directory\ReadInterface::class);
6868
$this->compiledDirectoryMock = $this->createMock(\Magento\Framework\Filesystem\Directory\ReadInterface::class);
6969

70-
$this->_fileSystemMock->expects($this->any())
70+
$this->fileSystemMock->expects($this->any())
7171
->method('getDirectoryRead')
7272
->will($this->returnValueMap(
7373
[
@@ -91,10 +91,18 @@ protected function setUp()
9191
]
9292
)
9393
);
94-
$this->_validator = new \Magento\Framework\View\Element\Template\File\Validator(
95-
$this->_fileSystemMock,
96-
$this->_scopeConfigMock,
97-
$this->componentRegistrar
94+
95+
$fileDriverMock = $this->createMock(\Magento\Framework\Filesystem\Driver\File::class);
96+
$fileDriverMock->expects($this->any())
97+
->method('getRealPath')
98+
->willReturnArgument(0);
99+
100+
$this->validator = new \Magento\Framework\View\Element\Template\File\Validator(
101+
$this->fileSystemMock,
102+
$this->scopeConfigMock,
103+
$this->componentRegistrar,
104+
null,
105+
$fileDriverMock
98106
);
99107
}
100108

@@ -103,23 +111,22 @@ protected function setUp()
103111
*
104112
* @param string $file
105113
* @param bool $expectedResult
106-
*
107-
* @dataProvider testIsValidDataProvider
108-
*
109114
* @return void
115+
*
116+
* @dataProvider isValidDataProvider
110117
*/
111118
public function testIsValid($file, $expectedResult)
112119
{
113120
$this->rootDirectoryMock->expects($this->any())->method('isFile')->will($this->returnValue(true));
114-
$this->assertEquals($expectedResult, $this->_validator->isValid($file));
121+
$this->assertEquals($expectedResult, $this->validator->isValid($file));
115122
}
116123

117124
/**
118125
* Data provider for testIsValid
119126
*
120-
* @return []
127+
* @return array
121128
*/
122-
public function testIsValidDataProvider()
129+
public function isValidDataProvider()
123130
{
124131
return [
125132
'empty' => ['', false],

0 commit comments

Comments
 (0)