aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--includes/user/User.php18
-rw-r--r--tests/phpunit/MediaWikiIntegrationTestCase.php17
-rw-r--r--tests/phpunit/includes/GlobalFunctions/WfExpandUrlTest.php2
-rw-r--r--tests/phpunit/includes/OutputPageTest.php4
-rw-r--r--tests/phpunit/includes/api/ApiTestCase.php2
-rw-r--r--tests/phpunit/includes/block/BlockManagerTest.php6
-rw-r--r--tests/phpunit/includes/user/UserTest.php4
-rw-r--r--tests/phpunit/languages/LanguageConverterTest.php1
8 files changed, 31 insertions, 23 deletions
diff --git a/includes/user/User.php b/includes/user/User.php
index ce5dd1fd056a..43b0c2534ef5 100644
--- a/includes/user/User.php
+++ b/includes/user/User.php
@@ -669,7 +669,7 @@ class User implements IDBAccessObject, UserIdentity {
* Create a new user object using data from session. If the login
* credentials are invalid, the result is an anonymous user.
*
- * @param WebRequest|null $request Object to use; $wgRequest will be used if omitted.
+ * @param WebRequest|null $request Object to use; the global request will be used if omitted.
* @return User
*/
public static function newFromSession( WebRequest $request = null ) {
@@ -3107,9 +3107,7 @@ class User implements IDBAccessObject, UserIdentity {
if ( $this->mRequest ) {
return $this->mRequest;
}
-
- global $wgRequest;
- return $wgRequest;
+ return RequestContext::getMain()->getRequest();
}
/**
@@ -3271,8 +3269,8 @@ class User implements IDBAccessObject, UserIdentity {
/**
* Persist this user's session (e.g. set cookies)
*
- * @param WebRequest|null $request WebRequest object to use; $wgRequest will be used if null
- * is passed.
+ * @param WebRequest|null $request WebRequest object to use; the global request
+ * will be used if null is passed.
* @param bool|null $secure Whether to force secure/insecure cookies or use default
* @param bool $rememberMe Whether to add a Token cookie for elongated sessions
*/
@@ -3743,7 +3741,7 @@ class User implements IDBAccessObject, UserIdentity {
*
* @since 1.27
* @param string|string[] $salt Optional function-specific data for hashing
- * @param WebRequest|null $request WebRequest object to use or null to use $wgRequest
+ * @param WebRequest|null $request WebRequest object to use, or null to use the global request
* @return MediaWiki\Session\Token The new edit token
*/
public function getEditTokenObject( $salt = '', $request = null ) {
@@ -3767,7 +3765,7 @@ class User implements IDBAccessObject, UserIdentity {
*
* @since 1.19
* @param string|string[] $salt Optional function-specific data for hashing
- * @param WebRequest|null $request WebRequest object to use or null to use $wgRequest
+ * @param WebRequest|null $request WebRequest object to use, or null to use the global request
* @return string The new edit token
*/
public function getEditToken( $salt = '', $request = null ) {
@@ -3782,7 +3780,7 @@ class User implements IDBAccessObject, UserIdentity {
*
* @param string $val Input value to compare
* @param string|array $salt Optional function-specific data for hashing
- * @param WebRequest|null $request Object to use or null to use $wgRequest
+ * @param WebRequest|null $request Object to use, or null to use the global request
* @param int|null $maxage Fail tokens older than this, in seconds
* @return bool Whether the token matches
*/
@@ -3796,7 +3794,7 @@ class User implements IDBAccessObject, UserIdentity {
*
* @param string $val Input value to compare
* @param string|array $salt Optional function-specific data for hashing
- * @param WebRequest|null $request Object to use or null to use $wgRequest
+ * @param WebRequest|null $request Object to use, or null to use the global request
* @param int|null $maxage Fail tokens older than this, in seconds
* @return bool Whether the token matches
*/
diff --git a/tests/phpunit/MediaWikiIntegrationTestCase.php b/tests/phpunit/MediaWikiIntegrationTestCase.php
index d24cedc782cb..3c210d8cd17f 100644
--- a/tests/phpunit/MediaWikiIntegrationTestCase.php
+++ b/tests/phpunit/MediaWikiIntegrationTestCase.php
@@ -391,7 +391,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
session_id( '' );
}
- $wgRequest = new FauxRequest();
+ $wgRequest = RequestContext::getMain()->getRequest();
MediaWiki\Session\SessionManager::resetCache();
}
@@ -651,7 +651,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
session_write_close();
session_id( '' );
}
- $wgRequest = new FauxRequest();
+ $wgRequest = RequestContext::getMain()->getRequest();
MediaWiki\Session\SessionManager::resetCache();
MediaWiki\Auth\AuthManager::resetCache();
@@ -775,6 +775,19 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
}
/**
+ * Set the global request in the two places it is stored.
+ * @param WebRequest $request
+ * @since 1.36
+ */
+ protected function setRequest( $request ) {
+ global $wgRequest;
+ // It's not necessary to stash the value with setMwGlobals(), since
+ // it's reset on teardown anyway.
+ $wgRequest = $request;
+ RequestContext::getMain()->setRequest( $request );
+ }
+
+ /**
* Set an ini setting for the duration of the test
* @param string $name Name of the setting
* @param string $value Value to set
diff --git a/tests/phpunit/includes/GlobalFunctions/WfExpandUrlTest.php b/tests/phpunit/includes/GlobalFunctions/WfExpandUrlTest.php
index d5171ec898b9..e053ab4f9e4f 100644
--- a/tests/phpunit/includes/GlobalFunctions/WfExpandUrlTest.php
+++ b/tests/phpunit/includes/GlobalFunctions/WfExpandUrlTest.php
@@ -15,9 +15,9 @@ class WfExpandUrlTest extends MediaWikiIntegrationTestCase {
$this->setMwGlobals( [
'wgServer' => $server,
'wgCanonicalServer' => $canServer,
- 'wgRequest' => new FauxRequest( [], false, null, $httpsMode ? 'https' : 'http' ),
'wgHttpsPort' => $httpsPort
] );
+ $this->setRequest( new FauxRequest( [], false, null, $httpsMode ? 'https' : 'http' ) );
$this->assertEquals( $fullUrl, wfExpandUrl( $shortUrl, $defaultProto ), $message );
}
diff --git a/tests/phpunit/includes/OutputPageTest.php b/tests/phpunit/includes/OutputPageTest.php
index 6bc9322426a2..4ee1770d61b7 100644
--- a/tests/phpunit/includes/OutputPageTest.php
+++ b/tests/phpunit/includes/OutputPageTest.php
@@ -2799,9 +2799,7 @@ class OutputPageTest extends MediaWikiIntegrationTestCase {
}
$fauxRequest = new FauxRequest( $queryData, false );
- $this->setMwGlobals( [
- 'wgRequest' => $fauxRequest,
- ] );
+ $this->setRequest( $fauxRequest );
$actualReturn = OutputPage::transformCssMedia( $args['media'] );
$this->assertSame( $args['expectedReturn'], $actualReturn, $args['message'] );
diff --git a/tests/phpunit/includes/api/ApiTestCase.php b/tests/phpunit/includes/api/ApiTestCase.php
index 780ddea9f9cf..3764ee439a13 100644
--- a/tests/phpunit/includes/api/ApiTestCase.php
+++ b/tests/phpunit/includes/api/ApiTestCase.php
@@ -28,8 +28,8 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
'uploader' => static::getTestUser(),
];
+ $this->setRequest( new FauxRequest( [] ) );
$this->setMwGlobals( [
- 'wgRequest' => new FauxRequest( [] ),
'wgUser' => self::$users['sysop']->getUser(),
] );
diff --git a/tests/phpunit/includes/block/BlockManagerTest.php b/tests/phpunit/includes/block/BlockManagerTest.php
index 2d95211adb84..6c39c9daf208 100644
--- a/tests/phpunit/includes/block/BlockManagerTest.php
+++ b/tests/phpunit/includes/block/BlockManagerTest.php
@@ -116,14 +116,16 @@ class BlockManagerTest extends MediaWikiIntegrationTestCase {
$user = $options['loggedIn'] ? $this->user : new User();
$user->getRequest()->setCookie( 'BlockID', $blockManager->getCookieValue( $block ) );
+ $response = new FauxResponse;
+
$blockManager->trackBlockWithCookie(
$user,
- $user->getRequest()->response()
+ $response
);
$this->assertCount(
$expectKeepCookie ? 0 : 1,
- $user->getRequest()->response()->getCookies()
+ $response->getCookies()
);
$blockStore->deleteBlock( $block );
diff --git a/tests/phpunit/includes/user/UserTest.php b/tests/phpunit/includes/user/UserTest.php
index 5fd906620961..d0138715be89 100644
--- a/tests/phpunit/includes/user/UserTest.php
+++ b/tests/phpunit/includes/user/UserTest.php
@@ -1231,9 +1231,7 @@ class UserTest extends MediaWikiIntegrationTestCase {
*/
public function testSessionAndRequest() {
$req1 = new WebRequest;
- $this->setMwGlobals( [
- 'wgRequest' => $req1,
- ] );
+ $this->setRequest( $req1 );
$user = User::newFromSession();
$request = $user->getRequest();
diff --git a/tests/phpunit/languages/LanguageConverterTest.php b/tests/phpunit/languages/LanguageConverterTest.php
index 147ac83780cb..eac1ad403eb3 100644
--- a/tests/phpunit/languages/LanguageConverterTest.php
+++ b/tests/phpunit/languages/LanguageConverterTest.php
@@ -29,7 +29,6 @@ class LanguageConverterTest extends MediaWikiLangTestCase {
$this->setMwGlobals( [
'wgDefaultLanguageVariant' => false,
- 'wgRequest' => new FauxRequest( [] ),
'wgUser' => new User,
] );