xref: /dokuwiki/_test/tests/inc/io_readfile.test.php (revision d387bf5e958e9d25a7192d1f5e5280ac0eb82da7)
1*d387bf5eSAndreas Gohr<?php
2*d387bf5eSAndreas Gohr
3*d387bf5eSAndreas Gohrclass io_readfile_test extends DokuWikiTest {
4*d387bf5eSAndreas Gohr
5*d387bf5eSAndreas Gohr    /*
6*d387bf5eSAndreas Gohr     * dependency for tests needing zlib extension to pass
7*d387bf5eSAndreas Gohr     */
8*d387bf5eSAndreas Gohr    public function test_ext_zlib() {
9*d387bf5eSAndreas Gohr        if (!extension_loaded('zlib')) {
10*d387bf5eSAndreas Gohr            $this->markTestSkipped('skipping all zlib tests.  Need zlib extension');
11*d387bf5eSAndreas Gohr        }
12*d387bf5eSAndreas Gohr    }
13*d387bf5eSAndreas Gohr
14*d387bf5eSAndreas Gohr    /*
15*d387bf5eSAndreas Gohr     * dependency for tests needing zlib extension to pass
16*d387bf5eSAndreas Gohr     */
17*d387bf5eSAndreas Gohr    public function test_ext_bz2() {
18*d387bf5eSAndreas Gohr        if (!extension_loaded('bz2')) {
19*d387bf5eSAndreas Gohr            $this->markTestSkipped('skipping all bzip2 tests.  Need bz2 extension');
20*d387bf5eSAndreas Gohr        }
21*d387bf5eSAndreas Gohr    }
22*d387bf5eSAndreas Gohr
23*d387bf5eSAndreas Gohr    function test_plain(){
24*d387bf5eSAndreas Gohr        // since git converts line endings, we can't check in this test file but have to create it ourselves
25*d387bf5eSAndreas Gohr        $plain = TMP_DIR.'/test.txt';
26*d387bf5eSAndreas Gohr        file_put_contents($plain, "The\015\012Test\015\012");
27*d387bf5eSAndreas Gohr
28*d387bf5eSAndreas Gohr        $this->assertEquals("The\012Test\012", io_readFile($plain));
29*d387bf5eSAndreas Gohr        $this->assertEquals("The\015\012Test\015\012", io_readFile($plain, false));
30*d387bf5eSAndreas Gohr        $this->assertEquals(false, io_readFile(__DIR__.'/io_readfile/nope.txt'));
31*d387bf5eSAndreas Gohr    }
32*d387bf5eSAndreas Gohr
33*d387bf5eSAndreas Gohr    /**
34*d387bf5eSAndreas Gohr     * @depends test_ext_zlib
35*d387bf5eSAndreas Gohr     */
36*d387bf5eSAndreas Gohr    function test_gzfiles(){
37*d387bf5eSAndreas Gohr        $this->assertEquals("The\012Test\012", io_readFile(__DIR__.'/io_readfile/test.txt.gz'));
38*d387bf5eSAndreas Gohr        $this->assertEquals("The\015\012Test\015\012", io_readFile(__DIR__.'/io_readfile/test.txt.gz', false));
39*d387bf5eSAndreas Gohr        $this->assertEquals(false, io_readFile(__DIR__.'/io_readfile/nope.txt.gz'));
40*d387bf5eSAndreas Gohr        $this->assertEquals(false, io_readFile(__DIR__.'/io_readfile/corrupt.txt.gz'));
41*d387bf5eSAndreas Gohr    }
42*d387bf5eSAndreas Gohr
43*d387bf5eSAndreas Gohr    /**
44*d387bf5eSAndreas Gohr     * @depends test_ext_bz2
45*d387bf5eSAndreas Gohr     */
46*d387bf5eSAndreas Gohr    function test_bzfiles(){
47*d387bf5eSAndreas Gohr        $this->assertEquals("The\012Test\012", io_readFile(__DIR__.'/io_readfile/test.txt.bz2'));
48*d387bf5eSAndreas Gohr        $this->assertEquals("The\015\012Test\015\012", io_readFile(__DIR__.'/io_readfile/test.txt.bz2', false));
49*d387bf5eSAndreas Gohr        $this->assertEquals(false, io_readFile(__DIR__.'/io_readfile/nope.txt.bz2'));
50*d387bf5eSAndreas Gohr        $this->assertEquals(false, io_readFile(__DIR__.'/io_readfile/corrupt.txt.bz2'));
51*d387bf5eSAndreas Gohr    }
52*d387bf5eSAndreas Gohr
53*d387bf5eSAndreas Gohr}