7
7
*/
8
8
namespace Magento \Framework \Filesystem \Directory ;
9
9
10
+ use Magento \Framework \Exception \ValidatorException ;
10
11
use Magento \TestFramework \Helper \Bootstrap ;
11
12
12
13
/**
@@ -34,13 +35,57 @@ public function testGetAbsolutePath()
34
35
$ this ->assertContains ('_files/foo/bar ' , $ dir ->getAbsolutePath ('bar ' ));
35
36
}
36
37
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
+
37
64
public function testGetRelativePath ()
38
65
{
39
66
$ dir = $ this ->getDirectoryInstance ('foo ' );
67
+ $ this ->assertEquals (
68
+ 'file_three.txt ' ,
69
+ $ dir ->getRelativePath ('file_three.txt ' )
70
+ );
40
71
$ this ->assertEquals ('' , $ dir ->getRelativePath ());
41
72
$ this ->assertEquals ('bar ' , $ dir ->getRelativePath (__DIR__ . '/../_files/foo/bar ' ));
42
73
}
43
74
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
+
44
89
/**
45
90
* Test for read method
46
91
*
@@ -72,6 +117,20 @@ public function readProvider()
72
117
];
73
118
}
74
119
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
+
75
134
/**
76
135
* Test for search method
77
136
*
@@ -103,6 +162,20 @@ public function searchProvider()
103
162
];
104
163
}
105
164
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
+
106
179
/**
107
180
* Test for isExist method
108
181
*
@@ -127,6 +200,20 @@ public function existsProvider()
127
200
return [['foo ' , 'bar ' , true ], ['foo ' , 'bar/baz/ ' , true ], ['foo ' , 'bar/notexists ' , false ]];
128
201
}
129
202
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
+
130
217
/**
131
218
* Test for stat method
132
219
*
@@ -168,6 +255,20 @@ public function statProvider()
168
255
return [['foo ' , 'bar ' ], ['foo ' , 'file_three.txt ' ]];
169
256
}
170
257
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
+
171
272
/**
172
273
* Test for isReadable method
173
274
*
@@ -182,6 +283,20 @@ public function testIsReadable($dirPath, $path, $readable)
182
283
$ this ->assertEquals ($ readable , $ dir ->isReadable ($ path ));
183
284
}
184
285
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
+
185
300
/**
186
301
* Test for isFile method
187
302
*
@@ -194,6 +309,20 @@ public function testIsFile($path, $isFile)
194
309
$ this ->assertEquals ($ isFile , $ this ->getDirectoryInstance ('foo ' )->isFile ($ path ));
195
310
}
196
311
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
+
197
326
/**
198
327
* Test for isDirectory method
199
328
*
@@ -206,6 +335,20 @@ public function testIsDirectory($path, $isDirectory)
206
335
$ this ->assertEquals ($ isDirectory , $ this ->getDirectoryInstance ('foo ' )->isDirectory ($ path ));
207
336
}
208
337
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
+
209
352
/**
210
353
* Data provider for testIsReadable
211
354
*
@@ -246,6 +389,20 @@ public function testOpenFile()
246
389
$ this ->assertTrue ($ file instanceof \Magento \Framework \Filesystem \File \ReadInterface);
247
390
}
248
391
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
+
249
406
/**
250
407
* Test readFile
251
408
*
@@ -268,10 +425,27 @@ public function readFileProvider()
268
425
{
269
426
return [
270
427
['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
+ ],
272
432
];
273
433
}
274
434
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
+
275
449
/**
276
450
* Get readable file instance
277
451
* Get full path for files located in _files directory
@@ -301,4 +475,18 @@ public function testReadRecursively()
301
475
sort ($ expected );
302
476
$ this ->assertEquals ($ expected , $ actual );
303
477
}
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
+ }
304
492
}
0 commit comments