Debian Codegraph @

tests/phpunit/includes/filebackend/FileBackendStoreTest.php

raw symbols SCIP
1 <?php
2
3 namespace phpunit\includes\filebackend;
4
5 use MediaWikiIntegrationTestCase;
6 use Wikimedia\FileBackend\FileBackend;
7 use Wikimedia\FileBackend\MemoryFileBackend;
8 use Wikimedia\TestingAccessWrapper;
9
10 /**
11 * @covers \Wikimedia\FileBackend\FileBackendStore
12 */
13 class FileBackendStoreTest extends MediaWikiIntegrationTestCase {
14
15 /**
16 * @dataProvider provider_testGetContentType
17 */
18 public function testGetContentType( $mimeFromString ) {
19 global $IP;
20
21 if ( $mimeFromString ) {
22 $mimeCallback = [ $this->getServiceContainer()->getFileBackendGroup(), 'guessMimeInternal' ];
23 } else {
24 $mimeCallback = null;
25 }
26
27 $be = TestingAccessWrapper::newFromObject( new MemoryFileBackend( [
28 'name' => 'testing',
29 'class' => MemoryFileBackend::class,
30 'wikiId' => 'meow',
31 'mimeCallback' => $mimeCallback,
32 ] ) );
33
34 $dst = 'mwstore://testing/container/path/to/file_no_ext';
35 $src = "$IP/tests/phpunit/data/media/srgb.jpg";
36 $this->assertEquals( 'image/jpeg', $be->getContentType( $dst, null, $src ) );
37 $this->assertEquals( $mimeFromString ? 'image/jpeg' : 'unknown/unknown',
38 $be->getContentType( $dst, file_get_contents( $src ), null ) );
39
40 $src = "$IP/tests/phpunit/data/media/Png-native-test.png";
41 $this->assertEquals( 'image/png', $be->getContentType( $dst, null, $src ) );
42 $this->assertEquals( $mimeFromString ? 'image/png' : 'unknown/unknown',
43 $be->getContentType( $dst, file_get_contents( $src ), null ) );
44 }
45
46 public static function provider_testGetContentType() {
47 return [
48 [ false ],
49 [ true ],
50 ];
51 }
52
53 public function testSanitizeOpHeaders() {
54 $be = TestingAccessWrapper::newFromObject( new MemoryFileBackend( [
55 'name' => 'localtesting',
56 'wikiId' => 'wikidb',
57 ] ) );
58
59 $input = [
60 'headers' => [
61 'content-Disposition' => FileBackend::makeContentDisposition( 'inline', 'name' ),
62 'Content-dUration' => 25.6,
63 'X-LONG-VALUE' => str_pad( '0', 300 ),
64 'CONTENT-LENGTH' => 855055,
65 ],
66 ];
67 $expected = [
68 'headers' => [
69 'content-disposition' => FileBackend::makeContentDisposition( 'inline', 'name' ),
70 'content-duration' => 25.6,
71 'content-length' => 855055,
72 ],
73 ];
74
75 $actual = @$be->sanitizeOpHeaders( $input );
76 $this->assertEquals( $expected, $actual, "Header sanitized properly" );
77 }
78
79 }