Merged r114672 from wmf1.19 plus tests; crosswiki block name/id fix.
[mediawiki.git] / tests / phpunit / includes / ZipDirectoryReaderTest.php
blobf7ca59e241cc76f3c4e71599bea2091acdc1520f
1 <?php
3 class ZipDirectoryReaderTest extends MediaWikiTestCase {
4 var $zipDir, $entries;
6 function setUp() {
7 $this->zipDir = dirname( __FILE__ ) . '/../data/zip';
10 function zipCallback( $entry ) {
11 $this->entries[] = $entry;
14 function readZipAssertError( $file, $error, $assertMessage ) {
15 $this->entries = array();
16 $status = ZipDirectoryReader::read( "{$this->zipDir}/$file", array( $this, 'zipCallback' ) );
17 $this->assertTrue( $status->hasMessage( $error ), $assertMessage );
20 function readZipAssertSuccess( $file, $assertMessage ) {
21 $this->entries = array();
22 $status = ZipDirectoryReader::read( "{$this->zipDir}/$file", array( $this, 'zipCallback' ) );
23 $this->assertTrue( $status->isOK(), $assertMessage );
26 function testEmpty() {
27 $this->readZipAssertSuccess( 'empty.zip', 'Empty zip' );
30 function testMultiDisk0() {
31 $this->readZipAssertError( 'split.zip', 'zip-unsupported',
32 'Split zip error' );
35 function testNoSignature() {
36 $this->readZipAssertError( 'nosig.zip', 'zip-wrong-format',
37 'No signature should give "wrong format" error' );
40 function testSimple() {
41 $this->readZipAssertSuccess( 'class.zip', 'Simple ZIP' );
42 $this->assertEquals( $this->entries, array( array(
43 'name' => 'Class.class',
44 'mtime' => '20010115000000',
45 'size' => 1,
46 ) ) );
49 function testBadCentralEntrySignature() {
50 $this->readZipAssertError( 'wrong-central-entry-sig.zip', 'zip-bad',
51 'Bad central entry error' );
54 function testTrailingBytes() {
55 $this->readZipAssertError( 'trail.zip', 'zip-bad',
56 'Trailing bytes error' );
59 function testWrongCDStart() {
60 $this->readZipAssertError( 'wrong-cd-start-disk.zip', 'zip-unsupported',
61 'Wrong CD start disk error' );
65 function testCentralDirectoryGap() {
66 $this->readZipAssertError( 'cd-gap.zip', 'zip-bad',
67 'CD gap error' );
70 function testCentralDirectoryTruncated() {
71 $this->readZipAssertError( 'cd-truncated.zip', 'zip-bad',
72 'CD truncated error (should hit unpack() overrun)' );
75 function testLooksLikeZip64() {
76 $this->readZipAssertError( 'looks-like-zip64.zip', 'zip-unsupported',
77 'A file which looks like ZIP64 but isn\'t, should give error' );