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