Skip to content

Commit 732c065

Browse files
committed
MAGETWO-95628: Filesystem Directory Improvement
1 parent fd8f1db commit 732c065

File tree

4 files changed

+21
-32
lines changed

4 files changed

+21
-32
lines changed

dev/tests/integration/testsuite/Magento/Framework/Filesystem/Directory/ReadTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function testGetAbsolutePathOutside($path)
4646
{
4747
$dir = $this->getDirectoryInstance('foo');
4848

49-
$dir->getAbsolutePath($path);
49+
$dir->getAbsolutePath($path . '/ReadTest.php');
5050
}
5151

5252
/**
@@ -55,9 +55,9 @@ public function testGetAbsolutePathOutside($path)
5555
public function pathDataProvider()
5656
{
5757
return [
58-
['../../Directory/ReadTest.php'],
59-
['//./..///../Directory/ReadTest.php'],
60-
['\..\..\Directory\ReadTest.php'],
58+
['../../Directory'],
59+
['//./..///../Directory'],
60+
['\..\..\Directory'],
6161
];
6262
}
6363

@@ -83,7 +83,7 @@ public function testGetRelativePathOutside($path)
8383
{
8484
$dir = $this->getDirectoryInstance('foo');
8585

86-
$dir->getRelativePath(__DIR__ . $path);
86+
$dir->getRelativePath(__DIR__ . $path . '/ReadTest.php');
8787
}
8888

8989
/**
@@ -128,7 +128,7 @@ public function testReadOutside($path)
128128
{
129129
$dir = $this->getDirectoryInstance('foo');
130130

131-
$dir->read($path);
131+
$dir->read($path . '/ReadTest.php');
132132
}
133133

134134
/**
@@ -173,7 +173,7 @@ public function testSearchOutside($path)
173173
{
174174
$dir = $this->getDirectoryInstance('foo');
175175

176-
$dir->search('/*/*.txt', $path);
176+
$dir->search('/*/*.txt', $path . '/ReadTest.php');
177177
}
178178

179179
/**
@@ -211,7 +211,7 @@ public function testIsExistOutside($path)
211211
{
212212
$dir = $this->getDirectoryInstance('foo');
213213

214-
$dir->isExist($path);
214+
$dir->isExist($path . '/ReadTest.php');
215215
}
216216

217217
/**
@@ -294,7 +294,7 @@ public function testIsReadableOutside($path)
294294
{
295295
$dir = $this->getDirectoryInstance('foo');
296296

297-
$dir->isReadable($path);
297+
$dir->isReadable($path . '/ReadTest.php');
298298
}
299299

300300
/**
@@ -320,7 +320,7 @@ public function testIsFileOutside($path)
320320
{
321321
$dir = $this->getDirectoryInstance('foo');
322322

323-
$dir->isFile($path);
323+
$dir->isFile($path . '/ReadTest.php');
324324
}
325325

326326
/**
@@ -346,7 +346,7 @@ public function testIsDirectoryOutside($path)
346346
{
347347
$dir = $this->getDirectoryInstance('foo');
348348

349-
$dir->isDirectory($path);
349+
$dir->isDirectory($path . '/ReadTest.php');
350350
}
351351

352352
/**
@@ -400,7 +400,7 @@ public function testOpenFileOutside($path)
400400
{
401401
$dir = $this->getDirectoryInstance('foo');
402402

403-
$dir->openFile($path);
403+
$dir->openFile($path . '/ReadTest.php');
404404
}
405405

406406
/**
@@ -443,7 +443,7 @@ public function testReadFileOutside($path)
443443
{
444444
$dir = $this->getDirectoryInstance('foo');
445445

446-
$dir->readFile($path);
446+
$dir->readFile($path . '/ReadTest.php');
447447
}
448448

449449
/**

dev/tests/integration/testsuite/Magento/Framework/Filesystem/Directory/WriteTest.php

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,29 +65,17 @@ public function createProvider()
6565
}
6666

6767
/**
68+
* @param string $path
69+
*
6870
* @return void
71+
* @expectedException \Magento\Framework\Exception\ValidatorException
72+
* @dataProvider pathDataProvider
6973
*/
70-
public function testCreateOutside()
74+
public function testCreateOutside($path)
7175
{
72-
$exceptions = 0;
7376
$dir = $this->getDirectoryInstance('newDir1', 0777);
74-
try {
75-
$dir->create('../../outsideDir');
76-
} catch (ValidatorException $exception) {
77-
$exceptions++;
78-
}
79-
try {
80-
$dir->create('//./..///../outsideDir');
81-
} catch (ValidatorException $exception) {
82-
$exceptions++;
83-
}
84-
try {
85-
$dir->create('\..\..\outsideDir');
86-
} catch (ValidatorException $exception) {
87-
$exceptions++;
88-
}
8977

90-
$this->assertEquals(3, $exceptions);
78+
$dir->create($path);
9179
}
9280

9381
/**

lib/internal/Magento/Framework/Filesystem/Driver/File.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ public function getRealPathSafety($path)
939939

940940
//Removing redundant directory separators.
941941
$path = preg_replace(
942-
'/\\' . DIRECTORY_SEPARATOR .'\\' . DIRECTORY_SEPARATOR .'+/',
942+
'/\\' . DIRECTORY_SEPARATOR . '\\' . DIRECTORY_SEPARATOR . '+/',
943943
DIRECTORY_SEPARATOR,
944944
$path
945945
);

lib/internal/Magento/Framework/Test/Unit/Filesystem/Directory/PathValidatorTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public function testValidateWithoutAbsolutePath()
7979
/**
8080
* @return void
8181
* @expectedException \Magento\Framework\Exception\ValidatorException
82+
* @expectedExceptionMessageRegExp /^Path ".+/static/testFile.txt" cannot be used with directory ".+/pub/static/"$/
8283
*/
8384
public function testValidateWithWrongPath()
8485
{

0 commit comments

Comments
 (0)