Use MainConfigNames constants in tests where possible

I believe this makes the code less brittle, and also makes it a bit
more obvious what these strings are meant to represent.

Change-Id: I01adaff0ed75f792d1130bbc75e7840b3d044c54
This commit is contained in:
thiemowmde 2024-07-09 12:39:08 +02:00 committed by Thiemo Kreuz (WMDE)
parent da90f4b049
commit 13d3a218b0
2 changed files with 27 additions and 25 deletions

View file

@ -4,6 +4,7 @@ namespace MediaWiki\Extension\DiscussionTools\Tests;
use MediaWiki\Config\HashConfig; use MediaWiki\Config\HashConfig;
use MediaWiki\Extension\DiscussionTools\CommentUtils; use MediaWiki\Extension\DiscussionTools\CommentUtils;
use MediaWiki\MainConfigNames;
/** /**
* @group DiscussionTools * @group DiscussionTools
@ -49,7 +50,7 @@ class CommentUtilsTest extends IntegrationTestCase {
public static function provideGetTitleFromUrl_Decoding() { public static function provideGetTitleFromUrl_Decoding() {
// Standard short URL configuration like on Wikimedia wikis // Standard short URL configuration like on Wikimedia wikis
$config = new HashConfig( [ 'ArticlePath' => '/wiki/$1' ] ); $config = new HashConfig( [ MainConfigNames::ArticlePath => '/wiki/$1' ] );
// In URL paths, non-percent-encoded `+` represents itself // In URL paths, non-percent-encoded `+` represents itself
yield [ 'A+B', '/wiki/A+B', $config ]; yield [ 'A+B', '/wiki/A+B', $config ];
@ -66,7 +67,7 @@ class CommentUtilsTest extends IntegrationTestCase {
public static function provideGetTitleFromUrl_ShortUrl() { public static function provideGetTitleFromUrl_ShortUrl() {
// Standard short URL configuration like on Wikimedia wikis // Standard short URL configuration like on Wikimedia wikis
$config = new HashConfig( [ 'ArticlePath' => '/wiki/$1' ] ); $config = new HashConfig( [ MainConfigNames::ArticlePath => '/wiki/$1' ] );
// These should never occur in documents generated by either wikitext parser // These should never occur in documents generated by either wikitext parser
yield 'ShortUrl-null-string' => [ null, 'Foo', $config ]; yield 'ShortUrl-null-string' => [ null, 'Foo', $config ];
@ -97,7 +98,7 @@ class CommentUtilsTest extends IntegrationTestCase {
public static function provideGetTitleFromUrl_ConfusingShortUrl() { public static function provideGetTitleFromUrl_ConfusingShortUrl() {
// Super short URL that is confusing for the software but people use it anyway // Super short URL that is confusing for the software but people use it anyway
$config = new HashConfig( [ 'ArticlePath' => '/$1' ] ); $config = new HashConfig( [ MainConfigNames::ArticlePath => '/$1' ] );
// These should never occur in documents generated by either wikitext parser // These should never occur in documents generated by either wikitext parser
yield 'ConfusingShortUrl-null-string' => [ null, 'Foo', $config ]; yield 'ConfusingShortUrl-null-string' => [ null, 'Foo', $config ];
@ -127,7 +128,7 @@ class CommentUtilsTest extends IntegrationTestCase {
public static function provideGetTitleFromUrl_NoShortUrl() { public static function provideGetTitleFromUrl_NoShortUrl() {
// No short URL configuration // No short URL configuration
$config = new HashConfig( [ 'ArticlePath' => '/wiki/index.php?title=$1' ] ); $config = new HashConfig( [ MainConfigNames::ArticlePath => '/wiki/index.php?title=$1' ] );
// These should never occur in documents generated by either wikitext parser // These should never occur in documents generated by either wikitext parser
yield 'NoShortUrl-null-string' => [ null, 'Foo', $config ]; yield 'NoShortUrl-null-string' => [ null, 'Foo', $config ];

View file

@ -11,6 +11,7 @@ use MediaWiki\Extension\DiscussionTools\CommentParser;
use MediaWiki\Interwiki\NullInterwikiLookup; use MediaWiki\Interwiki\NullInterwikiLookup;
use MediaWiki\Languages\LanguageConverterFactory; use MediaWiki\Languages\LanguageConverterFactory;
use MediaWiki\Languages\LanguageFactory; use MediaWiki\Languages\LanguageFactory;
use MediaWiki\MainConfigNames;
use MediaWiki\MediaWikiServices; use MediaWiki\MediaWikiServices;
use MediaWiki\Title\MediaWikiTitleCodec; use MediaWiki\Title\MediaWikiTitleCodec;
use MediaWiki\Title\NamespaceInfo; use MediaWiki\Title\NamespaceInfo;
@ -127,20 +128,19 @@ trait TestUtils {
private static function prepareConfig( array $config, array $data ): array { private static function prepareConfig( array $config, array $data ): array {
return [ return [
'LanguageCode' => $config['wgContentLanguage'], MainConfigNames::LanguageCode => $config['wgContentLanguage'],
'ArticlePath' => $config['wgArticlePath'], MainConfigNames::ArticlePath => $config['wgArticlePath'],
// TODO: Move this to $config // TODO: Move this to $config
'Localtimezone' => $data['localTimezone'], MainConfigNames::Localtimezone => $data['localTimezone'],
// Defaults for NamespaceInfo // Defaults for NamespaceInfo
'CanonicalNamespaceNames' => NamespaceInfo::CANONICAL_NAMES, MainConfigNames::CanonicalNamespaceNames => NamespaceInfo::CANONICAL_NAMES,
'CapitalLinkOverrides' => [], MainConfigNames::CapitalLinkOverrides => [],
'CapitalLinks' => true, MainConfigNames::CapitalLinks => true,
'ContentNamespaces' => [ NS_MAIN ], MainConfigNames::ContentNamespaces => [ NS_MAIN ],
'ExtraNamespaces' => [], MainConfigNames::ExtraSignatureNamespaces => [],
'ExtraSignatureNamespaces' => [], MainConfigNames::NamespaceContentModels => [],
'NamespaceContentModels' => [], MainConfigNames::NamespacesWithSubpages => [
'NamespacesWithSubpages' => [
NS_TALK => true, NS_TALK => true,
NS_USER => true, NS_USER => true,
NS_USER_TALK => true, NS_USER_TALK => true,
@ -155,24 +155,25 @@ trait TestUtils {
NS_HELP_TALK => true, NS_HELP_TALK => true,
NS_CATEGORY_TALK => true NS_CATEGORY_TALK => true
], ],
'NonincludableNamespaces' => [], MainConfigNames::NonincludableNamespaces => [],
// Defaults for LanguageFactory // Defaults for LanguageFactory
'DummyLanguageCodes' => [], MainConfigNames::DummyLanguageCodes => [],
// Defaults for LanguageConverterFactory // Defaults for LanguageConverterFactory
'UsePigLatinVariant' => false, MainConfigNames::UsePigLatinVariant => false,
'DisableLangConversion' => false, MainConfigNames::DisableLangConversion => false,
'DisableTitleConversion' => false, MainConfigNames::DisableTitleConversion => false,
// Defaults for Language // Defaults for Language
'ExtraGenderNamespaces' => [], MainConfigNames::ExtraGenderNamespaces => [],
// Overrides // Overrides
'ExtraNamespaces' => array_diff_key( $config['wgFormattedNamespaces'], NamespaceInfo::CANONICAL_NAMES ), MainConfigNames::ExtraNamespaces => array_diff_key(
'MetaNamespace' => strtr( $config['wgFormattedNamespaces'][NS_PROJECT], ' ', '_' ), $config['wgFormattedNamespaces'], NamespaceInfo::CANONICAL_NAMES ),
'MetaNamespaceTalk' => strtr( $config['wgFormattedNamespaces'][NS_PROJECT_TALK], ' ', '_' ), MainConfigNames::MetaNamespace => strtr( $config['wgFormattedNamespaces'][NS_PROJECT], ' ', '_' ),
'NamespaceAliases' => $config['wgNamespaceIds'], MainConfigNames::MetaNamespaceTalk => strtr( $config['wgFormattedNamespaces'][NS_PROJECT_TALK], ' ', '_' ),
MainConfigNames::NamespaceAliases => $config['wgNamespaceIds'],
]; ];
} }