Add pp_propname_page index to page_props
[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 parent::setUp();
8 $this->zipDir = __DIR__ . '/../data/zip';
9 }
10
11 function zipCallback( $entry ) {
12 $this->entries[] = $entry;
13 }
14
15 function readZipAssertError( $file, $error, $assertMessage ) {
16 $this->entries = array();
17 $status = ZipDirectoryReader::read( "{$this->zipDir}/$file", array( $this, 'zipCallback' ) );
18 $this->assertTrue( $status->hasMessage( $error ), $assertMessage );
19 }
20
21 function readZipAssertSuccess( $file, $assertMessage ) {
22 $this->entries = array();
23 $status = ZipDirectoryReader::read( "{$this->zipDir}/$file", array( $this, 'zipCallback' ) );
24 $this->assertTrue( $status->isOK(), $assertMessage );
25 }
26
27 function testEmpty() {
28 $this->readZipAssertSuccess( 'empty.zip', 'Empty zip' );
29 }
30
31 function testMultiDisk0() {
32 $this->readZipAssertError( 'split.zip', 'zip-unsupported',
33 'Split zip error' );
34 }
35
36 function testNoSignature() {
37 $this->readZipAssertError( 'nosig.zip', 'zip-wrong-format',
38 'No signature should give "wrong format" error' );
39 }
40
41 function testSimple() {
42 $this->readZipAssertSuccess( 'class.zip', 'Simple ZIP' );
43 $this->assertEquals( $this->entries, array( array(
44 'name' => 'Class.class',
45 'mtime' => '20010115000000',
46 'size' => 1,
47 ) ) );
48 }
49
50 function testBadCentralEntrySignature() {
51 $this->readZipAssertError( 'wrong-central-entry-sig.zip', 'zip-bad',
52 'Bad central entry error' );
53 }
54
55 function testTrailingBytes() {
56 $this->readZipAssertError( 'trail.zip', 'zip-bad',
57 'Trailing bytes error' );
58 }
59
60 function testWrongCDStart() {
61 $this->readZipAssertError( 'wrong-cd-start-disk.zip', 'zip-unsupported',
62 'Wrong CD start disk error' );
63 }
64
65
66 function testCentralDirectoryGap() {
67 $this->readZipAssertError( 'cd-gap.zip', 'zip-bad',
68 'CD gap error' );
69 }
70
71 function testCentralDirectoryTruncated() {
72 $this->readZipAssertError( 'cd-truncated.zip', 'zip-bad',
73 'CD truncated error (should hit unpack() overrun)' );
74 }
75
76 function testLooksLikeZip64() {
77 $this->readZipAssertError( 'looks-like-zip64.zip', 'zip-unsupported',
78 'A file which looks like ZIP64 but isn\'t, should give error' );
79 }
80 }