[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/_test/tests/inc/ -> init_fullpath.test.php (source)

   1  <?php
   2  
   3  class init_fullpath_test extends DokuWikiTest {
   4  
   5      function test_unix_paths(){
   6          $base = $_SERVER['SCRIPT_FILENAME'];
   7          $_SERVER['SCRIPT_FILENAME'] = '/absolute/path/self.php';
   8          $GLOBALS['DOKU_UNITTEST_ASSUME_WINDOWS'] = false;
   9  
  10          // paths to check
  11          $tests = array(
  12                          '/foo/bar/baz' => '/foo/bar/baz',
  13                          '/foo//bar/baz' => '/foo/bar/baz',
  14                          '/foo/../bar/baz' => '/bar/baz',
  15                          '/foo/./bar/baz' => '/foo/bar/baz',
  16                          '/foo/bar/..' => '/foo',
  17                          '/foo/bar/../../../baz' => '/baz',
  18  
  19                          'foo/bar/baz' => '/absolute/path/foo/bar/baz',
  20                          'foo//bar/baz' => '/absolute/path/foo/bar/baz',
  21                          'foo/../bar/baz' => '/absolute/path/bar/baz',
  22                          'foo/./bar/baz' => '/absolute/path/foo/bar/baz',
  23                          'foo/bar/..' => '/absolute/path/foo',
  24                          'foo/bar/../../../baz' => '/absolute/baz',
  25                        );
  26  
  27          foreach($tests as $from => $to){
  28              $info = "Testing '$from' resulted in '".fullpath($from)."'";
  29  
  30              $this->assertEquals(fullpath($from), $to, $info);
  31          }
  32  
  33  
  34          $_SERVER['SCRIPT_FILENAME'] = $base;
  35          unset($GLOBALS['DOKU_UNITTEST_ASSUME_WINDOWS']);
  36      }
  37  
  38      function test_windows_paths(){
  39          $base = $_SERVER['SCRIPT_FILENAME'];
  40          $_SERVER['SCRIPT_FILENAME'] = '/absolute/path/self.php';
  41          $GLOBALS['DOKU_UNITTEST_ASSUME_WINDOWS'] = true;
  42  
  43          // paths to check
  44          $tests = array(
  45                          'c:foo/bar/baz' => 'c:/foo/bar/baz',
  46                          'c:foo//bar/baz' => 'c:/foo/bar/baz',
  47                          'c:foo/../bar/baz' => 'c:/bar/baz',
  48                          'c:foo/./bar/baz' => 'c:/foo/bar/baz',
  49                          'c:foo/bar/..' => 'c:/foo',
  50                          'c:foo/bar/../../../baz' => 'c:/baz',
  51  
  52                          'c:/foo/bar/baz' => 'c:/foo/bar/baz',
  53                          'c:/foo//bar/baz' => 'c:/foo/bar/baz',
  54                          'c:/foo/../bar/baz' => 'c:/bar/baz',
  55                          'c:/foo/./bar/baz' => 'c:/foo/bar/baz',
  56                          'c:/foo/bar/..' => 'c:/foo',
  57                          'c:/foo/bar/../../../baz' => 'c:/baz',
  58  
  59                          'c:\\foo\\bar\\baz' => 'c:/foo/bar/baz',
  60                          'c:\\foo\\\\bar\\baz' => 'c:/foo/bar/baz',
  61                          'c:\\foo\\..\\bar\\baz' => 'c:/bar/baz',
  62                          'c:\\foo\\.\\bar\\baz' => 'c:/foo/bar/baz',
  63                          'c:\\foo\\bar\\..' => 'c:/foo',
  64                          'c:\\foo\\bar\\..\\..\\..\\baz' => 'c:/baz',
  65  
  66                          '\\\\server\\share/foo/bar/baz' => '\\\\server\\share/foo/bar/baz',
  67                          '\\\\server\\share/foo//bar/baz' => '\\\\server\\share/foo/bar/baz',
  68                          '\\\\server\\share/foo/../bar/baz' => '\\\\server\\share/bar/baz',
  69                          '\\\\server\\share/foo/./bar/baz' => '\\\\server\\share/foo/bar/baz',
  70                          '\\\\server\\share/foo/bar/..' => '\\\\server\\share/foo',
  71                          '\\\\server\\share/foo/bar/../../../baz' => '\\\\server\\share/baz',
  72                        );
  73  
  74          foreach($tests as $from => $to){
  75              $info = "Testing '$from' resulted in '".fullpath($from)."'";
  76  
  77              $this->assertEquals(fullpath($from), $to, $info);
  78          }
  79  
  80  
  81          $_SERVER['SCRIPT_FILENAME'] = $base;
  82          unset($GLOBALS['DOKU_UNITTEST_ASSUME_WINDOWS']);
  83      }
  84  
  85  }
  86  //Setup VIM: ex: et ts=4 :