Skip to content

Commit a330532

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-95622' into 2.2.7-develop-pr53
2 parents 5b1b70d + 8110949 commit a330532

File tree

2 files changed

+47
-35
lines changed

2 files changed

+47
-35
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
*/
66
namespace Magento\Framework\View\Element\Template\File;
77

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

1112
/**
12-
* Class Validator
13-
* @package Magento\Framework\View\Element\Template\File
13+
* Class Validator.
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: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,40 @@
1010
use \Magento\Framework\Filesystem\DriverPool;
1111

1212
/**
13-
* Class ValidatorTest
14-
* @package Magento\Framework\View\Test\Unit\Element\Template\File
13+
* Tests for Magento\Framework\View\Element\Template\File\Validator class.
1514
*/
1615
class ValidatorTest extends \PHPUnit\Framework\TestCase
1716
{
1817
/**
19-
* Resolver object
18+
* Resolver object.
2019
*
2120
* @var \Magento\Framework\View\Element\Template\File\Validator
2221
*/
23-
private $_validator;
22+
private $validator;
2423

2524
/**
26-
* Mock for view file system
25+
* Mock for view file system.
2726
*
2827
* @var \Magento\Framework\FileSystem|\PHPUnit_Framework_MockObject_MockObject
2928
*/
30-
private $_fileSystemMock;
29+
private $fileSystemMock;
3130

3231
/**
33-
* Mock for scope config
32+
* Mock for scope config.
3433
*
3534
* @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
3635
*/
37-
private $_scopeConfigMock;
36+
private $scopeConfigMock;
3837

3938
/**
40-
* Mock for root directory reader
39+
* Mock for root directory reader.
4140
*
4241
* @var \Magento\Framework\Filesystem\Directory\ReadInterface|\PHPUnit_Framework_MockObject_MockObject
4342
*/
4443
private $rootDirectoryMock;
4544

4645
/**
47-
* Mock for compiled directory reader
46+
* Mock for compiled directory reader.
4847
*
4948
* @var \Magento\Framework\Filesystem\Directory\ReadInterface|\PHPUnit_Framework_MockObject_MockObject
5049
*/
@@ -56,18 +55,16 @@ class ValidatorTest extends \PHPUnit\Framework\TestCase
5655
private $componentRegistrar;
5756

5857
/**
59-
* Test Setup
60-
*
61-
* @return void
58+
* @inheritdoc
6259
*/
6360
protected function setUp()
6461
{
65-
$this->_fileSystemMock = $this->createMock(\Magento\Framework\Filesystem::class);
66-
$this->_scopeConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
62+
$this->fileSystemMock = $this->createMock(\Magento\Framework\Filesystem::class);
63+
$this->scopeConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
6764
$this->rootDirectoryMock = $this->createMock(\Magento\Framework\Filesystem\Directory\ReadInterface::class);
6865
$this->compiledDirectoryMock = $this->createMock(\Magento\Framework\Filesystem\Directory\ReadInterface::class);
6966

70-
$this->_fileSystemMock->expects($this->any())
67+
$this->fileSystemMock->expects($this->any())
7168
->method('getDirectoryRead')
7269
->will($this->returnValueMap(
7370
[
@@ -87,39 +84,46 @@ protected function setUp()
8784
$this->returnValueMap(
8885
[
8986
[ComponentRegistrar::MODULE, ['/magento/app/code/Some/Module']],
90-
[ComponentRegistrar::THEME, ['/magento/themes/default']]
87+
[ComponentRegistrar::THEME, ['/magento/themes/default']],
9188
]
9289
)
9390
);
94-
$this->_validator = new \Magento\Framework\View\Element\Template\File\Validator(
95-
$this->_fileSystemMock,
96-
$this->_scopeConfigMock,
97-
$this->componentRegistrar
91+
92+
$fileDriverMock = $this->createMock(\Magento\Framework\Filesystem\Driver\File::class);
93+
$fileDriverMock->expects($this->any())
94+
->method('getRealPath')
95+
->willReturnArgument(0);
96+
97+
$this->validator = new \Magento\Framework\View\Element\Template\File\Validator(
98+
$this->fileSystemMock,
99+
$this->scopeConfigMock,
100+
$this->componentRegistrar,
101+
null,
102+
$fileDriverMock
98103
);
99104
}
100105

101106
/**
102-
* Test is file valid
107+
* Test is file valid.
103108
*
104109
* @param string $file
105110
* @param bool $expectedResult
106-
*
107-
* @dataProvider testIsValidDataProvider
108-
*
109111
* @return void
112+
*
113+
* @dataProvider isValidDataProvider
110114
*/
111-
public function testIsValid($file, $expectedResult)
115+
public function testIsValid(string $file, bool $expectedResult)
112116
{
113117
$this->rootDirectoryMock->expects($this->any())->method('isFile')->will($this->returnValue(true));
114-
$this->assertEquals($expectedResult, $this->_validator->isValid($file));
118+
$this->assertEquals($expectedResult, $this->validator->isValid($file));
115119
}
116120

117121
/**
118-
* Data provider for testIsValid
122+
* Data provider for testIsValid.
119123
*
120-
* @return []
124+
* @return array
121125
*/
122-
public function testIsValidDataProvider()
126+
public function isValidDataProvider() : array
123127
{
124128
return [
125129
'empty' => ['', false],

0 commit comments

Comments
 (0)