MediaWiki  master
MSCompoundFileReaderTest.php
Go to the documentation of this file.
1 <?php
2 /*
3  * Copyright 2019 Wikimedia Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License"); you may
6  * not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software distributed
12  * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
13  * OF ANY KIND, either express or implied. See the License for the
14  * specific language governing permissions and limitations under the License.
15  */
16 
22  public static function provideValid() {
23  return [
24  [ 'calc.xls', 'application/vnd.ms-excel' ],
25  [ 'excel2016-compat97.xls', 'application/vnd.ms-excel' ],
26  [ 'gnumeric.xls', 'application/vnd.ms-excel' ],
27  [ 'impress.ppt', 'application/vnd.ms-powerpoint' ],
28  [ 'powerpoint2016-compat97.ppt', 'application/vnd.ms-powerpoint' ],
29  [ 'word2016-compat97.doc', 'application/msword' ],
30  [ 'writer.doc', 'application/msword' ],
31  ];
32  }
33 
35  public function testReadFile( $fileName, $expectedMime ) {
36  global $IP;
37 
38  $info = MSCompoundFileReader::readFile( "$IP/tests/phpunit/data/MSCompoundFileReader/$fileName" );
39  $this->assertTrue( $info['valid'] );
40  $this->assertSame( $expectedMime, $info['mime'] );
41  }
42 
43  public static function provideInvalid() {
44  return [
45  [ 'dir-beyond-end.xls', 'ERROR_READ_PAST_END' ],
46  [ 'fat-loop.xls', 'ERROR_INVALID_FORMAT' ],
47  [ 'invalid-signature.xls', 'ERROR_INVALID_SIGNATURE' ],
48  ];
49  }
50 
52  public function testReadFileInvalid( $fileName, $expectedError ) {
53  global $IP;
54 
55  $info = MSCompoundFileReader::readFile( "$IP/tests/phpunit/data/MSCompoundFileReader/$fileName" );
56  $this->assertFalse( $info['valid'] );
57  $this->assertSame( constant( MSCompoundFileReader::class . '::' . $expectedError ),
58  $info['errorCode'] );
59  }
60 }
$IP
Definition: WebStart.php:41
static static readFile( $fileName)
Read a file by name.
Media MSCompoundFileReader.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
testReadFile( $fileName, $expectedMime)
provideValid
testReadFileInvalid( $fileName, $expectedError)
provideInvalid