Merge "Use FauxRequest::setUpload in AbuseFilterUploadTestTrait::doUpload"

This commit is contained in:
jenkins-bot 2021-05-15 12:22:10 +00:00 committed by Gerrit Code Review
commit 7d0e50a2cd
2 changed files with 6 additions and 9 deletions

View file

@ -1,8 +1,6 @@
<?xml version="1.0"?>
<ruleset>
<rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki">
<exclude name="MediaWiki.Usage.SuperGlobalsUsage.SuperGlobals" />
</rule>
<rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki" />
<rule ref="Generic.Files.LineLength">
<exclude-pattern>AbuseFilter\.alias\.php</exclude-pattern>
</rule>

View file

@ -5,7 +5,7 @@ use MediaWiki\MediaWikiServices;
/**
* This trait can be used to perform uploads in integration tests.
* NOTE: The implementing classes MUST extend MediaWikiIntegrationTestCase
* The tearDown method must clear $_FILES and the local file
* The tearDown method must clear the local file
* @todo This might be moved to MediaWikiIntegrationTestCase
*
* @method string getNewTempDirectory()
@ -21,7 +21,6 @@ trait AbuseFilterUploadTestTrait {
* Clear any temporary uploads, should be called from tearDown
*/
protected function clearUploads() : void {
$_FILES = [];
if ( $this->clearPath ) {
$backend = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()->getBackend();
$backend->delete( [ 'src' => $this->clearPath ], [ 'force' => 1 ] );
@ -48,15 +47,15 @@ trait AbuseFilterUploadTestTrait {
$mime = 'image/svg+xml';
$filePath = $imgGen->writeImages( 1, $format, $this->getNewTempDirectory() )[0];
clearstatcache();
$_FILES[ 'wpUploadFile' ] = [
$request = new FauxRequest( [
'wpDestFile' => $fileName
] );
$request->setUpload( 'wpUploadFile', [
'name' => $fileName,
'type' => $mime,
'tmp_name' => $filePath,
'error' => UPLOAD_ERR_OK,
'size' => filesize( $filePath ),
];
$request = new FauxRequest( [
'wpDestFile' => $fileName
] );
/** @var UploadFromFile $ub */
$ub = UploadBase::createFromRequest( $request );