4 * @covers \ZipDirectoryReader
6 class ZipDirectoryReaderTest
extends MediaWikiIntegrationTestCase
{
7 private const ZIP_DIR
= __DIR__
. '/../../data/zip';
12 public function zipCallback( $entry ) {
13 $this->entries
[] = $entry;
16 public function readZipAssertError( $file, $error, $assertMessage ) {
18 $status = ZipDirectoryReader
::read( self
::ZIP_DIR
. "/$file", [ $this, 'zipCallback' ] );
19 $this->assertStatusError( $error, $status, $assertMessage );
22 public function readZipAssertSuccess( $file, $assertMessage ) {
24 $status = ZipDirectoryReader
::read( self
::ZIP_DIR
. "/$file", [ $this, 'zipCallback' ] );
25 $this->assertStatusOK( $status, $assertMessage );
28 public function testEmpty() {
29 $this->readZipAssertSuccess( 'empty.zip', 'Empty zip' );
32 public function testMultiDisk0() {
33 $this->readZipAssertError( 'split.zip', 'zip-unsupported',
37 public function testNoSignature() {
38 $this->readZipAssertError( 'nosig.zip', 'zip-wrong-format',
39 'No signature should give "wrong format" error' );
42 public function testSimple() {
43 $this->readZipAssertSuccess( 'class.zip', 'Simple ZIP' );
44 $this->assertEquals( [ [
45 'name' => 'Class.class',
46 'mtime' => '20010115000000',
48 ] ], $this->entries
);
51 public function testBadCentralEntrySignature() {
52 $this->readZipAssertError( 'wrong-central-entry-sig.zip', 'zip-bad',
53 'Bad central entry error' );
56 public function testTrailingBytes() {
57 // Due to T40432 this is now zip-wrong-format instead of zip-bad
58 $this->readZipAssertError( 'trail.zip', 'zip-wrong-format',
59 'Trailing bytes error' );
62 public function testWrongCDStart() {
63 $this->readZipAssertError( 'wrong-cd-start-disk.zip', 'zip-unsupported',
64 'Wrong CD start disk error' );
67 public function testCentralDirectoryGap() {
68 $this->readZipAssertError( 'cd-gap.zip', 'zip-bad',
72 public function testCentralDirectoryTruncated() {
73 $this->readZipAssertError( 'cd-truncated.zip', 'zip-bad',
74 'CD truncated error (should hit unpack() overrun)' );
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' );