1<?php 2 3class io_getSizeFile_test extends DokuWikiTest { 4 5 /* 6 * dependency for tests needing zlib extension to pass 7 */ 8 public function test_ext_zlib() { 9 if (!DOKU_HAS_GZIP) { 10 $this->markTestSkipped('skipping all zlib tests. Need zlib extension'); 11 } 12 } 13 14 /* 15 * dependency for tests needing zlib extension to pass 16 */ 17 public function test_ext_bz2() { 18 if (!DOKU_HAS_BZIP) { 19 $this->markTestSkipped('skipping all bzip2 tests. Need bz2 extension'); 20 } 21 } 22 23 function test_plain(){ 24 // since git converts line endings, we can't check in this test file but have to create it ourselves 25 $plain = TMP_DIR.'/test.txt'; 26 file_put_contents($plain, "The\015\012Test\015\012"); 27 28 $this->assertEquals(11, io_getSizeFile($plain)); 29 $this->assertEquals(0, io_getSizeFile(__DIR__.'/io_readfile/nope.txt')); 30 $plain_mb = TMP_DIR.'/test.txt'; 31 io_saveFile($plain_mb, "string with utf-8 chars åèö - doo-bee doo-bee dooh\012"); 32 $this->assertEquals(54, io_getSizeFile($plain_mb)); 33 } 34 35 /** 36 * @depends test_ext_zlib 37 */ 38 function test_gzfiles(){ 39 $this->assertEquals(11, io_getSizeFile(__DIR__.'/io_readfile/test.txt.gz')); 40 $this->assertEquals(0, io_getSizeFile(__DIR__.'/io_readfile/nope.txt.gz')); 41 $this->assertEquals(11, io_getSizeFile(__DIR__.'/io_readfile/corrupt.txt.gz')); 42 $gz_mb = TMP_DIR.'/test.txt.gz'; 43 io_saveFile($gz_mb, "string with utf-8 chars åèö - doo-bee doo-bee dooh\012"); 44 $this->assertEquals(54, io_getSizeFile($gz_mb)); 45 } 46 47 /** 48 * @depends test_ext_bz2 49 */ 50 function test_bzfiles(){ 51 52 $this->assertEquals(11, io_getSizeFile(__DIR__.'/io_readfile/test.txt.bz2')); 53 $this->assertEquals(0, io_getSizeFile(__DIR__.'/io_readfile/nope.txt.bz2')); 54 $this->assertEquals(0, io_getSizeFile(__DIR__.'/io_readfile/corrupt.txt.bz2')); 55 $this->assertEquals(9720, io_getSizeFile(__DIR__.'/io_readfile/large.txt.bz2')); 56 $this->assertEquals(17780, io_getSizeFile(__DIR__.'/io_readfile/long.txt.bz2')); 57 $bz_mb = TMP_DIR.'/test.txt.bz2'; 58 io_saveFile($bz_mb, "string with utf-8 chars åèö - doo-bee doo-bee dooh\012"); 59 $this->assertEquals(54, io_getSizeFile($bz_mb)); 60 } 61 62} 63