Fix typo erronously -> erroneously
[lhc/web/wiklou.git] / tests / phpunit / includes / ZipDirectoryReaderTest.php
1 <?php
2
3 /**
4 * @covers ZipDirectoryReader
5 * NOTE: this test is more like an integration test than a unit test
6 */
7 class ZipDirectoryReaderTest extends MediaWikiTestCase {
8 var $zipDir, $entries;
9
10 protected function setUp() {
11 parent::setUp();
12 $this->zipDir = __DIR__ . '/../data/zip';
13 }
14
15 function zipCallback( $entry ) {
16 $this->entries[] = $entry;
17 }
18
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 );
23 }
24
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 );
29 }
30
31 function testEmpty() {
32 $this->readZipAssertSuccess( 'empty.zip', 'Empty zip' );
33 }
34
35 function testMultiDisk0() {
36 $this->readZipAssertError( 'split.zip', 'zip-unsupported',
37 'Split zip error' );
38 }
39
40 function testNoSignature() {
41 $this->readZipAssertError( 'nosig.zip', 'zip-wrong-format',
42 'No signature should give "wrong format" error' );
43 }
44
45 function testSimple() {
46 $this->readZipAssertSuccess( 'class.zip', 'Simple ZIP' );
47 $this->assertEquals( $this->entries, array( array(
48 'name' => 'Class.class',
49 'mtime' => '20010115000000',
50 'size' => 1,
51 ) ) );
52 }
53
54 function testBadCentralEntrySignature() {
55 $this->readZipAssertError( 'wrong-central-entry-sig.zip', 'zip-bad',
56 'Bad central entry error' );
57 }
58
59 function testTrailingBytes() {
60 $this->readZipAssertError( 'trail.zip', 'zip-bad',
61 'Trailing bytes error' );
62 }
63
64 function testWrongCDStart() {
65 $this->readZipAssertError( 'wrong-cd-start-disk.zip', 'zip-unsupported',
66 'Wrong CD start disk error' );
67 }
68
69
70 function testCentralDirectoryGap() {
71 $this->readZipAssertError( 'cd-gap.zip', 'zip-bad',
72 'CD gap error' );
73 }
74
75 function testCentralDirectoryTruncated() {
76 $this->readZipAssertError( 'cd-truncated.zip', 'zip-bad',
77 'CD truncated error (should hit unpack() overrun)' );
78 }
79
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' );
83 }
84 }