Skip to content

Commit a18f0ce

Browse files
Merge MC-31652 into 2.4-bugfixes-100620
2 parents e3d07b3 + c82ced1 commit a18f0ce

File tree

2 files changed

+121
-16
lines changed
  • dev/tests/integration/testsuite/Magento/Framework/Filesystem/Directory
  • lib/internal/Magento/Framework/Filesystem/Directory

2 files changed

+121
-16
lines changed

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

Lines changed: 97 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77
*/
88
namespace Magento\Framework\Filesystem\Directory;
99

10+
use Magento\Framework\Exception\FileSystemException;
1011
use Magento\Framework\Exception\ValidatorException;
1112
use Magento\Framework\Filesystem\DriverPool;
1213
use Magento\TestFramework\Helper\Bootstrap;
14+
use PHPUnit\Framework\TestCase;
1315

1416
/**
1517
* Class ReadTest
1618
* Test for Magento\Framework\Filesystem\Directory\Read class
1719
*/
18-
class WriteTest extends \PHPUnit\Framework\TestCase
20+
class WriteTest extends TestCase
1921
{
2022
/**
2123
* Test data to be cleaned
@@ -41,6 +43,8 @@ public function testInstance()
4143
* @param string $basePath
4244
* @param int $permissions
4345
* @param string $path
46+
* @throws FileSystemException
47+
* @throws ValidatorException
4448
*/
4549
public function testCreate($basePath, $permissions, $path)
4650
{
@@ -64,6 +68,11 @@ public function createProvider()
6468
];
6569
}
6670

71+
/**
72+
* Test for create outside
73+
*
74+
* @throws FileSystemException
75+
*/
6776
public function testCreateOutside()
6877
{
6978
$exceptions = 0;
@@ -91,6 +100,8 @@ public function testCreateOutside()
91100
*
92101
* @dataProvider deleteProvider
93102
* @param string $path
103+
* @throws FileSystemException
104+
* @throws ValidatorException
94105
*/
95106
public function testDelete($path)
96107
{
@@ -111,6 +122,11 @@ public function deleteProvider()
111122
return [['subdir'], ['subdir/subsubdir']];
112123
}
113124

125+
/**
126+
* Test for delete outside
127+
*
128+
* @throws FileSystemException
129+
*/
114130
public function testDeleteOutside()
115131
{
116132
$exceptions = 0;
@@ -141,6 +157,8 @@ public function testDeleteOutside()
141157
* @param int $permissions
142158
* @param string $name
143159
* @param string $newName
160+
* @throws FileSystemException
161+
* @throws ValidatorException
144162
*/
145163
public function testRename($basePath, $permissions, $name, $newName)
146164
{
@@ -164,6 +182,11 @@ public function renameProvider()
164182
return [['newDir1', 0777, 'first_name.txt', 'second_name.txt']];
165183
}
166184

185+
/**
186+
* Test for rename outside
187+
*
188+
* @throws FileSystemException
189+
*/
167190
public function testRenameOutside()
168191
{
169192
$exceptions = 0;
@@ -198,6 +221,8 @@ public function testRenameOutside()
198221
* @param int $permission
199222
* @param string $name
200223
* @param string $newName
224+
* @throws FileSystemException
225+
* @throws ValidatorException
201226
*/
202227
public function testRenameTargetDir($firstDir, $secondDir, $permission, $name, $newName)
203228
{
@@ -231,6 +256,8 @@ public function renameTargetDirProvider()
231256
* @param int $permissions
232257
* @param string $name
233258
* @param string $newName
259+
* @throws ValidatorException
260+
* @throws FileSystemException
234261
*/
235262
public function testCopy($basePath, $permissions, $name, $newName)
236263
{
@@ -255,6 +282,11 @@ public function copyProvider()
255282
];
256283
}
257284

285+
/**
286+
* Test for copy outside
287+
*
288+
* @throws FileSystemException|ValidatorException
289+
*/
258290
public function testCopyOutside()
259291
{
260292
$exceptions = 0;
@@ -298,6 +330,8 @@ public function testCopyOutside()
298330
* @param int $permission
299331
* @param string $name
300332
* @param string $newName
333+
* @throws FileSystemException
334+
* @throws ValidatorException
301335
*/
302336
public function testCopyTargetDir($firstDir, $secondDir, $permission, $name, $newName)
303337
{
@@ -327,6 +361,8 @@ public function copyTargetDirProvider()
327361

328362
/**
329363
* Test for changePermissions method
364+
*
365+
* @throws FileSystemException|ValidatorException
330366
*/
331367
public function testChangePermissions()
332368
{
@@ -335,6 +371,11 @@ public function testChangePermissions()
335371
$this->assertTrue($directory->changePermissions('test_directory', 0644));
336372
}
337373

374+
/**
375+
* Test for changePermissions outside
376+
*
377+
* @throws FileSystemException
378+
*/
338379
public function testChangePermissionsOutside()
339380
{
340381
$exceptions = 0;
@@ -359,6 +400,8 @@ public function testChangePermissionsOutside()
359400

360401
/**
361402
* Test for changePermissionsRecursively method
403+
*
404+
* @throws FileSystemException|ValidatorException
362405
*/
363406
public function testChangePermissionsRecursively()
364407
{
@@ -370,6 +413,11 @@ public function testChangePermissionsRecursively()
370413
$this->assertTrue($directory->changePermissionsRecursively('test_directory', 0777, 0644));
371414
}
372415

416+
/**
417+
* Test for changePermissionsRecursively outside
418+
*
419+
* @throws FileSystemException
420+
*/
373421
public function testChangePermissionsRecursivelyOutside()
374422
{
375423
$exceptions = 0;
@@ -400,6 +448,8 @@ public function testChangePermissionsRecursivelyOutside()
400448
* @param int $permissions
401449
* @param string $path
402450
* @param int $time
451+
* @throws FileSystemException
452+
* @throws ValidatorException
403453
*/
404454
public function testTouch($basePath, $permissions, $path, $time)
405455
{
@@ -422,6 +472,11 @@ public function touchProvider()
422472
];
423473
}
424474

475+
/**
476+
* Test for touch outside
477+
*
478+
* @throws FileSystemException
479+
*/
425480
public function testTouchOutside()
426481
{
427482
$exceptions = 0;
@@ -446,6 +501,8 @@ public function testTouchOutside()
446501

447502
/**
448503
* Test isWritable method
504+
*
505+
* @throws FileSystemException|ValidatorException
449506
*/
450507
public function testIsWritable()
451508
{
@@ -455,6 +512,11 @@ public function testIsWritable()
455512
$this->assertTrue($directory->isWritable('bar'));
456513
}
457514

515+
/**
516+
* Test isWritable method outside
517+
*
518+
* @throws FileSystemException
519+
*/
458520
public function testIsWritableOutside()
459521
{
460522
$exceptions = 0;
@@ -485,6 +547,8 @@ public function testIsWritableOutside()
485547
* @param int $permissions
486548
* @param string $path
487549
* @param string $mode
550+
* @throws FileSystemException
551+
* @throws ValidatorException
488552
*/
489553
public function testOpenFile($basePath, $permissions, $path, $mode)
490554
{
@@ -507,6 +571,11 @@ public function openFileProvider()
507571
];
508572
}
509573

574+
/**
575+
* Test for openFile outside
576+
*
577+
* @throws FileSystemException
578+
*/
510579
public function testOpenFileOutside()
511580
{
512581
$exceptions = 0;
@@ -536,6 +605,8 @@ public function testOpenFileOutside()
536605
* @param string $path
537606
* @param string $content
538607
* @param string $extraContent
608+
* @throws FileSystemException
609+
* @throws ValidatorException
539610
*/
540611
public function testWriteFile($path, $content, $extraContent)
541612
{
@@ -553,6 +624,8 @@ public function testWriteFile($path, $content, $extraContent)
553624
* @param string $path
554625
* @param string $content
555626
* @param string $extraContent
627+
* @throws FileSystemException
628+
* @throws ValidatorException
556629
*/
557630
public function testWriteFileAppend($path, $content, $extraContent)
558631
{
@@ -573,6 +646,11 @@ public function writeFileProvider()
573646
return [['file1', '123', '456'], ['folder1/file1', '123', '456']];
574647
}
575648

649+
/**
650+
* Test for writeFile outside
651+
*
652+
* @throws FileSystemException
653+
*/
576654
public function testWriteFileOutside()
577655
{
578656
$exceptions = 0;
@@ -595,8 +673,24 @@ public function testWriteFileOutside()
595673
$this->assertEquals(3, $exceptions);
596674
}
597675

676+
/**
677+
* Test for invalidDeletePath
678+
*
679+
* @throws ValidatorException
680+
*/
681+
public function testInvalidDeletePath()
682+
{
683+
$this->expectException(FileSystemException::class);
684+
$directory = $this->getDirectoryInstance('newDir', 0777);
685+
$invalidPath = 'invalidPath/../';
686+
$directory->create($invalidPath);
687+
$directory->delete($invalidPath);
688+
}
689+
598690
/**
599691
* Tear down
692+
*
693+
* @throws ValidatorException|FileSystemException
600694
*/
601695
protected function tearDown(): void
602696
{
@@ -620,8 +714,8 @@ private function getDirectoryInstance($path, $permissions)
620714
{
621715
$fullPath = __DIR__ . '/../_files/' . $path;
622716
$objectManager = Bootstrap::getObjectManager();
623-
/** @var \Magento\Framework\Filesystem\Directory\WriteFactory $directoryFactory */
624-
$directoryFactory = $objectManager->create(\Magento\Framework\Filesystem\Directory\WriteFactory::class);
717+
/** @var WriteFactory $directoryFactory */
718+
$directoryFactory = $objectManager->create(WriteFactory::class);
625719
$directory = $directoryFactory->create($fullPath, DriverPool::FILE, $permissions);
626720
$this->testDirectories[] = $directory;
627721
return $directory;

0 commit comments

Comments
 (0)