Merge "Update docs/hooks.txt for ShowSearchHitTitle"
[mediawiki.git] / tests / phpunit / includes / utils / FileContentsHasherTest.php
blob0ee4c1342d6880dd80c8743fdbe3a3614471ed4e
1 <?php
3 /**
4 * @covers FileContentsHasherTest
5 */
6 class FileContentsHasherTest extends PHPUnit_Framework_TestCase {
8 public function provideSingleFile() {
9 return array_map( function ( $file ) {
10 return [ $file, file_get_contents( $file ) ];
11 }, glob( __DIR__ . '/../../data/filecontentshasher/*.*' ) );
14 public function provideMultipleFiles() {
15 return [
16 [ $this->provideSingleFile() ]
20 /**
21 * @covers FileContentsHasher::getFileContentsHash
22 * @covers FileContentsHasher::getFileContentsHashInternal
23 * @dataProvider provideSingleFile
25 public function testSingleFileHash( $fileName, $contents ) {
26 foreach ( [ 'md4', 'md5' ] as $algo ) {
27 $expectedHash = hash( $algo, $contents );
28 $actualHash = FileContentsHasher::getFileContentsHash( $fileName, $algo );
29 $this->assertEquals( $expectedHash, $actualHash );
30 $actualHashRepeat = FileContentsHasher::getFileContentsHash( $fileName, $algo );
31 $this->assertEquals( $expectedHash, $actualHashRepeat );
35 /**
36 * @covers FileContentsHasher::getFileContentsHash
37 * @covers FileContentsHasher::getFileContentsHashInternal
38 * @dataProvider provideMultipleFiles
40 public function testMultipleFileHash( $files ) {
41 $fileNames = [];
42 $hashes = [];
43 foreach ( $files as $fileInfo ) {
44 list( $fileName, $contents ) = $fileInfo;
45 $fileNames[] = $fileName;
46 $hashes[] = md5( $contents );
49 $expectedHash = md5( implode( '', $hashes ) );
50 $actualHash = FileContentsHasher::getFileContentsHash( $fileNames, 'md5' );
51 $this->assertEquals( $expectedHash, $actualHash );
52 $actualHashRepeat = FileContentsHasher::getFileContentsHash( $fileNames, 'md5' );
53 $this->assertEquals( $expectedHash, $actualHashRepeat );