Skip to content

Commit 962accf

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-95621' into 2.1.16-develop-pr59
2 parents 1e31242 + b4c2edc commit 962accf

File tree

2 files changed

+63
-24
lines changed

2 files changed

+63
-24
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::TEMPLATE_MINIFICATION_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: 50 additions & 19 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,30 @@ class ValidatorTest extends \PHPUnit_Framework_TestCase
6262
*/
6363
protected function setUp()
6464
{
65-
$this->_fileSystemMock = $this->getMock('\Magento\Framework\Filesystem', [], [], '', false);
66-
$this->_scopeConfigMock = $this->getMock('\Magento\Framework\App\Config\ScopeConfigInterface');
67-
$this->rootDirectoryMock = $this->getMock('\Magento\Framework\Filesystem\Directory\ReadInterface');
68-
$this->compiledDirectoryMock = $this->getMock('\Magento\Framework\Filesystem\Directory\ReadInterface');
65+
$this->fileSystemMock = $this->getMock(\Magento\Framework\Filesystem::class, [], [], '', false);
66+
$this->scopeConfigMock = $this->getMock(
67+
\Magento\Framework\App\Config\ScopeConfigInterface::class,
68+
[],
69+
[],
70+
'',
71+
false
72+
);
73+
$this->rootDirectoryMock = $this->getMock(
74+
\Magento\Framework\Filesystem\Directory\ReadInterface::class,
75+
[],
76+
[],
77+
'',
78+
false
79+
);
80+
$this->compiledDirectoryMock = $this->getMock(
81+
\Magento\Framework\Filesystem\Directory\ReadInterface::class,
82+
[],
83+
[],
84+
'',
85+
false
86+
);
6987

70-
$this->_fileSystemMock->expects($this->any())
88+
$this->fileSystemMock->expects($this->any())
7189
->method('getDirectoryRead')
7290
->will($this->returnValueMap(
7391
[
@@ -80,7 +98,13 @@ protected function setUp()
8098
->method('getAbsolutePath')
8199
->will($this->returnValue('/magento/var/compiled'));
82100

83-
$this->componentRegistrar = $this->getMock('Magento\Framework\Component\ComponentRegistrar', [], [], '', false);
101+
$this->componentRegistrar = $this->getMock(
102+
\Magento\Framework\Component\ComponentRegistrar::class,
103+
[],
104+
[],
105+
'',
106+
false
107+
);
84108
$this->componentRegistrar->expects($this->any())
85109
->method('getPaths')
86110
->will(
@@ -91,10 +115,18 @@ protected function setUp()
91115
]
92116
)
93117
);
94-
$this->_validator = new \Magento\Framework\View\Element\Template\File\Validator(
95-
$this->_fileSystemMock,
96-
$this->_scopeConfigMock,
97-
$this->componentRegistrar
118+
119+
$fileDriverMock = $this->getMock(\Magento\Framework\Filesystem\Driver\File::class);
120+
$fileDriverMock->expects($this->any())
121+
->method('getRealPath')
122+
->willReturnArgument(0);
123+
124+
$this->validator = new \Magento\Framework\View\Element\Template\File\Validator(
125+
$this->fileSystemMock,
126+
$this->scopeConfigMock,
127+
$this->componentRegistrar,
128+
null,
129+
$fileDriverMock
98130
);
99131
}
100132

@@ -103,23 +135,22 @@ protected function setUp()
103135
*
104136
* @param string $file
105137
* @param bool $expectedResult
106-
*
107-
* @dataProvider testIsValidDataProvider
108-
*
109138
* @return void
139+
*
140+
* @dataProvider isValidDataProvider
110141
*/
111142
public function testIsValid($file, $expectedResult)
112143
{
113144
$this->rootDirectoryMock->expects($this->any())->method('isFile')->will($this->returnValue(true));
114-
$this->assertEquals($expectedResult, $this->_validator->isValid($file));
145+
$this->assertEquals($expectedResult, $this->validator->isValid($file));
115146
}
116147

117148
/**
118149
* Data provider for testIsValid
119150
*
120-
* @return []
151+
* @return array
121152
*/
122-
public function testIsValidDataProvider()
153+
public function isValidDataProvider()
123154
{
124155
return [
125156
'empty' => ['', false],

0 commit comments

Comments
 (0)