Replace global variable by config

Use $this->overrideConfigValues instead of $this->setMwGlobals in the
test.

Change-Id: I1ae238235476a001683ea81d2b65d209a2774549
This commit is contained in:
Fomafix 2024-02-25 19:26:11 +00:00
parent a59ddbb849
commit 3bb9611497
2 changed files with 17 additions and 14 deletions

View file

@ -24,6 +24,7 @@ use IContextSource;
use MediaWiki\Config\Config;
use MediaWiki\Config\ConfigException;
use MediaWiki\Content\IContentHandlerFactory;
use MediaWiki\MainConfigNames;
use MediaWiki\Minerva\LanguagesHelper;
use MediaWiki\Minerva\SkinOptions;
use MediaWiki\Permissions\Authority;
@ -140,8 +141,6 @@ final class MinervaPagePermissions implements IMinervaPagePermissions {
* @throws ConfigException
*/
public function isAllowed( $action ) {
global $wgHideInterlanguageLinks;
if ( !$this->title ) {
return false;
}
@ -150,7 +149,7 @@ final class MinervaPagePermissions implements IMinervaPagePermissions {
// the "switch-language" button. But disable "edit" and "watch" actions.
if ( $this->title->isMainPage() ) {
if ( $action === self::SWITCH_LANGUAGE ) {
return !$wgHideInterlanguageLinks;
return !$this->config->get( MainConfigNames::HideInterlanguageLinks );
}
// Only the talk page is allowed on the main page provided user is registered.
// talk page permission is disabled on mobile for anons
@ -194,7 +193,7 @@ final class MinervaPagePermissions implements IMinervaPagePermissions {
}
if ( $action === self::SWITCH_LANGUAGE ) {
if ( $wgHideInterlanguageLinks ) {
if ( $this->config->get( MainConfigNames::HideInterlanguageLinks ) ) {
return false;
}
return $this->languagesHelper->doesTitleHasLanguagesOrVariants( $this->title ) ||

View file

@ -3,8 +3,8 @@
namespace MediaWiki\Minerva;
use ContentHandler;
use MediaWiki\Config\HashConfig;
use MediaWiki\Content\IContentHandlerFactory;
use MediaWiki\MainConfigNames;
use MediaWiki\Minerva\Permissions\IMinervaPagePermissions;
use MediaWiki\Minerva\Permissions\MinervaPagePermissions;
use MediaWiki\Permissions\Authority;
@ -22,14 +22,19 @@ use RequestContext;
class MinervaPagePermissionsTest extends MediaWikiIntegrationTestCase {
use MockAuthorityTrait;
protected function setUp(): void {
$this->overrideConfigValues( [
MainConfigNames::HideInterlanguageLinks => false
] );
}
private function buildPermissionsObject(
Title $title,
$actions = null, /* unused */
array $options = [],
ContentHandler $contentHandler = null,
Authority $user = null,
$hasOtherLanguagesOrVariants = false,
$alwaysShowLanguageButton = true
$hasOtherLanguagesOrVariants = false
) {
$languageHelper = $this->createMock( LanguagesHelper::class );
$languageHelper->method( 'doesTitleHasLanguagesOrVariants' )
@ -56,9 +61,6 @@ class MinervaPagePermissionsTest extends MediaWikiIntegrationTestCase {
// Force a content model to avoid DB queries.
$title->setContentModel( CONTENT_MODEL_WIKITEXT );
$context->setTitle( $title );
$context->setConfig( new HashConfig( [
'MinervaAlwaysShowLanguageButton' => $alwaysShowLanguageButton
] ) );
$context->setAuthority( $user );
$permissionManager = $this->getServiceContainer()->getPermissionManager();
@ -186,7 +188,7 @@ class MinervaPagePermissionsTest extends MediaWikiIntegrationTestCase {
* @covers ::isAllowed
*/
public function testGlobalHideLanguageLinksTakesPrecedenceOnMainPage() {
$this->setMwGlobals( [ 'wgHideInterlanguageLinks' => true ] );
$this->overrideConfigValues( [ MainConfigNames::HideInterlanguageLinks => true ] );
$perms = $this->buildPermissionsObject( Title::newMainPage() );
$this->assertFalse( $perms->isAllowed( IMinervaPagePermissions::SWITCH_LANGUAGE ) );
}
@ -197,7 +199,7 @@ class MinervaPagePermissionsTest extends MediaWikiIntegrationTestCase {
* @covers ::isAllowed
*/
public function testGlobalHideLanguageLinksTakesPrecedence() {
$this->setMwGlobals( [ 'wgHideInterlanguageLinks' => true ] );
$this->overrideConfigValues( [ MainConfigNames::HideInterlanguageLinks => true ] );
$perms = $this->buildPermissionsObject( Title::makeTitle( NS_MAIN, 'Test' ) );
$this->assertFalse( $perms->isAllowed( IMinervaPagePermissions::SWITCH_LANGUAGE ) );
}
@ -223,14 +225,16 @@ class MinervaPagePermissionsTest extends MediaWikiIntegrationTestCase {
->method( 'getContentModel' )
->willReturn( CONTENT_MODEL_WIKITEXT );
$this->overrideConfigValues( [
'MinervaAlwaysShowLanguageButton' => $minervaAlwaysShowLanguageButton
] );
$permissions = $this->buildPermissionsObject(
$title,
null,
[],
null,
null,
$hasLanguagesOrVariants,
$minervaAlwaysShowLanguageButton
$hasLanguagesOrVariants
);
$actual = $permissions->isAllowed( IMinervaPagePermissions::SWITCH_LANGUAGE );