Skip to content

Commit 5dd4fde

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-95628' into 2.1.16-develop-pr58
2 parents ad5f2e2 + e1a5489 commit 5dd4fde

File tree

15 files changed

+742
-25
lines changed

15 files changed

+742
-25
lines changed

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

Lines changed: 13 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,16 @@ 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+
$directory->delete('import');
94+
}
8295
}

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
],

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

Lines changed: 189 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
namespace Magento\Framework\Filesystem\Directory;
99

10+
use Magento\Framework\Exception\ValidatorException;
1011
use Magento\TestFramework\Helper\Bootstrap;
1112

1213
/**
@@ -34,13 +35,57 @@ public function testGetAbsolutePath()
3435
$this->assertContains('_files/foo/bar', $dir->getAbsolutePath('bar'));
3536
}
3637

38+
/**
39+
* @param string $path
40+
*
41+
* @return void
42+
* @expectedException \Magento\Framework\Exception\ValidatorException
43+
* @dataProvider pathDataProvider
44+
*/
45+
public function testGetAbsolutePathOutside($path)
46+
{
47+
$dir = $this->getDirectoryInstance('foo');
48+
49+
$dir->getAbsolutePath($path . '/ReadTest.php');
50+
}
51+
52+
/**
53+
* @return array
54+
*/
55+
public function pathDataProvider()
56+
{
57+
return [
58+
['../../Directory'],
59+
['//./..///../Directory'],
60+
['\..\..\Directory'],
61+
];
62+
}
63+
3764
public function testGetRelativePath()
3865
{
3966
$dir = $this->getDirectoryInstance('foo');
67+
$this->assertEquals(
68+
'file_three.txt',
69+
$dir->getRelativePath('file_three.txt')
70+
);
4071
$this->assertEquals('', $dir->getRelativePath());
4172
$this->assertEquals('bar', $dir->getRelativePath(__DIR__ . '/../_files/foo/bar'));
4273
}
4374

75+
/**
76+
* @param string $path
77+
*
78+
* @return void
79+
* @expectedException \Magento\Framework\Exception\ValidatorException
80+
* @dataProvider pathDataProvider
81+
*/
82+
public function testGetRelativePathOutside($path)
83+
{
84+
$dir = $this->getDirectoryInstance('foo');
85+
86+
$dir->getRelativePath(__DIR__ . $path . '/ReadTest.php');
87+
}
88+
4489
/**
4590
* Test for read method
4691
*
@@ -72,6 +117,20 @@ public function readProvider()
72117
];
73118
}
74119

120+
/**
121+
* @param string $path
122+
*
123+
* @return void
124+
* @expectedException \Magento\Framework\Exception\ValidatorException
125+
* @dataProvider pathDataProvider
126+
*/
127+
public function testReadOutside($path)
128+
{
129+
$dir = $this->getDirectoryInstance('foo');
130+
131+
$dir->read($path . '/ReadTest.php');
132+
}
133+
75134
/**
76135
* Test for search method
77136
*
@@ -103,6 +162,20 @@ public function searchProvider()
103162
];
104163
}
105164

165+
/**
166+
* @param string $path
167+
*
168+
* @return void
169+
* @expectedException \Magento\Framework\Exception\ValidatorException
170+
* @dataProvider pathDataProvider
171+
*/
172+
public function testSearchOutside($path)
173+
{
174+
$dir = $this->getDirectoryInstance('foo');
175+
176+
$dir->search('/*/*.txt', $path . '/ReadTest.php');
177+
}
178+
106179
/**
107180
* Test for isExist method
108181
*
@@ -127,6 +200,20 @@ public function existsProvider()
127200
return [['foo', 'bar', true], ['foo', 'bar/baz/', true], ['foo', 'bar/notexists', false]];
128201
}
129202

203+
/**
204+
* @param string $path
205+
*
206+
* @return void
207+
* @expectedException \Magento\Framework\Exception\ValidatorException
208+
* @dataProvider pathDataProvider
209+
*/
210+
public function testIsExistOutside($path)
211+
{
212+
$dir = $this->getDirectoryInstance('foo');
213+
214+
$dir->isExist($path . '/ReadTest.php');
215+
}
216+
130217
/**
131218
* Test for stat method
132219
*
@@ -168,6 +255,20 @@ public function statProvider()
168255
return [['foo', 'bar'], ['foo', 'file_three.txt']];
169256
}
170257

258+
/**
259+
* @param string $path
260+
*
261+
* @return void
262+
* @expectedException \Magento\Framework\Exception\ValidatorException
263+
* @dataProvider pathDataProvider
264+
*/
265+
public function testStatOutside($path)
266+
{
267+
$dir = $this->getDirectoryInstance('foo');
268+
269+
$dir->stat('bar/' . $path);
270+
}
271+
171272
/**
172273
* Test for isReadable method
173274
*
@@ -182,6 +283,20 @@ public function testIsReadable($dirPath, $path, $readable)
182283
$this->assertEquals($readable, $dir->isReadable($path));
183284
}
184285

286+
/**
287+
* @param string $path
288+
*
289+
* @return void
290+
* @expectedException \Magento\Framework\Exception\ValidatorException
291+
* @dataProvider pathDataProvider
292+
*/
293+
public function testIsReadableOutside($path)
294+
{
295+
$dir = $this->getDirectoryInstance('foo');
296+
297+
$dir->isReadable($path . '/ReadTest.php');
298+
}
299+
185300
/**
186301
* Test for isFile method
187302
*
@@ -194,6 +309,20 @@ public function testIsFile($path, $isFile)
194309
$this->assertEquals($isFile, $this->getDirectoryInstance('foo')->isFile($path));
195310
}
196311

312+
/**
313+
* @param string $path
314+
*
315+
* @return void
316+
* @expectedException \Magento\Framework\Exception\ValidatorException
317+
* @dataProvider pathDataProvider
318+
*/
319+
public function testIsFileOutside($path)
320+
{
321+
$dir = $this->getDirectoryInstance('foo');
322+
323+
$dir->isFile($path . '/ReadTest.php');
324+
}
325+
197326
/**
198327
* Test for isDirectory method
199328
*
@@ -206,6 +335,20 @@ public function testIsDirectory($path, $isDirectory)
206335
$this->assertEquals($isDirectory, $this->getDirectoryInstance('foo')->isDirectory($path));
207336
}
208337

338+
/**
339+
* @param string $path
340+
*
341+
* @return void
342+
* @expectedException \Magento\Framework\Exception\ValidatorException
343+
* @dataProvider pathDataProvider
344+
*/
345+
public function testIsDirectoryOutside($path)
346+
{
347+
$dir = $this->getDirectoryInstance('foo');
348+
349+
$dir->isDirectory($path . '/ReadTest.php');
350+
}
351+
209352
/**
210353
* Data provider for testIsReadable
211354
*
@@ -246,6 +389,20 @@ public function testOpenFile()
246389
$this->assertTrue($file instanceof \Magento\Framework\Filesystem\File\ReadInterface);
247390
}
248391

392+
/**
393+
* @param string $path
394+
*
395+
* @return void
396+
* @expectedException \Magento\Framework\Exception\ValidatorException
397+
* @dataProvider pathDataProvider
398+
*/
399+
public function testOpenFileOutside($path)
400+
{
401+
$dir = $this->getDirectoryInstance('foo');
402+
403+
$dir->openFile($path . '/ReadTest.php');
404+
}
405+
249406
/**
250407
* Test readFile
251408
*
@@ -268,10 +425,27 @@ public function readFileProvider()
268425
{
269426
return [
270427
['popup.csv', 'var myData = 5;'],
271-
['data.csv', '"field1", "field2"' . "\n" . '"field3", "field4"' . "\n"]
428+
[
429+
'data.csv',
430+
'"field1", "field2"' . PHP_EOL . '"field3", "field4"' . PHP_EOL,
431+
],
272432
];
273433
}
274434

435+
/**
436+
* @param string $path
437+
*
438+
* @return void
439+
* @expectedException \Magento\Framework\Exception\ValidatorException
440+
* @dataProvider pathDataProvider
441+
*/
442+
public function testReadFileOutside($path)
443+
{
444+
$dir = $this->getDirectoryInstance('foo');
445+
446+
$dir->readFile($path . '/ReadTest.php');
447+
}
448+
275449
/**
276450
* Get readable file instance
277451
* Get full path for files located in _files directory
@@ -301,4 +475,18 @@ public function testReadRecursively()
301475
sort($expected);
302476
$this->assertEquals($expected, $actual);
303477
}
478+
479+
/**
480+
* @param string $path
481+
*
482+
* @return void
483+
* @expectedException \Magento\Framework\Exception\ValidatorException
484+
* @dataProvider pathDataProvider
485+
*/
486+
public function testReadRecursivelyOutside($path)
487+
{
488+
$dir = $this->getDirectoryInstance('foo');
489+
490+
$dir->readRecursively($path);
491+
}
304492
}

0 commit comments

Comments
 (0)