xref: /dokuwiki/_test/tests/inc/io_readfile.test.php (revision 2ba676793c566450417f4d9fa28c1fdf95d60161)
1d387bf5eSAndreas Gohr<?php
2d387bf5eSAndreas Gohr
3d387bf5eSAndreas Gohrclass io_readfile_test extends DokuWikiTest {
4d387bf5eSAndreas Gohr
5d387bf5eSAndreas Gohr    /*
6d387bf5eSAndreas Gohr     * dependency for tests needing zlib extension to pass
7d387bf5eSAndreas Gohr     */
8d387bf5eSAndreas Gohr    public function test_ext_zlib() {
9216e727cSAndreas Gohr        if (!DOKU_HAS_GZIP) {
10d387bf5eSAndreas Gohr            $this->markTestSkipped('skipping all zlib tests.  Need zlib extension');
11*2ba67679SAndreas Gohr            return;
12d387bf5eSAndreas Gohr        }
13*2ba67679SAndreas Gohr        $this->assertTrue(true);
14d387bf5eSAndreas Gohr    }
15d387bf5eSAndreas Gohr
16d387bf5eSAndreas Gohr    /*
17d387bf5eSAndreas Gohr     * dependency for tests needing zlib extension to pass
18d387bf5eSAndreas Gohr     */
19d387bf5eSAndreas Gohr    public function test_ext_bz2() {
20216e727cSAndreas Gohr        if (!DOKU_HAS_BZIP) {
21d387bf5eSAndreas Gohr            $this->markTestSkipped('skipping all bzip2 tests.  Need bz2 extension');
22*2ba67679SAndreas Gohr            return;
23d387bf5eSAndreas Gohr        }
24*2ba67679SAndreas Gohr        $this->assertTrue(true);
25d387bf5eSAndreas Gohr    }
26d387bf5eSAndreas Gohr
27d387bf5eSAndreas Gohr    function test_plain(){
28d387bf5eSAndreas Gohr        // since git converts line endings, we can't check in this test file but have to create it ourselves
29d387bf5eSAndreas Gohr        $plain = TMP_DIR.'/test.txt';
30d387bf5eSAndreas Gohr        file_put_contents($plain, "The\015\012Test\015\012");
31d387bf5eSAndreas Gohr
32d387bf5eSAndreas Gohr        $this->assertEquals("The\012Test\012", io_readFile($plain));
33d387bf5eSAndreas Gohr        $this->assertEquals("The\015\012Test\015\012", io_readFile($plain, false));
34d387bf5eSAndreas Gohr        $this->assertEquals(false, io_readFile(__DIR__.'/io_readfile/nope.txt'));
35d387bf5eSAndreas Gohr    }
36d387bf5eSAndreas Gohr
37d387bf5eSAndreas Gohr    /**
38d387bf5eSAndreas Gohr     * @depends test_ext_zlib
39d387bf5eSAndreas Gohr     */
40d387bf5eSAndreas Gohr    function test_gzfiles(){
41d387bf5eSAndreas Gohr        $this->assertEquals("The\012Test\012", io_readFile(__DIR__.'/io_readfile/test.txt.gz'));
42d387bf5eSAndreas Gohr        $this->assertEquals("The\015\012Test\015\012", io_readFile(__DIR__.'/io_readfile/test.txt.gz', false));
43d387bf5eSAndreas Gohr        $this->assertEquals(false, io_readFile(__DIR__.'/io_readfile/nope.txt.gz'));
44d387bf5eSAndreas Gohr        $this->assertEquals(false, io_readFile(__DIR__.'/io_readfile/corrupt.txt.gz'));
45d387bf5eSAndreas Gohr    }
46d387bf5eSAndreas Gohr
47d387bf5eSAndreas Gohr    /**
48d387bf5eSAndreas Gohr     * @depends test_ext_bz2
49d387bf5eSAndreas Gohr     */
50d387bf5eSAndreas Gohr    function test_bzfiles(){
51d387bf5eSAndreas Gohr        $this->assertEquals("The\012Test\012", io_readFile(__DIR__.'/io_readfile/test.txt.bz2'));
52d387bf5eSAndreas Gohr        $this->assertEquals("The\015\012Test\015\012", io_readFile(__DIR__.'/io_readfile/test.txt.bz2', false));
53d387bf5eSAndreas Gohr        $this->assertEquals(false, io_readFile(__DIR__.'/io_readfile/nope.txt.bz2'));
54d387bf5eSAndreas Gohr        $this->assertEquals(false, io_readFile(__DIR__.'/io_readfile/corrupt.txt.bz2'));
55cfb71e37SPatrick Brown        // internal bzfile function
56cfb71e37SPatrick Brown        $this->assertEquals(array("The\015\012","Test\015\012"), bzfile(__DIR__.'/io_readfile/test.txt.bz2', true));
57cfb71e37SPatrick Brown        $this->assertEquals(array_fill(0, 120, str_repeat('a', 80)."\012"), bzfile(__DIR__.'/io_readfile/large.txt.bz2', true));
58cfb71e37SPatrick Brown        $line = str_repeat('a', 8888)."\012";
59cfb71e37SPatrick Brown        $this->assertEquals(array($line,"\012",$line,"!"), bzfile(__DIR__.'/io_readfile/long.txt.bz2', true));
60d387bf5eSAndreas Gohr    }
61d387bf5eSAndreas Gohr
62d387bf5eSAndreas Gohr}
63