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