X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Ffilebackend%2FFileBackendTest.php;h=e115d17c157b7482e5a36545f102ba7372a74449;hb=fbab4fecef8dcd4010d5c81736cccb565bf218da;hp=e7d092fad0297bcafb1be88e64a1631d3f078fab;hpb=41f9c915459a43545fa7f0a39c1357f873b66f45;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/filebackend/FileBackendTest.php b/tests/phpunit/includes/filebackend/FileBackendTest.php index e7d092fad0..e115d17c15 100644 --- a/tests/phpunit/includes/filebackend/FileBackendTest.php +++ b/tests/phpunit/includes/filebackend/FileBackendTest.php @@ -18,7 +18,6 @@ class FileBackendTest extends MediaWikiTestCase { protected function setUp() { global $wgFileBackends; parent::setUp(); - $uniqueId = time() . '-' . mt_rand(); $tmpDir = $this->getNewTempDirectory(); if ( $this->getCliArg( 'use-filebackend' ) ) { if ( self::$backendToUse ) { @@ -58,7 +57,7 @@ class FileBackendTest extends MediaWikiTestCase { 'name' => 'localtesting', 'lockManager' => LockManagerGroup::singleton()->get( 'fsLockManager' ), 'parallelize' => 'implicit', - 'wikiId' => wfWikiId() . $uniqueId, + 'wikiId' => wfWikiId() . wfRandomString(), 'backends' => array( array( 'name' => 'localmultitesting1', @@ -1716,7 +1715,7 @@ class FileBackendTest extends MediaWikiTestCase { $this->assertEquals( strlen( $fileBContents ), $this->backend->getFileSize( array( 'src' => $fileC ) ), "Correct file size of $fileC" ); - $this->assertEquals( wfBaseConvert( sha1( $fileBContents ), 16, 36, 31 ), + $this->assertEquals( Wikimedia\base_convert( sha1( $fileBContents ), 16, 36, 31 ), $this->backend->getFileSha1Base36( array( 'src' => $fileC ) ), "Correct file SHA-1 of $fileC" ); } @@ -1815,7 +1814,7 @@ class FileBackendTest extends MediaWikiTestCase { $this->assertEquals( strlen( $fileBContents ), $this->backend->getFileSize( array( 'src' => $fileC ) ), "Correct file size of $fileC" ); - $this->assertEquals( wfBaseConvert( sha1( $fileBContents ), 16, 36, 31 ), + $this->assertEquals( Wikimedia\base_convert( sha1( $fileBContents ), 16, 36, 31 ), $this->backend->getFileSha1Base36( array( 'src' => $fileC ) ), "Correct file SHA-1 of $fileC" ); } @@ -1892,7 +1891,7 @@ class FileBackendTest extends MediaWikiTestCase { $this->assertEquals( strlen( $fileBContents ), $this->backend->getFileSize( array( 'src' => $fileA ) ), "Correct file size of $fileA" ); - $this->assertEquals( wfBaseConvert( sha1( $fileBContents ), 16, 36, 31 ), + $this->assertEquals( Wikimedia\base_convert( sha1( $fileBContents ), 16, 36, 31 ), $this->backend->getFileSha1Base36( array( 'src' => $fileA ) ), "Correct file SHA-1 of $fileA" ); } @@ -2397,6 +2396,42 @@ class FileBackendTest extends MediaWikiTestCase { "Scoped unlocking of files succeeded with OK status ($backendName)." ); } + /** + * @dataProvider provider_testGetContentType + */ + public function testGetContentType( $mimeCallback, $mimeFromString ) { + global $IP; + + $be = TestingAccessWrapper::newFromObject( new MemoryFileBackend( + array( + 'name' => 'testing', + 'class' => 'MemoryFileBackend', + 'wikiId' => 'meow', + 'mimeCallback' => $mimeCallback + ) + ) ); + + $dst = 'mwstore://testing/container/path/to/file_no_ext'; + $src = "$IP/tests/phpunit/data/media/srgb.jpg"; + $this->assertEquals( 'image/jpeg', $be->getContentType( $dst, null, $src ) ); + $this->assertEquals( + $mimeFromString ? 'image/jpeg' : 'unknown/unknown', + $be->getContentType( $dst, file_get_contents( $src ), null ) ); + + $src = "$IP/tests/phpunit/data/media/Png-native-test.png"; + $this->assertEquals( 'image/png', $be->getContentType( $dst, null, $src ) ); + $this->assertEquals( + $mimeFromString ? 'image/png' : 'unknown/unknown', + $be->getContentType( $dst, file_get_contents( $src ), null ) ); + } + + public static function provider_testGetContentType() { + return array( + array( null, false ), + array( array( FileBackendGroup::singleton(), 'guessMimeInternal' ), true ) + ); + } + public function testReadAffinity() { $be = TestingAccessWrapper::newFromObject( new FileBackendMultiWrite( array(