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