4 * @covers ZipDirectoryReader
5 * NOTE: this test is more like an integration test than a unit test
7 class ZipDirectoryReaderTest
extends PHPUnit_Framework_TestCase
{
9 use MediaWikiCoversValidator
;
14 protected function setUp() {
16 $this->zipDir
= __DIR__
. '/../../data/zip';
19 function zipCallback( $entry ) {
20 $this->entries
[] = $entry;
23 function readZipAssertError( $file, $error, $assertMessage ) {
25 $status = ZipDirectoryReader
::read( "{$this->zipDir}/$file", [ $this, 'zipCallback' ] );
26 $this->assertTrue( $status->hasMessage( $error ), $assertMessage );
29 function readZipAssertSuccess( $file, $assertMessage ) {
31 $status = ZipDirectoryReader
::read( "{$this->zipDir}/$file", [ $this, 'zipCallback' ] );
32 $this->assertTrue( $status->isOK(), $assertMessage );
35 public function testEmpty() {
36 $this->readZipAssertSuccess( 'empty.zip', 'Empty zip' );
39 public function testMultiDisk0() {
40 $this->readZipAssertError( 'split.zip', 'zip-unsupported',
44 public function testNoSignature() {
45 $this->readZipAssertError( 'nosig.zip', 'zip-wrong-format',
46 'No signature should give "wrong format" error' );
49 public function testSimple() {
50 $this->readZipAssertSuccess( 'class.zip', 'Simple ZIP' );
51 $this->assertEquals( $this->entries
, [ [
52 'name' => 'Class.class',
53 'mtime' => '20010115000000',
58 public function testBadCentralEntrySignature() {
59 $this->readZipAssertError( 'wrong-central-entry-sig.zip', 'zip-bad',
60 'Bad central entry error' );
63 public function testTrailingBytes() {
64 $this->readZipAssertError( 'trail.zip', 'zip-bad',
65 'Trailing bytes error' );
68 public function testWrongCDStart() {
69 $this->readZipAssertError( 'wrong-cd-start-disk.zip', 'zip-unsupported',
70 'Wrong CD start disk error' );
73 public function testCentralDirectoryGap() {
74 $this->readZipAssertError( 'cd-gap.zip', 'zip-bad',
78 public function testCentralDirectoryTruncated() {
79 $this->readZipAssertError( 'cd-truncated.zip', 'zip-bad',
80 'CD truncated error (should hit unpack() overrun)' );
83 public function testLooksLikeZip64() {
84 $this->readZipAssertError( 'looks-like-zip64.zip', 'zip-unsupported',
85 'A file which looks like ZIP64 but isn\'t, should give error' );