Merge "Fixed dependencies for jquery.collapsibleTabs"
[lhc/web/wiklou.git] / tests / phpunit / includes / ZipDirectoryReaderTest.php
1 <?php
2
3 class ZipDirectoryReaderTest extends MediaWikiTestCase {
4 var $zipDir, $entries;
5
6 protected function setUp() {
7 $this->zipDir = __DIR__ . '/../data/zip';
8 }
9
10 function zipCallback( $entry ) {
11 $this->entries[] = $entry;
12 }
13
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 );
18 }
19
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 );
24 }
25
26 function testEmpty() {
27 $this->readZipAssertSuccess( 'empty.zip', 'Empty zip' );
28 }
29
30 function testMultiDisk0() {
31 $this->readZipAssertError( 'split.zip', 'zip-unsupported',
32 'Split zip error' );
33 }
34
35 function testNoSignature() {
36 $this->readZipAssertError( 'nosig.zip', 'zip-wrong-format',
37 'No signature should give "wrong format" error' );
38 }
39
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 ) ) );
47 }
48
49 function testBadCentralEntrySignature() {
50 $this->readZipAssertError( 'wrong-central-entry-sig.zip', 'zip-bad',
51 'Bad central entry error' );
52 }
53
54 function testTrailingBytes() {
55 $this->readZipAssertError( 'trail.zip', 'zip-bad',
56 'Trailing bytes error' );
57 }
58
59 function testWrongCDStart() {
60 $this->readZipAssertError( 'wrong-cd-start-disk.zip', 'zip-unsupported',
61 'Wrong CD start disk error' );
62 }
63
64
65 function testCentralDirectoryGap() {
66 $this->readZipAssertError( 'cd-gap.zip', 'zip-bad',
67 'CD gap error' );
68 }
69
70 function testCentralDirectoryTruncated() {
71 $this->readZipAssertError( 'cd-truncated.zip', 'zip-bad',
72 'CD truncated error (should hit unpack() overrun)' );
73 }
74
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' );
78 }
79 }