1<?php 2 3class io_rmdir_test extends DokuWikiTest { 4 5 6 function test_empty_single(){ 7 // set up test dir 8 $dir = io_mktmpdir(); 9 $top = dirname($dir); 10 $this->assertTrue($dir !== false); 11 $this->assertTrue(is_dir($dir)); 12 13 // delete successfully 14 $this->assertTrue(io_rmdir($dir, false)); 15 16 // check result 17 clearstatcache(); 18 $this->assertFalse(is_dir($dir)); 19 $this->assertTrue(is_dir($top)); 20 21 // same again with deletefiles 22 23 // set up test dir 24 $dir = io_mktmpdir(); 25 $this->assertTrue($dir !== false); 26 $this->assertTrue(is_dir($dir)); 27 28 // delete successfully 29 $this->assertTrue(io_rmdir($dir, true)); 30 31 // check result 32 clearstatcache(); 33 $this->assertFalse(is_dir($dir)); 34 $this->assertTrue(is_dir($top)); 35 } 36 37 38 function test_empty_hierarchy(){ 39 // setup hierachy and test it exists 40 $dir = io_mktmpdir(); 41 $top = dirname($dir); 42 $this->assertTrue($dir !== false); 43 $this->assertTrue(is_dir($dir)); 44 $this->assertTrue(io_mkdir_p("$dir/foo/bar/baz")); 45 $this->assertTrue(is_dir("$dir/foo/bar/baz")); 46 $this->assertTrue(io_mkdir_p("$dir/foobar/bar/baz")); 47 $this->assertTrue(is_dir("$dir/foobar/bar/baz")); 48 49 // delete successfully 50 $this->assertTrue(io_rmdir($dir, false)); 51 52 // check result 53 clearstatcache(); 54 $this->assertFalse(is_dir("$dir/foo/bar/baz")); 55 $this->assertFalse(is_dir("$dir/foobar/bar/baz")); 56 $this->assertFalse(is_dir($dir)); 57 $this->assertTrue(is_dir($top)); 58 59 // same again with deletefiles 60 61 // setup hierachy and test it exists 62 $dir = io_mktmpdir(); 63 $this->assertTrue($dir !== false); 64 $this->assertTrue(is_dir($dir)); 65 $this->assertTrue(io_mkdir_p("$dir/foo/bar/baz")); 66 $this->assertTrue(is_dir("$dir/foo/bar/baz")); 67 $this->assertTrue(io_mkdir_p("$dir/foobar/bar/baz")); 68 $this->assertTrue(is_dir("$dir/foobar/bar/baz")); 69 70 // delete successfully 71 $this->assertTrue(io_rmdir($dir, true)); 72 73 // check result 74 clearstatcache(); 75 $this->assertFalse(is_dir("$dir/foo/bar/baz")); 76 $this->assertFalse(is_dir("$dir/foobar/bar/baz")); 77 $this->assertFalse(is_dir($dir)); 78 $this->assertTrue(is_dir($top)); 79 } 80 81 function test_full_single(){ 82 // set up test dir 83 $dir = io_mktmpdir(); 84 $top = dirname($dir); 85 $this->assertTrue($dir !== false); 86 $this->assertTrue(is_dir($dir)); 87 88 // put file 89 $this->assertTrue(io_saveFile("$dir/testfile.txt", 'foobar')); 90 $this->assertFileExists("$dir/testfile.txt"); 91 92 // delete unsuccessfully 93 $this->assertFalse(io_rmdir($dir, false)); 94 95 // check result 96 clearstatcache(); 97 $this->assertFileExists("$dir/testfile.txt"); 98 $this->assertTrue(is_dir($dir)); 99 $this->assertTrue(is_dir($top)); 100 101 // same again with deletefiles 102 103 // delete successfully 104 $this->assertTrue(io_rmdir($dir, true)); 105 106 // check result 107 clearstatcache(); 108 $this->assertFileNotExists("$dir/testfile.txt"); 109 $this->assertFalse(is_dir($dir)); 110 $this->assertTrue(is_dir($top)); 111 } 112 113 function test_full_hierarchy(){ 114 // setup hierachy and test it exists 115 $dir = io_mktmpdir(); 116 $top = dirname($dir); 117 $this->assertTrue($dir !== false); 118 $this->assertTrue(is_dir($dir)); 119 $this->assertTrue(io_mkdir_p("$dir/foo/bar/baz")); 120 $this->assertTrue(is_dir("$dir/foo/bar/baz")); 121 $this->assertTrue(io_mkdir_p("$dir/foobar/bar/baz")); 122 $this->assertTrue(is_dir("$dir/foobar/bar/baz")); 123 124 // put files 125 $this->assertTrue(io_saveFile("$dir/testfile.txt", 'foobar')); 126 $this->assertFileExists("$dir/testfile.txt"); 127 $this->assertTrue(io_saveFile("$dir/foo/testfile.txt", 'foobar')); 128 $this->assertFileExists("$dir/foo/testfile.txt"); 129 $this->assertTrue(io_saveFile("$dir/foo/bar/baz/testfile.txt", 'foobar')); 130 $this->assertFileExists("$dir/foo/bar/baz/testfile.txt"); 131 132 // delete unsuccessfully 133 $this->assertFalse(io_rmdir($dir, false)); 134 135 // check result 136 clearstatcache(); 137 $this->assertFileExists("$dir/testfile.txt"); 138 $this->assertFileExists("$dir/foo/testfile.txt"); 139 $this->assertFileExists("$dir/foo/bar/baz/testfile.txt"); 140 $this->assertTrue(is_dir("$dir/foo/bar/baz")); 141 $this->assertTrue(is_dir("$dir/foobar/bar/baz")); 142 $this->assertTrue(is_dir($dir)); 143 $this->assertTrue(is_dir($top)); 144 145 // delete successfully 146 $this->assertTrue(io_rmdir($dir, true)); 147 148 // check result 149 clearstatcache(); 150 $this->assertFileNotExists("$dir/testfile.txt"); 151 $this->assertFileNotExists("$dir/foo/testfile.txt"); 152 $this->assertFileNotExists("$dir/foo/bar/baz/testfile.txt"); 153 $this->assertFalse(is_dir("$dir/foo/bar/baz")); 154 $this->assertFalse(is_dir("$dir/foobar/bar/baz")); 155 $this->assertFalse(is_dir($dir)); 156 $this->assertTrue(is_dir($top)); 157 } 158 159}