MediaWiki
REL1_19
|
00001 <?php 00002 00003 class ZipDirectoryReaderTest extends MediaWikiTestCase { 00004 var $zipDir, $entries; 00005 00006 function setUp() { 00007 $this->zipDir = dirname( __FILE__ ) . '/../data/zip'; 00008 } 00009 00010 function zipCallback( $entry ) { 00011 $this->entries[] = $entry; 00012 } 00013 00014 function readZipAssertError( $file, $error, $assertMessage ) { 00015 $this->entries = array(); 00016 $status = ZipDirectoryReader::read( "{$this->zipDir}/$file", array( $this, 'zipCallback' ) ); 00017 $this->assertTrue( $status->hasMessage( $error ), $assertMessage ); 00018 } 00019 00020 function readZipAssertSuccess( $file, $assertMessage ) { 00021 $this->entries = array(); 00022 $status = ZipDirectoryReader::read( "{$this->zipDir}/$file", array( $this, 'zipCallback' ) ); 00023 $this->assertTrue( $status->isOK(), $assertMessage ); 00024 } 00025 00026 function testEmpty() { 00027 $this->readZipAssertSuccess( 'empty.zip', 'Empty zip' ); 00028 } 00029 00030 function testMultiDisk0() { 00031 $this->readZipAssertError( 'split.zip', 'zip-unsupported', 00032 'Split zip error' ); 00033 } 00034 00035 function testNoSignature() { 00036 $this->readZipAssertError( 'nosig.zip', 'zip-wrong-format', 00037 'No signature should give "wrong format" error' ); 00038 } 00039 00040 function testSimple() { 00041 $this->readZipAssertSuccess( 'class.zip', 'Simple ZIP' ); 00042 $this->assertEquals( $this->entries, array( array( 00043 'name' => 'Class.class', 00044 'mtime' => '20010115000000', 00045 'size' => 1, 00046 ) ) ); 00047 } 00048 00049 function testBadCentralEntrySignature() { 00050 $this->readZipAssertError( 'wrong-central-entry-sig.zip', 'zip-bad', 00051 'Bad central entry error' ); 00052 } 00053 00054 function testTrailingBytes() { 00055 $this->readZipAssertError( 'trail.zip', 'zip-bad', 00056 'Trailing bytes error' ); 00057 } 00058 00059 function testWrongCDStart() { 00060 $this->readZipAssertError( 'wrong-cd-start-disk.zip', 'zip-unsupported', 00061 'Wrong CD start disk error' ); 00062 } 00063 00064 00065 function testCentralDirectoryGap() { 00066 $this->readZipAssertError( 'cd-gap.zip', 'zip-bad', 00067 'CD gap error' ); 00068 } 00069 00070 function testCentralDirectoryTruncated() { 00071 $this->readZipAssertError( 'cd-truncated.zip', 'zip-bad', 00072 'CD truncated error (should hit unpack() overrun)' ); 00073 } 00074 00075 function testLooksLikeZip64() { 00076 $this->readZipAssertError( 'looks-like-zip64.zip', 'zip-unsupported', 00077 'A file which looks like ZIP64 but isn\'t, should give error' ); 00078 } 00079 }