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