59c70473230e317117d7a2c577f1cdc5cbbace84
4 * @covers ZipDirectoryReader
5 * NOTE: this test is more like an integration test than a unit test
7 class ZipDirectoryReaderTest
extends MediaWikiTestCase
{
10 protected function setUp() {
12 $this->zipDir
= __DIR__
. '/../data/zip';
15 function zipCallback( $entry ) {
16 $this->entries
[] = $entry;
19 function readZipAssertError( $file, $error, $assertMessage ) {
20 $this->entries
= array();
21 $status = ZipDirectoryReader
::read( "{$this->zipDir}/$file", array( $this, 'zipCallback' ) );
22 $this->assertTrue( $status->hasMessage( $error ), $assertMessage );
25 function readZipAssertSuccess( $file, $assertMessage ) {
26 $this->entries
= array();
27 $status = ZipDirectoryReader
::read( "{$this->zipDir}/$file", array( $this, 'zipCallback' ) );
28 $this->assertTrue( $status->isOK(), $assertMessage );
31 function testEmpty() {
32 $this->readZipAssertSuccess( 'empty.zip', 'Empty zip' );
35 function testMultiDisk0() {
36 $this->readZipAssertError( 'split.zip', 'zip-unsupported',
40 function testNoSignature() {
41 $this->readZipAssertError( 'nosig.zip', 'zip-wrong-format',
42 'No signature should give "wrong format" error' );
45 function testSimple() {
46 $this->readZipAssertSuccess( 'class.zip', 'Simple ZIP' );
47 $this->assertEquals( $this->entries
, array( array(
48 'name' => 'Class.class',
49 'mtime' => '20010115000000',
54 function testBadCentralEntrySignature() {
55 $this->readZipAssertError( 'wrong-central-entry-sig.zip', 'zip-bad',
56 'Bad central entry error' );
59 function testTrailingBytes() {
60 $this->readZipAssertError( 'trail.zip', 'zip-bad',
61 'Trailing bytes error' );
64 function testWrongCDStart() {
65 $this->readZipAssertError( 'wrong-cd-start-disk.zip', 'zip-unsupported',
66 'Wrong CD start disk error' );
70 function testCentralDirectoryGap() {
71 $this->readZipAssertError( 'cd-gap.zip', 'zip-bad',
75 function testCentralDirectoryTruncated() {
76 $this->readZipAssertError( 'cd-truncated.zip', 'zip-bad',
77 'CD truncated error (should hit unpack() overrun)' );
80 function testLooksLikeZip64() {
81 $this->readZipAssertError( 'looks-like-zip64.zip', 'zip-unsupported',
82 'A file which looks like ZIP64 but isn\'t, should give error' );