* ApiQueryTest: One random is enough.
* FileBackendTest: More consistent and idiomatic via wfRandomString()
* MigrateFileRepoLayoutTest: Use getNewTempDirectory(). Similar to
what FileBackendTest used already.
* UploadFromUrlTestSuite: Use getNewTempDirectory().
Change-Id: I772de2134be41506d8ed08367be8c18f354bfc72
* not likely to give duplicate values for any realistic
* number of articles.
*
+ * @note This is designed for use in relation to Special:RandomPage
+ * and the page_random database field.
+ *
* @return string
*/
function wfRandom() {
- # The maximum random value is "only" 2^31-1, so get two random
- # values to reduce the chance of dupes
+ // The maximum random value is "only" 2^31-1, so get two random
+ // values to reduce the chance of dupes
$max = mt_getrandmax() + 1;
$rand = number_format( ( mt_rand() * $max + mt_rand() ) / $max / $max, 12, '.', '' );
-
return $rand;
}
/**
- * Get a random string containing a number of pseudo-random hex
- * characters.
+ * Get a random string containing a number of pseudo-random hex characters.
+ *
* @note This is not secure, if you are trying to generate some sort
* of token please use MWCryptRand instead.
*
public function testTitlesAreRejectedIfInvalid() {
$title = false;
while ( !$title || Title::newFromText( $title )->exists() ) {
- $title = md5( mt_rand( 0, 10000 ) + rand( 0, 999000 ) );
+ $title = md5( mt_rand( 0, 100000 ) );
}
$data = $this->doApiRequest( array(
protected function setUp() {
global $wgFileBackends;
parent::setUp();
- $uniqueId = time() . '-' . mt_rand();
$tmpDir = $this->getNewTempDirectory();
if ( $this->getCliArg( 'use-filebackend' ) ) {
if ( self::$backendToUse ) {
'name' => 'localtesting',
'lockManager' => LockManagerGroup::singleton()->get( 'fsLockManager' ),
'parallelize' => 'implicit',
- 'wikiId' => wfWikiId() . $uniqueId,
+ 'wikiId' => wfWikiId() . wfRandomString(),
'backends' => array(
array(
'name' => 'localmultitesting1',
$filename = 'Foo.png';
- $this->tmpPrefix = wfTempDir() . '/migratefilelayout-test-' . time() . '-' . mt_rand();
+ $this->tmpPrefix = $this->getNewTempDirectory();
$backend = new FSFileBackend( array(
'name' => 'local-migratefilerepolayouttest',
$wgParserCacheType, $wgNamespaceAliases, $wgNamespaceProtection,
$parserMemc;
+ $tmpDir = $this->getNewTempDirectory();
$tmpGlobals = array();
$tmpGlobals['wgScript'] = '/index.php';
'name' => 'local-backend',
'wikiId' => wfWikiId(),
'containerPaths' => array(
- 'local-public' => wfTempDir() . '/test-repo/public',
- 'local-thumb' => wfTempDir() . '/test-repo/thumb',
- 'local-temp' => wfTempDir() . '/test-repo/temp',
- 'local-deleted' => wfTempDir() . '/test-repo/delete',
+ 'local-public' => "{$tmpDir}/test-repo/public",
+ 'local-thumb' => "{$tmpDir}/test-repo/thumb",
+ 'local-temp' => "{$tmpDir}/test-repo/temp",
+ 'local-deleted' => "{$tmpDir}/test-repo/delete",
)
) ),
);
return $dir;
}
} else {
- $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images";
+ $dir = $this->getNewTempDirectory();
}
wfDebug( "Creating upload directory $dir\n" );
- if ( file_exists( $dir ) ) {
- wfDebug( "Already exists!\n" );
-
- return $dir;
- }
-
wfMkdirParents( $dir . '/3/3a', null, __METHOD__ );
copy( "$IP/tests/phpunit/data/upload/headbg.jpg", "$dir/3/3a/Foobar.jpg" );