7
7
*/
8
8
namespace Magento \Framework \Filesystem \Directory ;
9
9
10
+ use Magento \Framework \Exception \FileSystemException ;
10
11
use Magento \Framework \Exception \ValidatorException ;
11
12
use Magento \Framework \Filesystem \DriverPool ;
12
13
use Magento \TestFramework \Helper \Bootstrap ;
14
+ use PHPUnit \Framework \TestCase ;
13
15
14
16
/**
15
17
* Class ReadTest
16
18
* Test for Magento\Framework\Filesystem\Directory\Read class
17
19
*/
18
- class WriteTest extends \ PHPUnit \ Framework \ TestCase
20
+ class WriteTest extends TestCase
19
21
{
20
22
/**
21
23
* Test data to be cleaned
@@ -41,6 +43,8 @@ public function testInstance()
41
43
* @param string $basePath
42
44
* @param int $permissions
43
45
* @param string $path
46
+ * @throws FileSystemException
47
+ * @throws ValidatorException
44
48
*/
45
49
public function testCreate ($ basePath , $ permissions , $ path )
46
50
{
@@ -64,6 +68,11 @@ public function createProvider()
64
68
];
65
69
}
66
70
71
+ /**
72
+ * Test for create outside
73
+ *
74
+ * @throws FileSystemException
75
+ */
67
76
public function testCreateOutside ()
68
77
{
69
78
$ exceptions = 0 ;
@@ -91,6 +100,8 @@ public function testCreateOutside()
91
100
*
92
101
* @dataProvider deleteProvider
93
102
* @param string $path
103
+ * @throws FileSystemException
104
+ * @throws ValidatorException
94
105
*/
95
106
public function testDelete ($ path )
96
107
{
@@ -111,6 +122,11 @@ public function deleteProvider()
111
122
return [['subdir ' ], ['subdir/subsubdir ' ]];
112
123
}
113
124
125
+ /**
126
+ * Test for delete outside
127
+ *
128
+ * @throws FileSystemException
129
+ */
114
130
public function testDeleteOutside ()
115
131
{
116
132
$ exceptions = 0 ;
@@ -141,6 +157,8 @@ public function testDeleteOutside()
141
157
* @param int $permissions
142
158
* @param string $name
143
159
* @param string $newName
160
+ * @throws FileSystemException
161
+ * @throws ValidatorException
144
162
*/
145
163
public function testRename ($ basePath , $ permissions , $ name , $ newName )
146
164
{
@@ -164,6 +182,11 @@ public function renameProvider()
164
182
return [['newDir1 ' , 0777 , 'first_name.txt ' , 'second_name.txt ' ]];
165
183
}
166
184
185
+ /**
186
+ * Test for rename outside
187
+ *
188
+ * @throws FileSystemException
189
+ */
167
190
public function testRenameOutside ()
168
191
{
169
192
$ exceptions = 0 ;
@@ -198,6 +221,8 @@ public function testRenameOutside()
198
221
* @param int $permission
199
222
* @param string $name
200
223
* @param string $newName
224
+ * @throws FileSystemException
225
+ * @throws ValidatorException
201
226
*/
202
227
public function testRenameTargetDir ($ firstDir , $ secondDir , $ permission , $ name , $ newName )
203
228
{
@@ -231,6 +256,8 @@ public function renameTargetDirProvider()
231
256
* @param int $permissions
232
257
* @param string $name
233
258
* @param string $newName
259
+ * @throws FileSystemException
260
+ * @throws ValidatorException
234
261
*/
235
262
public function testCopy ($ basePath , $ permissions , $ name , $ newName )
236
263
{
@@ -255,6 +282,12 @@ public function copyProvider()
255
282
];
256
283
}
257
284
285
+ /**
286
+ * Test for copy outside
287
+ *
288
+ * @throws FileSystemException
289
+ * @throws ValidatorException
290
+ */
258
291
public function testCopyOutside ()
259
292
{
260
293
$ exceptions = 0 ;
@@ -298,6 +331,8 @@ public function testCopyOutside()
298
331
* @param int $permission
299
332
* @param string $name
300
333
* @param string $newName
334
+ * @throws FileSystemException
335
+ * @throws ValidatorException
301
336
*/
302
337
public function testCopyTargetDir ($ firstDir , $ secondDir , $ permission , $ name , $ newName )
303
338
{
@@ -327,6 +362,8 @@ public function copyTargetDirProvider()
327
362
328
363
/**
329
364
* Test for changePermissions method
365
+ *
366
+ * @throws FileSystemException|ValidatorException
330
367
*/
331
368
public function testChangePermissions ()
332
369
{
@@ -335,6 +372,11 @@ public function testChangePermissions()
335
372
$ this ->assertTrue ($ directory ->changePermissions ('test_directory ' , 0644 ));
336
373
}
337
374
375
+ /**
376
+ * Test change permissions outside
377
+ *
378
+ * @throws FileSystemException
379
+ */
338
380
public function testChangePermissionsOutside ()
339
381
{
340
382
$ exceptions = 0 ;
@@ -359,6 +401,8 @@ public function testChangePermissionsOutside()
359
401
360
402
/**
361
403
* Test for changePermissionsRecursively method
404
+ *
405
+ * @throws FileSystemException|ValidatorException
362
406
*/
363
407
public function testChangePermissionsRecursively ()
364
408
{
@@ -370,6 +414,11 @@ public function testChangePermissionsRecursively()
370
414
$ this ->assertTrue ($ directory ->changePermissionsRecursively ('test_directory ' , 0777 , 0644 ));
371
415
}
372
416
417
+ /**
418
+ * Test writable for outside
419
+ *
420
+ * @throws FileSystemException
421
+ */
373
422
public function testChangePermissionsRecursivelyOutside ()
374
423
{
375
424
$ exceptions = 0 ;
@@ -400,6 +449,8 @@ public function testChangePermissionsRecursivelyOutside()
400
449
* @param int $permissions
401
450
* @param string $path
402
451
* @param int $time
452
+ * @throws FileSystemException
453
+ * @throws ValidatorException
403
454
*/
404
455
public function testTouch ($ basePath , $ permissions , $ path , $ time )
405
456
{
@@ -422,6 +473,11 @@ public function touchProvider()
422
473
];
423
474
}
424
475
476
+ /**
477
+ * Test touch for outside
478
+ *
479
+ * @throws FileSystemException
480
+ */
425
481
public function testTouchOutside ()
426
482
{
427
483
$ exceptions = 0 ;
@@ -446,6 +502,8 @@ public function testTouchOutside()
446
502
447
503
/**
448
504
* Test isWritable method
505
+ *
506
+ * @throws FileSystemException|ValidatorException
449
507
*/
450
508
public function testIsWritable ()
451
509
{
@@ -455,6 +513,11 @@ public function testIsWritable()
455
513
$ this ->assertTrue ($ directory ->isWritable ('bar ' ));
456
514
}
457
515
516
+ /**
517
+ * Test writable for outside
518
+ *
519
+ * @throws FileSystemException
520
+ */
458
521
public function testIsWritableOutside ()
459
522
{
460
523
$ exceptions = 0 ;
@@ -485,6 +548,8 @@ public function testIsWritableOutside()
485
548
* @param int $permissions
486
549
* @param string $path
487
550
* @param string $mode
551
+ * @throws FileSystemException
552
+ * @throws ValidatorException
488
553
*/
489
554
public function testOpenFile ($ basePath , $ permissions , $ path , $ mode )
490
555
{
@@ -507,6 +572,11 @@ public function openFileProvider()
507
572
];
508
573
}
509
574
575
+ /**
576
+ * Test open file outside
577
+ *
578
+ * @throws FileSystemException
579
+ */
510
580
public function testOpenFileOutside ()
511
581
{
512
582
$ exceptions = 0 ;
@@ -536,6 +606,8 @@ public function testOpenFileOutside()
536
606
* @param string $path
537
607
* @param string $content
538
608
* @param string $extraContent
609
+ * @throws FileSystemException
610
+ * @throws ValidatorException
539
611
*/
540
612
public function testWriteFile ($ path , $ content , $ extraContent )
541
613
{
@@ -553,6 +625,8 @@ public function testWriteFile($path, $content, $extraContent)
553
625
* @param string $path
554
626
* @param string $content
555
627
* @param string $extraContent
628
+ * @throws FileSystemException
629
+ * @throws ValidatorException
556
630
*/
557
631
public function testWriteFileAppend ($ path , $ content , $ extraContent )
558
632
{
@@ -573,6 +647,11 @@ public function writeFileProvider()
573
647
return [['file1 ' , '123 ' , '456 ' ], ['folder1/file1 ' , '123 ' , '456 ' ]];
574
648
}
575
649
650
+ /**
651
+ * Test writing file to outside
652
+ *
653
+ * @throws FileSystemException
654
+ */
576
655
public function testWriteFileOutside ()
577
656
{
578
657
$ exceptions = 0 ;
@@ -595,8 +674,25 @@ public function testWriteFileOutside()
595
674
$ this ->assertEquals (3 , $ exceptions );
596
675
}
597
676
677
+ /**
678
+ * Test for invalid delete path
679
+ *
680
+ * @throws ValidatorException
681
+ */
682
+ public function testInvalidDeletePath ()
683
+ {
684
+ $ this ->expectException (FileSystemException::class);
685
+ $ directory = $ this ->getDirectoryInstance ('newDir ' , 0777 );
686
+ $ invalidPath = 'invalidPath/../ ' ;
687
+ $ directory ->create ($ invalidPath );
688
+ $ directory ->delete ($ invalidPath );
689
+ }
690
+
598
691
/**
599
692
* Tear down
693
+ *
694
+ * @throws FileSystemException
695
+ * @throws ValidatorException
600
696
*/
601
697
public function tearDown ()
602
698
{
@@ -620,8 +716,8 @@ private function getDirectoryInstance($path, $permissions)
620
716
{
621
717
$ fullPath = __DIR__ . '/../_files/ ' . $ path ;
622
718
$ objectManager = Bootstrap::getObjectManager ();
623
- /** @var \Magento\Framework\Filesystem\Directory\ WriteFactory $directoryFactory */
624
- $ directoryFactory = $ objectManager ->create (\ Magento \ Framework \ Filesystem \ Directory \ WriteFactory::class);
719
+ /** @var WriteFactory $directoryFactory */
720
+ $ directoryFactory = $ objectManager ->create (WriteFactory::class);
625
721
$ directory = $ directoryFactory ->create ($ fullPath , DriverPool::FILE , $ permissions );
626
722
$ this ->testDirectories [] = $ directory ;
627
723
return $ directory ;
0 commit comments