Changeset View
Changeset View
Standalone View
Standalone View
src/filesystem/__tests__/FilesystemTestCase.php
| Show First 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | try { | ||||
| Filesystem::readRandomBytes(0); | Filesystem::readRandomBytes(0); | ||||
| } catch (Exception $ex) { | } catch (Exception $ex) { | ||||
| $caught = $ex; | $caught = $ex; | ||||
| } | } | ||||
| $this->assertTrue($caught instanceof Exception); | $this->assertTrue($caught instanceof Exception); | ||||
| } | } | ||||
| public function testWalkToRoot() { | public function testWalkToRoot() { | ||||
| $win_root = phutil_is_windows() ? getenv('HOMEDRIVE') : ''; | |||||
| $test_cases = array( | $test_cases = array( | ||||
| array( | array( | ||||
| dirname(__FILE__).'/data/include_dir.txt/subdir.txt/test', | Filesystem::buildPath( | ||||
| dirname(__FILE__), | |||||
| 'data', 'include_dir.txt', 'subdir.txt', 'test'), | |||||
| dirname(__FILE__), | dirname(__FILE__), | ||||
| array( | array( | ||||
| dirname(__FILE__).'/data/include_dir.txt/subdir.txt/test', | Filesystem::buildPath( | ||||
| dirname(__FILE__).'/data/include_dir.txt/subdir.txt', | dirname(__FILE__), | ||||
| dirname(__FILE__).'/data/include_dir.txt', | 'data', 'include_dir.txt', 'subdir.txt', 'test'), | ||||
| dirname(__FILE__).'/data', | Filesystem::buildPath( | ||||
| dirname(__FILE__), | |||||
| 'data', 'include_dir.txt', 'subdir.txt'), | |||||
| Filesystem::buildPath(dirname(__FILE__), 'data', 'include_dir.txt'), | |||||
| Filesystem::buildPath(dirname(__FILE__), 'data'), | |||||
| dirname(__FILE__), | dirname(__FILE__), | ||||
| ), | ), | ||||
| ), | ), | ||||
| array( | array( | ||||
| dirname(__FILE__).'/data/include_dir.txt/subdir.txt', | Filesystem::buildPath( | ||||
| dirname(__FILE__), | |||||
| 'data', 'include_dir.txt', 'subdir.txt'), | |||||
| dirname(__FILE__), | dirname(__FILE__), | ||||
| array( | array( | ||||
| dirname(__FILE__).'/data/include_dir.txt/subdir.txt', | Filesystem::buildPath( | ||||
| dirname(__FILE__).'/data/include_dir.txt', | dirname(__FILE__), | ||||
| dirname(__FILE__).'/data', | 'data', 'include_dir.txt', 'subdir.txt'), | ||||
| Filesystem::buildPath(dirname(__FILE__), 'data', 'include_dir.txt'), | |||||
| Filesystem::buildPath(dirname(__FILE__), 'data'), | |||||
| dirname(__FILE__), | dirname(__FILE__), | ||||
| ), | ), | ||||
| ), | ), | ||||
| 'root and path are identical' => array( | 'root and path are identical' => array( | ||||
| dirname(__FILE__), | dirname(__FILE__), | ||||
| dirname(__FILE__), | dirname(__FILE__), | ||||
| array( | array( | ||||
| dirname(__FILE__), | dirname(__FILE__), | ||||
| ), | ), | ||||
| ), | ), | ||||
| 'root is not an ancestor of path' => array( | 'root is not an ancestor of path' => array( | ||||
| dirname(__FILE__), | dirname(__FILE__), | ||||
| dirname(__FILE__).'/data/include_dir.txt/subdir.txt', | Filesystem::buildPath( | ||||
| dirname(__FILE__), 'data', 'include_dir.txt', 'subdir.txt'), | |||||
| array(), | array(), | ||||
| ), | ), | ||||
| 'fictional paths work' => array( | 'fictional paths work' => array( | ||||
| '/x/y/z', | '/x/y/z', | ||||
| '/', | '/', | ||||
| phutil_is_windows() ? | |||||
| array( | |||||
| $win_root.'\\x\\y\\z', | |||||
| $win_root.'\\x\\y', | |||||
| $win_root.'\\x', | |||||
| $win_root, | |||||
| ) | |||||
| : | |||||
| array( | array( | ||||
| '/x/y/z', | '/x/y/z', | ||||
| '/x/y', | '/x/y', | ||||
| '/x', | '/x', | ||||
| '/', | '/', | ||||
| ), | ), | ||||
| ), | ), | ||||
| ); | ); | ||||
| foreach ($test_cases as $test_case) { | foreach ($test_cases as $test_case) { | ||||
| list($path, $root, $expected) = $test_case; | list($path, $root, $expected) = $test_case; | ||||
| $this->assertEqual( | $this->assertEqual( | ||||
| ▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines | |||||