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