4 * @covers ZipDirectoryReader
5 * NOTE: this test is more like an integration test than a unit test
7 class ZipDirectoryReaderTest
extends MediaWikiUnitTestCase
{
12 protected function setUp() {
14 $this->zipDir
= __DIR__
. '/../../../data/zip';
17 function zipCallback( $entry ) {
18 $this->entries
[] = $entry;
21 function readZipAssertError( $file, $error, $assertMessage ) {
23 $status = ZipDirectoryReader
::read( "{$this->zipDir}/$file", [ $this, 'zipCallback' ] );
24 $this->assertTrue( $status->hasMessage( $error ), $assertMessage );
27 function readZipAssertSuccess( $file, $assertMessage ) {
29 $status = ZipDirectoryReader
::read( "{$this->zipDir}/$file", [ $this, 'zipCallback' ] );
30 $this->assertTrue( $status->isOK(), $assertMessage );
33 public function testEmpty() {
34 $this->readZipAssertSuccess( 'empty.zip', 'Empty zip' );
37 public function testMultiDisk0() {
38 $this->readZipAssertError( 'split.zip', 'zip-unsupported',
42 public function testNoSignature() {
43 $this->readZipAssertError( 'nosig.zip', 'zip-wrong-format',
44 'No signature should give "wrong format" error' );
47 public function testSimple() {
48 $this->readZipAssertSuccess( 'class.zip', 'Simple ZIP' );
49 $this->assertEquals( $this->entries
, [ [
50 'name' => 'Class.class',
51 'mtime' => '20010115000000',
56 public function testBadCentralEntrySignature() {
57 $this->readZipAssertError( 'wrong-central-entry-sig.zip', 'zip-bad',
58 'Bad central entry error' );
61 public function testTrailingBytes() {
62 // Due to T40432 this is now zip-wrong-format instead of zip-bad
63 $this->readZipAssertError( 'trail.zip', 'zip-wrong-format',
64 'Trailing bytes error' );
67 public function testWrongCDStart() {
68 $this->readZipAssertError( 'wrong-cd-start-disk.zip', 'zip-unsupported',
69 'Wrong CD start disk error' );
72 public function testCentralDirectoryGap() {
73 $this->readZipAssertError( 'cd-gap.zip', 'zip-bad',
77 public function testCentralDirectoryTruncated() {
78 $this->readZipAssertError( 'cd-truncated.zip', 'zip-bad',
79 'CD truncated error (should hit unpack() overrun)' );
82 public function testLooksLikeZip64() {
83 $this->readZipAssertError( 'looks-like-zip64.zip', 'zip-unsupported',
84 'A file which looks like ZIP64 but isn\'t, should give error' );