MediaWiki REL1_31
FileContentsHasherTest.php
Go to the documentation of this file.
1<?php
2
6class FileContentsHasherTest extends PHPUnit\Framework\TestCase {
7
8 use MediaWikiCoversValidator;
9
10 public function provideSingleFile() {
11 return array_map( function ( $file ) {
12 return [ $file, file_get_contents( $file ) ];
13 }, glob( __DIR__ . '/../../data/filecontentshasher/*.*' ) );
14 }
15
16 public function provideMultipleFiles() {
17 return [
18 [ $this->provideSingleFile() ]
19 ];
20 }
21
27 public function testSingleFileHash( $fileName, $contents ) {
28 foreach ( [ 'md4', 'md5' ] as $algo ) {
29 $expectedHash = hash( $algo, $contents );
30 $actualHash = FileContentsHasher::getFileContentsHash( $fileName, $algo );
31 $this->assertEquals( $expectedHash, $actualHash );
32 $actualHashRepeat = FileContentsHasher::getFileContentsHash( $fileName, $algo );
33 $this->assertEquals( $expectedHash, $actualHashRepeat );
34 }
35 }
36
42 public function testMultipleFileHash( $files ) {
43 $fileNames = [];
44 $hashes = [];
45 foreach ( $files as $fileInfo ) {
46 list( $fileName, $contents ) = $fileInfo;
47 $fileNames[] = $fileName;
48 $hashes[] = md5( $contents );
49 }
50
51 $expectedHash = md5( implode( '', $hashes ) );
52 $actualHash = FileContentsHasher::getFileContentsHash( $fileNames, 'md5' );
53 $this->assertEquals( $expectedHash, $actualHash );
54 $actualHashRepeat = FileContentsHasher::getFileContentsHash( $fileNames, 'md5' );
55 $this->assertEquals( $expectedHash, $actualHashRepeat );
56 }
57}
FileContentsHasherTest.
testMultipleFileHash( $files)
FileContentsHasher::getFileContentsHash FileContentsHasher::getFileContentsHashInternal provideMultip...
testSingleFileHash( $fileName, $contents)
FileContentsHasher::getFileContentsHash FileContentsHasher::getFileContentsHashInternal provideSingle...
static getFileContentsHash( $filePaths, $algo='md4')
Get a hash of the combined contents of one or more files, either by retrieving a previously-computed ...
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition deferred.txt:11