Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / includes / utils / ZipDirectoryReaderTest.php
blob792253464efcd2b754c47157e7657fc3fd060c5f
1 <?php
3 /**
4 * @covers \ZipDirectoryReader
5 */
6 class ZipDirectoryReaderTest extends MediaWikiIntegrationTestCase {
7 private const ZIP_DIR = __DIR__ . '/../../data/zip';
9 /** @var array[] */
10 protected $entries;
12 public function zipCallback( $entry ) {
13 $this->entries[] = $entry;
16 public function readZipAssertError( $file, $error, $assertMessage ) {
17 $this->entries = [];
18 $status = ZipDirectoryReader::read( self::ZIP_DIR . "/$file", [ $this, 'zipCallback' ] );
19 $this->assertStatusError( $error, $status, $assertMessage );
22 public function readZipAssertSuccess( $file, $assertMessage ) {
23 $this->entries = [];
24 $status = ZipDirectoryReader::read( self::ZIP_DIR . "/$file", [ $this, 'zipCallback' ] );
25 $this->assertStatusOK( $status, $assertMessage );
28 public function testEmpty() {
29 $this->readZipAssertSuccess( 'empty.zip', 'Empty zip' );
32 public function testMultiDisk0() {
33 $this->readZipAssertError( 'split.zip', 'zip-unsupported',
34 'Split zip error' );
37 public function testNoSignature() {
38 $this->readZipAssertError( 'nosig.zip', 'zip-wrong-format',
39 'No signature should give "wrong format" error' );
42 public function testSimple() {
43 $this->readZipAssertSuccess( 'class.zip', 'Simple ZIP' );
44 $this->assertEquals( [ [
45 'name' => 'Class.class',
46 'mtime' => '20010115000000',
47 'size' => 1,
48 ] ], $this->entries );
51 public function testBadCentralEntrySignature() {
52 $this->readZipAssertError( 'wrong-central-entry-sig.zip', 'zip-bad',
53 'Bad central entry error' );
56 public function testTrailingBytes() {
57 // Due to T40432 this is now zip-wrong-format instead of zip-bad
58 $this->readZipAssertError( 'trail.zip', 'zip-wrong-format',
59 'Trailing bytes error' );
62 public function testWrongCDStart() {
63 $this->readZipAssertError( 'wrong-cd-start-disk.zip', 'zip-unsupported',
64 'Wrong CD start disk error' );
67 public function testCentralDirectoryGap() {
68 $this->readZipAssertError( 'cd-gap.zip', 'zip-bad',
69 'CD gap error' );
72 public function testCentralDirectoryTruncated() {
73 $this->readZipAssertError( 'cd-truncated.zip', 'zip-bad',
74 'CD truncated error (should hit unpack() overrun)' );
77 public function testLooksLikeZip64() {
78 $this->readZipAssertError( 'looks-like-zip64.zip', 'zip-unsupported',
79 'A file which looks like ZIP64 but isn\'t, should give error' );