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