[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

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

   1  <?php
   2  
   3  class io_rmdir_test extends DokuWikiTest {
   4  
   5      function test_nopes(){
   6          // set up test dir
   7          $dir = realpath(io_mktmpdir());
   8          $top = dirname($dir);
   9          $this->assertTrue($dir !== false);
  10          $this->assertTrue(is_dir($dir));
  11  
  12          // switch into it
  13          $this->assertTrue(chdir($dir));
  14          $this->assertEquals($dir, getcwd());
  15  
  16  
  17          $this->assertFalse(io_rmdir('', false));
  18          clearstatcache();
  19          $this->assertTrue(is_dir($dir));
  20          $this->assertTrue(is_dir($top));
  21  
  22          $this->assertFalse(io_rmdir('', true));
  23          clearstatcache();
  24          $this->assertTrue(is_dir($dir));
  25          $this->assertTrue(is_dir($top));
  26  
  27          $this->assertFalse(io_rmdir(null, false));
  28          clearstatcache();
  29          $this->assertTrue(is_dir($dir));
  30          $this->assertTrue(is_dir($top));
  31  
  32          $this->assertFalse(io_rmdir(null, true));
  33          clearstatcache();
  34          $this->assertTrue(is_dir($dir));
  35          $this->assertTrue(is_dir($top));
  36  
  37          $this->assertFalse(io_rmdir(false, false));
  38          clearstatcache();
  39          $this->assertTrue(is_dir($dir));
  40          $this->assertTrue(is_dir($top));
  41  
  42          $this->assertFalse(io_rmdir(false, true));
  43          clearstatcache();
  44          $this->assertTrue(is_dir($dir));
  45          $this->assertTrue(is_dir($top));
  46  
  47          $this->assertFalse(io_rmdir(array(), false));
  48          clearstatcache();
  49          $this->assertTrue(is_dir($dir));
  50          $this->assertTrue(is_dir($top));
  51  
  52          $this->assertFalse(io_rmdir(array(), true));
  53          clearstatcache();
  54          $this->assertTrue(is_dir($dir));
  55          $this->assertTrue(is_dir($top));
  56  
  57          $this->assertFileNotExists("$dir/this/does/not/exist");
  58          $this->assertTrue(io_rmdir("$dir/this/does/not/exist"));
  59          clearstatcache();
  60          $this->assertFileNotExists("$dir/this/does/not/exist");
  61          $this->assertTrue(is_dir($dir));
  62          $this->assertTrue(is_dir($top));
  63      }
  64  
  65  
  66      function test_empty_single(){
  67          // set up test dir
  68          $dir = io_mktmpdir();
  69          $top = dirname($dir);
  70          $this->assertTrue($dir !== false);
  71          $this->assertTrue(is_dir($dir));
  72  
  73          // delete successfully
  74          $this->assertTrue(io_rmdir($dir, false));
  75  
  76          // check result
  77          clearstatcache();
  78          $this->assertFalse(is_dir($dir));
  79          $this->assertTrue(is_dir($top));
  80  
  81          // same again with deletefiles
  82  
  83          // set up test dir
  84          $dir = io_mktmpdir();
  85          $this->assertTrue($dir !== false);
  86          $this->assertTrue(is_dir($dir));
  87  
  88          // delete successfully
  89          $this->assertTrue(io_rmdir($dir, true));
  90  
  91          // check result
  92          clearstatcache();
  93          $this->assertFalse(is_dir($dir));
  94          $this->assertTrue(is_dir($top));
  95      }
  96  
  97  
  98      function test_empty_hierarchy(){
  99          // setup hierachy and test it exists
 100          $dir = io_mktmpdir();
 101          $top = dirname($dir);
 102          $this->assertTrue($dir !== false);
 103          $this->assertTrue(is_dir($dir));
 104          $this->assertTrue(io_mkdir_p("$dir/foo/bar/baz"));
 105          $this->assertTrue(is_dir("$dir/foo/bar/baz"));
 106          $this->assertTrue(io_mkdir_p("$dir/foobar/bar/baz"));
 107          $this->assertTrue(is_dir("$dir/foobar/bar/baz"));
 108  
 109          // delete successfully
 110          $this->assertTrue(io_rmdir($dir, false));
 111  
 112          // check result
 113          clearstatcache();
 114          $this->assertFalse(is_dir("$dir/foo/bar/baz"));
 115          $this->assertFalse(is_dir("$dir/foobar/bar/baz"));
 116          $this->assertFalse(is_dir($dir));
 117          $this->assertTrue(is_dir($top));
 118  
 119          // same again with deletefiles
 120  
 121          // setup hierachy and test it exists
 122          $dir = io_mktmpdir();
 123          $this->assertTrue($dir !== false);
 124          $this->assertTrue(is_dir($dir));
 125          $this->assertTrue(io_mkdir_p("$dir/foo/bar/baz"));
 126          $this->assertTrue(is_dir("$dir/foo/bar/baz"));
 127          $this->assertTrue(io_mkdir_p("$dir/foobar/bar/baz"));
 128          $this->assertTrue(is_dir("$dir/foobar/bar/baz"));
 129  
 130          // delete successfully
 131          $this->assertTrue(io_rmdir($dir, true));
 132  
 133          // check result
 134          clearstatcache();
 135          $this->assertFalse(is_dir("$dir/foo/bar/baz"));
 136          $this->assertFalse(is_dir("$dir/foobar/bar/baz"));
 137          $this->assertFalse(is_dir($dir));
 138          $this->assertTrue(is_dir($top));
 139      }
 140  
 141      function test_full_single(){
 142          // set up test dir
 143          $dir = io_mktmpdir();
 144          $top = dirname($dir);
 145          $this->assertTrue($dir !== false);
 146          $this->assertTrue(is_dir($dir));
 147  
 148          // put file
 149          $this->assertTrue(io_saveFile("$dir/testfile.txt", 'foobar'));
 150          $this->assertFileExists("$dir/testfile.txt");
 151  
 152          // delete unsuccessfully
 153          $this->assertFalse(io_rmdir($dir, false));
 154  
 155          // check result
 156          clearstatcache();
 157          $this->assertFileExists("$dir/testfile.txt");
 158          $this->assertTrue(is_dir($dir));
 159          $this->assertTrue(is_dir($top));
 160  
 161          // same again with deletefiles
 162  
 163          // delete successfully
 164          $this->assertTrue(io_rmdir($dir, true));
 165  
 166          // check result
 167          clearstatcache();
 168          $this->assertFileNotExists("$dir/testfile.txt");
 169          $this->assertFalse(is_dir($dir));
 170          $this->assertTrue(is_dir($top));
 171      }
 172  
 173      function test_full_hierarchy(){
 174          // setup hierachy and test it exists
 175          $dir = io_mktmpdir();
 176          $top = dirname($dir);
 177          $this->assertTrue($dir !== false);
 178          $this->assertTrue(is_dir($dir));
 179          $this->assertTrue(io_mkdir_p("$dir/foo/bar/baz"));
 180          $this->assertTrue(is_dir("$dir/foo/bar/baz"));
 181          $this->assertTrue(io_mkdir_p("$dir/foobar/bar/baz"));
 182          $this->assertTrue(is_dir("$dir/foobar/bar/baz"));
 183  
 184          // put files
 185          $this->assertTrue(io_saveFile("$dir/testfile.txt", 'foobar'));
 186          $this->assertFileExists("$dir/testfile.txt");
 187          $this->assertTrue(io_saveFile("$dir/foo/testfile.txt", 'foobar'));
 188          $this->assertFileExists("$dir/foo/testfile.txt");
 189          $this->assertTrue(io_saveFile("$dir/foo/bar/baz/testfile.txt", 'foobar'));
 190          $this->assertFileExists("$dir/foo/bar/baz/testfile.txt");
 191  
 192          // delete unsuccessfully
 193          $this->assertFalse(io_rmdir($dir, false));
 194  
 195          // check result
 196          clearstatcache();
 197          $this->assertFileExists("$dir/testfile.txt");
 198          $this->assertFileExists("$dir/foo/testfile.txt");
 199          $this->assertFileExists("$dir/foo/bar/baz/testfile.txt");
 200          $this->assertTrue(is_dir("$dir/foo/bar/baz"));
 201          $this->assertTrue(is_dir("$dir/foobar/bar/baz"));
 202          $this->assertTrue(is_dir($dir));
 203          $this->assertTrue(is_dir($top));
 204  
 205          // delete successfully
 206          $this->assertTrue(io_rmdir($dir, true));
 207  
 208          // check result
 209          clearstatcache();
 210          $this->assertFileNotExists("$dir/testfile.txt");
 211          $this->assertFileNotExists("$dir/foo/testfile.txt");
 212          $this->assertFileNotExists("$dir/foo/bar/baz/testfile.txt");
 213          $this->assertFalse(is_dir("$dir/foo/bar/baz"));
 214          $this->assertFalse(is_dir("$dir/foobar/bar/baz"));
 215          $this->assertFalse(is_dir($dir));
 216          $this->assertTrue(is_dir($top));
 217      }
 218  
 219  }