wiki.techinc.nl/tests/phpunit/integration/includes/utils/MWFilePropsTest.php
Tim Starling 5e30a927bc tests: Make some PHPUnit data providers static
Just methods where adding "static" to the declaration was enough, I
didn't do anything with providers that used $this.

Initially by search and replace. There were many mistakes which I
found mostly by running the PHPStorm inspection which searches for
$this usage in a static method. Later I used the PHPStorm "make static"
action which avoids the more obvious mistakes.

Bug: T332865
Change-Id: I47ed6692945607dfa5c139d42edbd934fa4f3a36
2023-03-24 02:53:57 +00:00

73 lines
1.8 KiB
PHP

<?php
/**
* @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 );
}
}