| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
class ZipDirectoryReaderTest extends MediaWikiIntegrationTestCase { |
| 7 |
private const ZIP_DIR = __DIR__ . '/../../data/zip'; |
| 8 |
|
| 9 |
|
| 10 |
protected $entries; |
| 11 |
|
| 12 |
public function zipCallback( $entry ) { |
| 13 |
$this->entries[] = $entry; |
| 14 |
} |
| 15 |
|
| 16 |
public function readZipAssertError( $file, $error, $assertMessage ) { |
| 17 |
$this->entries = []; |
| 18 |
$status = ZipDirectoryReader::read( self::ZIP_DIR . "/$file", [ $this, 'zipCallback' ] ); |
| 19 |
$this->assertStatusError( $error, $status, $assertMessage ); |
| 20 |
} |
| 21 |
|
| 22 |
public function readZipAssertSuccess( $file, $assertMessage ) { |
| 23 |
$this->entries = []; |
| 24 |
$status = ZipDirectoryReader::read( self::ZIP_DIR . "/$file", [ $this, 'zipCallback' ] ); |
| 25 |
$this->assertStatusOK( $status, $assertMessage ); |
| 26 |
} |
| 27 |
|
| 28 |
public function testEmpty() { |
| 29 |
$this->readZipAssertSuccess( 'empty.zip', 'Empty zip' ); |
| 30 |
} |
| 31 |
|
| 32 |
public function testMultiDisk0() { |
| 33 |
$this->readZipAssertError( 'split.zip', 'zip-unsupported', |
| 34 |
'Split zip error' ); |
| 35 |
} |
| 36 |
|
| 37 |
public function testNoSignature() { |
| 38 |
$this->readZipAssertError( 'nosig.zip', 'zip-wrong-format', |
| 39 |
'No signature should give "wrong format" error' ); |
| 40 |
} |
| 41 |
|
| 42 |
public function testSimple() { |
| 43 |
$this->readZipAssertSuccess( 'class.zip', 'Simple ZIP' ); |
| 44 |
$this->assertEquals( [ [ |
| 45 |
'name' => 'Class.class', |
| 46 |
'mtime' => '20010115000000', |
| 47 |
'size' => 1, |
| 48 |
] ], $this->entries ); |
| 49 |
} |
| 50 |
|
| 51 |
public function testBadCentralEntrySignature() { |
| 52 |
$this->readZipAssertError( 'wrong-central-entry-sig.zip', 'zip-bad', |
| 53 |
'Bad central entry error' ); |
| 54 |
} |
| 55 |
|
| 56 |
public function testTrailingBytes() { |
| 57 |
|
| 58 |
$this->readZipAssertError( 'trail.zip', 'zip-wrong-format', |
| 59 |
'Trailing bytes error' ); |
| 60 |
} |
| 61 |
|
| 62 |
public function testWrongCDStart() { |
| 63 |
$this->readZipAssertError( 'wrong-cd-start-disk.zip', 'zip-unsupported', |
| 64 |
'Wrong CD start disk error' ); |
| 65 |
} |
| 66 |
|
| 67 |
public function testCentralDirectoryGap() { |
| 68 |
$this->readZipAssertError( 'cd-gap.zip', 'zip-bad', |
| 69 |
'CD gap error' ); |
| 70 |
} |
| 71 |
|
| 72 |
public function testCentralDirectoryTruncated() { |
| 73 |
$this->readZipAssertError( 'cd-truncated.zip', 'zip-bad', |
| 74 |
'CD truncated error (should hit unpack() overrun)' ); |
| 75 |
} |
| 76 |
|
| 77 |
public function testLooksLikeZip64() { |
| 78 |
$this->readZipAssertError( 'looks-like-zip64.zip', 'zip-unsupported', |
| 79 |
'A file which looks like ZIP64 but isn\'t, should give error' ); |
| 80 |
} |
| 81 |
} |