3 class ZipDirectoryReaderTest
extends MediaWikiTestCase
{
6 protected function setUp() {
8 $this->zipDir
= __DIR__
. '/../data/zip';
11 function zipCallback( $entry ) {
12 $this->entries
[] = $entry;
15 function readZipAssertError( $file, $error, $assertMessage ) {
16 $this->entries
= array();
17 $status = ZipDirectoryReader
::read( "{$this->zipDir}/$file", array( $this, 'zipCallback' ) );
18 $this->assertTrue( $status->hasMessage( $error ), $assertMessage );
21 function readZipAssertSuccess( $file, $assertMessage ) {
22 $this->entries
= array();
23 $status = ZipDirectoryReader
::read( "{$this->zipDir}/$file", array( $this, 'zipCallback' ) );
24 $this->assertTrue( $status->isOK(), $assertMessage );
27 function testEmpty() {
28 $this->readZipAssertSuccess( 'empty.zip', 'Empty zip' );
31 function testMultiDisk0() {
32 $this->readZipAssertError( 'split.zip', 'zip-unsupported',
36 function testNoSignature() {
37 $this->readZipAssertError( 'nosig.zip', 'zip-wrong-format',
38 'No signature should give "wrong format" error' );
41 function testSimple() {
42 $this->readZipAssertSuccess( 'class.zip', 'Simple ZIP' );
43 $this->assertEquals( $this->entries
, array( array(
44 'name' => 'Class.class',
45 'mtime' => '20010115000000',
50 function testBadCentralEntrySignature() {
51 $this->readZipAssertError( 'wrong-central-entry-sig.zip', 'zip-bad',
52 'Bad central entry error' );
55 function testTrailingBytes() {
56 $this->readZipAssertError( 'trail.zip', 'zip-bad',
57 'Trailing bytes error' );
60 function testWrongCDStart() {
61 $this->readZipAssertError( 'wrong-cd-start-disk.zip', 'zip-unsupported',
62 'Wrong CD start disk error' );
66 function testCentralDirectoryGap() {
67 $this->readZipAssertError( 'cd-gap.zip', 'zip-bad',
71 function testCentralDirectoryTruncated() {
72 $this->readZipAssertError( 'cd-truncated.zip', 'zip-bad',
73 'CD truncated error (should hit unpack() overrun)' );
76 function testLooksLikeZip64() {
77 $this->readZipAssertError( 'looks-like-zip64.zip', 'zip-unsupported',
78 'A file which looks like ZIP64 but isn\'t, should give error' );