Skip to content

Commit af5544f

Browse files
committed
MAGETWO-95628: Filesystem Directory Improvement
1 parent afc47a3 commit af5544f

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/UploaderTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ protected function setUp()
4646
$mediaPath = $appParams[DirectoryList::MEDIA][DirectoryList::PATH];
4747
$this->directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
4848
$tmpDir = $this->directory->getRelativePath($mediaPath . '/import');
49+
$this->directory->create($tmpDir);
4950
$this->uploader->setTmpDir($tmpDir);
5051

5152
parent::setUp();
@@ -79,4 +80,18 @@ public function testMoveWithInvalidFile()
7980

8081
$this->assertFalse($this->directory->isExist($this->uploader->getTmpDir() . '/' . $fileName));
8182
}
83+
84+
/**
85+
* @inheritdoc
86+
*/
87+
public static function tearDownAfterClass()
88+
{
89+
$filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
90+
->get(\Magento\Framework\Filesystem::class);
91+
/** @var \Magento\Framework\Filesystem\Directory\WriteInterface $directory */
92+
$directory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
93+
if ($directory->isExist('import')) {
94+
$directory->delete('import');
95+
}
96+
}
8297
}

dev/tests/integration/testsuite/Magento/Framework/App/Filesystem/DirectoryResolverTest.php

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

77
namespace Magento\Framework\App\Filesystem;
88

9+
use Magento\Framework\App\Filesystem\DirectoryList;
910
use Magento\TestFramework\Helper\Bootstrap;
1011

1112
/**
@@ -24,9 +25,9 @@ class DirectoryResolverTest extends \PHPUnit_Framework_TestCase
2425
private $directoryResolver;
2526

2627
/**
27-
* @var \Magento\Framework\Filesystem\Directory\WriteInterface
28+
* @var \Magento\Framework\Filesystem
2829
*/
29-
private $directory;
30+
private $filesystem;
3031

3132
/**
3233
* @inheritdoc
@@ -36,9 +37,7 @@ protected function setUp()
3637
$this->objectManager = Bootstrap::getObjectManager();
3738
$this->directoryResolver = $this->objectManager
3839
->create(\Magento\Framework\App\Filesystem\DirectoryResolver::class);
39-
/** @var \Magento\Framework\Filesystem $filesystem */
40-
$filesystem = $this->objectManager->create(\Magento\Framework\Filesystem::class);
41-
$this->directory = $filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA);
40+
$this->filesystem = $this->objectManager->create(\Magento\Framework\Filesystem::class);
4241
}
4342

4443
/**
@@ -47,10 +46,12 @@ protected function setUp()
4746
* @param bool $expectation
4847
* @dataProvider validatePathDataProvider
4948
* @magentoAppIsolation enabled
49+
* @return void
5050
*/
5151
public function testValidatePath($path, $directoryConfig, $expectation)
5252
{
53-
$path = $this->directory->getAbsolutePath($path);
53+
$directory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
54+
$path = $directory->getAbsolutePath() .'/' .$path;
5455
$this->assertEquals($expectation, $this->directoryResolver->validatePath($path, $directoryConfig));
5556
}
5657

@@ -60,7 +61,8 @@ public function testValidatePath($path, $directoryConfig, $expectation)
6061
*/
6162
public function testValidatePathWithException()
6263
{
63-
$path = $this->directory->getAbsolutePath();
64+
$directory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
65+
$path = $directory->getAbsolutePath();
6466
$this->directoryResolver->validatePath($path, 'wrong_dir');
6567
}
6668

@@ -76,7 +78,7 @@ public function validatePathDataProvider()
7678
true,
7779
],
7880
[
79-
'/../../pub/',
81+
'/../../pub/',
8082
DirectoryList::MEDIA,
8183
false,
8284
],

lib/internal/Magento/Framework/Filesystem/Directory/PathValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function validate(
5656
}
5757

5858
if (mb_strpos($actualPath, $realDirectoryPath) !== 0
59-
&& $path .DIRECTORY_SEPARATOR !== $realDirectoryPath
59+
&& $path . DIRECTORY_SEPARATOR !== $realDirectoryPath
6060
) {
6161
throw new ValidatorException(
6262
new Phrase(

0 commit comments

Comments
 (0)