Changeset View
Changeset View
Standalone View
Standalone View
src/filesystem/__tests__/FilesystemTestCase.php
Show First 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | foreach ($test_cases as $test_case) { | ||||
list($path, $root, $expected) = $test_case; | list($path, $root, $expected) = $test_case; | ||||
$this->assertEqual( | $this->assertEqual( | ||||
$expected, | $expected, | ||||
Filesystem::walkToRoot($path, $root)); | Filesystem::walkToRoot($path, $root)); | ||||
} | } | ||||
} | } | ||||
public function testisDescendant() { | public function testRelativePath() { | ||||
$test_cases = array( | $test_cases = array( | ||||
array( | array( | ||||
__FILE__, | '/', | ||||
dirname(__FILE__), | '/foo/bar/baz', | ||||
true, | 'foo/bar/baz', | ||||
), | ), | ||||
array( | array( | ||||
dirname(__FILE__), | '/foo', | ||||
dirname(dirname(__FILE__)), | '/foo/bar/baz', | ||||
true, | 'bar/baz', | ||||
), | ), | ||||
array( | array( | ||||
dirname(__FILE__), | '/foo/bar/baz', | ||||
phutil_get_library_root_for_path(__FILE__), | '/foo/foobar', | ||||
true, | '../foobar', | ||||
), | ), | ||||
// Windows paths | |||||
array( | array( | ||||
dirname(dirname(__FILE__)), | 'c:\\', | ||||
dirname(__FILE__), | 'c:\\Windows\\System32\\Drivers\\etc\\hosts', | ||||
false, | 'Windows/System32/Drivers/etc/hosts', | ||||
), | ), | ||||
array( | array( | ||||
dirname(__FILE__).'/quack', | 'c:\\Users\\Bill Gates\\', | ||||
dirname(__FILE__), | 'c:\\Windows\\System32\\Drivers\\etc\\hosts', | ||||
false, | '../../Windows/System32/Drivers/etc/hosts', | ||||
), | ), | ||||
); | ); | ||||
foreach ($test_cases as $test_case) { | foreach ($test_cases as $test_case) { | ||||
list($path, $root, $expected) = $test_case; | list($from, $to, $expected) = $test_case; | ||||
$this->assertEqual( | $this->assertEqual( | ||||
$expected, | $expected, | ||||
Filesystem::isDescendant($path, $root), | Filesystem::relativePath($from, $to), | ||||
sprintf( | sprintf( | ||||
'Filesystem::isDescendant(%s, %s)', | 'Filesystem::relativePath(%s, %s)', | ||||
phutil_var_export($path), | phutil_var_export($from), | ||||
phutil_var_export($root))); | phutil_var_export($to))); | ||||
} | } | ||||
} | } | ||||
} | } |