tests: Clean up use of mt_rand()
[lhc/web/wiklou.git] / tests / phpunit / includes / filebackend / FileBackendTest.php
index 09b3728..e115d17 100644 (file)
@@ -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" );
        }
@@ -2531,6 +2530,37 @@ class FileBackendTest extends MediaWikiTestCase {
                );
        }
 
+       public function testSanitizeOpHeaders() {
+               $be = TestingAccessWrapper::newFromObject( new MemoryFileBackend( array(
+                       'name' => 'localtesting',
+                       'wikiId' => wfWikiID()
+               ) ) );
+
+               $name = wfRandomString( 300 );
+
+               $input = array(
+                       'headers' => array(
+                               'content-Disposition' => FileBackend::makeContentDisposition( 'inline', $name ),
+                               'Content-dUration' => 25.6,
+                               'X-LONG-VALUE' => str_pad( '0', 300 ),
+                               'CONTENT-LENGTH' => 855055,
+                       )
+               );
+               $expected = array(
+                       'headers' => array(
+                               'content-disposition' => FileBackend::makeContentDisposition( 'inline', $name ),
+                               'content-duration' => 25.6,
+                               'content-length' => 855055
+                       )
+               );
+
+               MediaWiki\suppressWarnings();
+               $actual = $be->sanitizeOpHeaders( $input );
+               MediaWiki\restoreWarnings();
+
+               $this->assertEquals( $expected, $actual, "Header sanitized properly" );
+       }
+
        // helper function
        private function listToArray( $iter ) {
                return is_array( $iter ) ? $iter : iterator_to_array( $iter );