aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/integration/includes/utils/MWFilePropsTest.php
blob: 2c0330099842c988b73e0db1007af0eede400726 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php

use Wikimedia\FileBackend\FileBackend;

/**
 * @covers \MWFileProps
 */
class MWFilePropsTest extends MediaWikiIntegrationTestCase {
	public static function provideGetPropsFromPath() {
		return [
			'nonexistent.png' => [ 'nonexistent.png', [
				'fileExists' => false,
				'size' => 0,
				'file-mime' => null,
				'major_mime' => null,
				'minor_mime' => null,
				'mime' => null,
				'sha1' => '',
				'metadata' => [],
				'width' => 0,
				'height' => 0,
				'bits' => 0,
				'media_type' => 'UNKNOWN',
			] ],
			'zip-kind-of-valid.png' => [ 'zip-kind-of-valid.png', [
				'fileExists' => true,
				'size' => 189,
				'file-mime' => 'application/zip',
				'major_mime' => 'application',
				'minor_mime' => 'zip',
				'mime' => 'application/zip',
				'sha1' => 'rt7k3bexfau9i8jd5z41oxi3fqz7psb',
				'metadata' => [],
				'width' => 0,
				'height' => 0,
				'bits' => 0,
				'media_type' => 'ARCHIVE',
			] ],
			'tinyrgb.jpg' => [ 'tinyrgb.jpg', [
				'width' => 120,
				'height' => 78,
				'bits' => 8,
				'fileExists' => true,
				'size' => 5118,
				'file-mime' => 'image/jpeg',
				'major_mime' => 'image',
				'minor_mime' => 'jpeg',
				'mime' => 'image/jpeg',
				'sha1' => 'iqrl77mbbzax718nogdpirzfodf7meh',
				'metadata' => [
					'JPEGFileComment' => [
						'File source: http://127.0.0.1:8080/wiki/File:Srgb_copy.jpg',
					],
					'MEDIAWIKI_EXIF_VERSION' => 2,
				],
				'media_type' => 'BITMAP',
			] ],
		];
	}

	/**
	 * @dataProvider provideGetPropsFromPath
	 * @param string $relPath
	 * @param array $expected
	 */
	public function testGetPropsFromPath( $relPath, $expected ) {
		$mwfp = new MWFileProps(
			$this->getServiceContainer()->getMimeAnalyzer()
		);
		$path = __DIR__ . '/../../../data/media/' . $relPath;

		$props = $mwfp->getPropsFromPath( $path, FileBackend::extensionFromPath( $path ) );
		$this->assertArrayEquals( $expected, $props, false, true );
	}
}