summaryrefslogtreecommitdiff
path: root/_test/tests/inc/io_deletefromfile.test.php
blob: 63951f548ea58793c4e4ea7548bfaae17ec5d06f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php

class io_deletefromfile_test extends DokuWikiTest {

    /*
     * dependency for tests needing zlib extension to pass
     */
    public function test_ext_zlib() {
        if (!extension_loaded('zlib')) {
            $this->markTestSkipped('skipping all zlib tests.  Need zlib extension');
        }
    }

    /*
     * dependency for tests needing zlib extension to pass
     */
    public function test_ext_bz2() {
        if (!extension_loaded('bz2')) {
            $this->markTestSkipped('skipping all bzip2 tests.  Need bz2 extension');
        }
    }

    function _write($file){
        $contents = "The\012Delete\012Delete01\012Delete02\012Delete\012DeleteX\012Test\012";
        io_saveFile($file, $contents);
        $this->assertTrue(io_deleteFromFile($file, "Delete\012"));
        $this->assertEquals("The\012Delete01\012Delete02\012DeleteX\012Test\012", io_readFile($file));
        $this->assertTrue(io_deleteFromFile($file, "#Delete\\d+\012#", true));
        $this->assertEquals("The\012DeleteX\012Test\012", io_readFile($file));
    }

    function test_delete(){
        $this->_write(TMP_DIR.'/test.txt');
    }

    /**
     * @depends test_ext_zlib
     */
    function test_gzwrite(){
        $this->_write(TMP_DIR.'/test.txt.gz');
    }

    /**
     * @depends test_ext_bz2
     */
    function test_bzwrite(){
        $this->_write(TMP_DIR.'/test.txt.bz2');
    }

}