Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / includes / utils / FileContentsHasherTest.php
blob33e047fb3c8ce2213bcb22ae4d6d84d20c072838
1 <?php
3 /**
4 * @covers \FileContentsHasher
5 */
6 class FileContentsHasherTest extends PHPUnit\Framework\TestCase {
8 use MediaWikiCoversValidator;
10 public static function provideSingleFile() {
11 return array_map( static function ( $file ) {
12 return [ $file, file_get_contents( $file ) ];
13 }, glob( __DIR__ . '/../../data/filecontentshasher/*.*' ) );
16 /**
17 * @dataProvider provideSingleFile
19 public function testSingleFileHash( $fileName, $contents ) {
20 $expected = hash( 'md4', $contents );
21 $actualHash = FileContentsHasher::getFileContentsHash( $fileName );
22 $this->assertEquals( $expected, $actualHash );
24 $actualHashRepeat = FileContentsHasher::getFileContentsHash( $fileName );
25 $this->assertEquals( $expected, $actualHashRepeat );
28 public function provideMultipleFiles() {
29 return [
30 [ $this->provideSingleFile() ]
34 /**
35 * @dataProvider provideMultipleFiles
37 public function testMultipleFileHash( $files ) {
38 $fileNames = [];
39 $hashes = [];
40 foreach ( $files as [ $fileName, $contents ] ) {
41 $fileNames[] = $fileName;
42 $hashes[] = hash( 'md4', $contents );
45 $expectedHash = hash( 'md4', implode( '', $hashes ) );
46 $actualHash = FileContentsHasher::getFileContentsHash( $fileNames );
47 $this->assertEquals( $expectedHash, $actualHash );
49 $actualHashRepeat = FileContentsHasher::getFileContentsHash( $fileNames );
50 $this->assertEquals( $expectedHash, $actualHashRepeat );