diff options
author | Andreas Gohr <andi@splitbrain.org> | 2008-09-14 15:47:44 +0200 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2008-09-14 15:47:44 +0200 |
commit | 4761d30ceb295143e72c59f91d19015d6b656ad5 (patch) | |
tree | 57b90444f129f759364052a5918ae471f55dbc1e /_test | |
parent | f5c6743cf7fd971197b6ff56c658bd2457cbb02f (diff) | |
download | rpg-4761d30ceb295143e72c59f91d19015d6b656ad5.tar.gz rpg-4761d30ceb295143e72c59f91d19015d6b656ad5.tar.bz2 |
rewrote the fullpath function FS#1462
The fullpath function now correctly handles windows drive letter paths and UNC
paths making sure that those are not destroyed with upper dir .. notation.
Unit tests where added.
darcs-hash:20080914134744-7ad00-9abf5931d910a0b12979b1f69b090e8ecd568c71.gz
Diffstat (limited to '_test')
-rw-r--r-- | _test/cases/inc/init_fullpath.test.php | 75 | ||||
-rwxr-xr-x | _test/runtests.php | 1 |
2 files changed, 76 insertions, 0 deletions
diff --git a/_test/cases/inc/init_fullpath.test.php b/_test/cases/inc/init_fullpath.test.php new file mode 100644 index 000000000..e2acc35a5 --- /dev/null +++ b/_test/cases/inc/init_fullpath.test.php @@ -0,0 +1,75 @@ +<?php +require_once DOKU_INC.'inc/init.php'; + +class init_fullpath_test extends UnitTestCase { + + function test_unix_paths(){ + $base = $_SERVER['SCRIPT_FILENAME']; + $_SERVER['SCRIPT_FILENAME'] = '/absolute/path/self.php'; + $GLOBALS['DOKU_UNITTEST_ASSUME_WINDOWS'] = false; + + // paths to check + $tests = array( + '/foo/bar/baz' => '/foo/bar/baz', + '/foo//bar/baz' => '/foo/bar/baz', + '/foo/../bar/baz' => '/bar/baz', + '/foo/./bar/baz' => '/foo/bar/baz', + '/foo/bar/..' => '/foo', + '/foo/bar/../../../baz' => '/baz', + + 'foo/bar/baz' => '/absolute/path/foo/bar/baz', + 'foo//bar/baz' => '/absolute/path/foo/bar/baz', + 'foo/../bar/baz' => '/absolute/path/bar/baz', + 'foo/./bar/baz' => '/absolute/path/foo/bar/baz', + 'foo/bar/..' => '/absolute/path/foo', + 'foo/bar/../../../baz' => '/absolute/baz', + ); + + foreach($tests as $from => $to){ + $info = "Testing '$from' resulted in '".fullpath($from)."'"; + $this->signal('failinfo',$info); + + $this->assertEqual(fullpath($from),$to); + } + + + $_SERVER['SCRIPT_FILENAME'] = $base; + unset($GLOBALS['DOKU_UNITTEST_ASSUME_WINDOWS']); + } + + function test_windows_paths(){ + $base = $_SERVER['SCRIPT_FILENAME']; + $_SERVER['SCRIPT_FILENAME'] = '/absolute/path/self.php'; + $GLOBALS['DOKU_UNITTEST_ASSUME_WINDOWS'] = true; + + // paths to check + $tests = array( + 'c:foo/bar/baz' => 'c:foo/bar/baz', + 'c:foo//bar/baz' => 'c:foo/bar/baz', + 'c:foo/../bar/baz' => 'c:bar/baz', + 'c:foo/./bar/baz' => 'c:foo/bar/baz', + 'c:foo/bar/..' => 'c:foo', + 'c:foo/bar/../../../baz' => 'c:baz', + + '\\\\server\\share/foo/bar/baz' => '\\\\server\\share/foo/bar/baz', + '\\\\server\\share/foo//bar/baz' => '\\\\server\\share/foo/bar/baz', + '\\\\server\\share/foo/../bar/baz' => '\\\\server\\share/bar/baz', + '\\\\server\\share/foo/./bar/baz' => '\\\\server\\share/foo/bar/baz', + '\\\\server\\share/foo/bar/..' => '\\\\server\\share/foo', + '\\\\server\\share/foo/bar/../../../baz' => '\\\\server\\share/baz', + ); + + foreach($tests as $from => $to){ + $info = "Testing '$from' resulted in '".fullpath($from)."'"; + $this->signal('failinfo',$info); + + $this->assertEqual(fullpath($from),$to); + } + + + $_SERVER['SCRIPT_FILENAME'] = $base; + unset($GLOBALS['DOKU_UNITTEST_ASSUME_WINDOWS']); + } + +} +//Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/_test/runtests.php b/_test/runtests.php index e3489b4cf..c4a4f36b4 100755 --- a/_test/runtests.php +++ b/_test/runtests.php @@ -2,6 +2,7 @@ <?php ini_set('memory_limit','128M'); if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); +define('DOKU_UNITTEST',true); require_once(DOKU_INC.'inc/init.php'); require_once(DOKU_INC.'inc/events.php'); |