77 */
88namespace Magento \Framework \Filesystem \Directory ;
99
10+ use Magento \Framework \Exception \ValidatorException ;
1011use 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