mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-23 16:06:53 +00:00
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:
parent
da90f4b049
commit
13d3a218b0
|
@ -4,6 +4,7 @@ namespace MediaWiki\Extension\DiscussionTools\Tests;
|
|||
|
||||
use MediaWiki\Config\HashConfig;
|
||||
use MediaWiki\Extension\DiscussionTools\CommentUtils;
|
||||
use MediaWiki\MainConfigNames;
|
||||
|
||||
/**
|
||||
* @group DiscussionTools
|
||||
|
@ -49,7 +50,7 @@ class CommentUtilsTest extends IntegrationTestCase {
|
|||
|
||||
public static function provideGetTitleFromUrl_Decoding() {
|
||||
// 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
|
||||
yield [ 'A+B', '/wiki/A+B', $config ];
|
||||
|
@ -66,7 +67,7 @@ class CommentUtilsTest extends IntegrationTestCase {
|
|||
|
||||
public static function provideGetTitleFromUrl_ShortUrl() {
|
||||
// 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
|
||||
yield 'ShortUrl-null-string' => [ null, 'Foo', $config ];
|
||||
|
@ -97,7 +98,7 @@ class CommentUtilsTest extends IntegrationTestCase {
|
|||
|
||||
public static function provideGetTitleFromUrl_ConfusingShortUrl() {
|
||||
// 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
|
||||
yield 'ConfusingShortUrl-null-string' => [ null, 'Foo', $config ];
|
||||
|
@ -127,7 +128,7 @@ class CommentUtilsTest extends IntegrationTestCase {
|
|||
|
||||
public static function provideGetTitleFromUrl_NoShortUrl() {
|
||||
// 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
|
||||
yield 'NoShortUrl-null-string' => [ null, 'Foo', $config ];
|
||||
|
|
|
@ -11,6 +11,7 @@ use MediaWiki\Extension\DiscussionTools\CommentParser;
|
|||
use MediaWiki\Interwiki\NullInterwikiLookup;
|
||||
use MediaWiki\Languages\LanguageConverterFactory;
|
||||
use MediaWiki\Languages\LanguageFactory;
|
||||
use MediaWiki\MainConfigNames;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Title\MediaWikiTitleCodec;
|
||||
use MediaWiki\Title\NamespaceInfo;
|
||||
|
@ -127,20 +128,19 @@ trait TestUtils {
|
|||
|
||||
private static function prepareConfig( array $config, array $data ): array {
|
||||
return [
|
||||
'LanguageCode' => $config['wgContentLanguage'],
|
||||
'ArticlePath' => $config['wgArticlePath'],
|
||||
MainConfigNames::LanguageCode => $config['wgContentLanguage'],
|
||||
MainConfigNames::ArticlePath => $config['wgArticlePath'],
|
||||
// TODO: Move this to $config
|
||||
'Localtimezone' => $data['localTimezone'],
|
||||
MainConfigNames::Localtimezone => $data['localTimezone'],
|
||||
|
||||
// Defaults for NamespaceInfo
|
||||
'CanonicalNamespaceNames' => NamespaceInfo::CANONICAL_NAMES,
|
||||
'CapitalLinkOverrides' => [],
|
||||
'CapitalLinks' => true,
|
||||
'ContentNamespaces' => [ NS_MAIN ],
|
||||
'ExtraNamespaces' => [],
|
||||
'ExtraSignatureNamespaces' => [],
|
||||
'NamespaceContentModels' => [],
|
||||
'NamespacesWithSubpages' => [
|
||||
MainConfigNames::CanonicalNamespaceNames => NamespaceInfo::CANONICAL_NAMES,
|
||||
MainConfigNames::CapitalLinkOverrides => [],
|
||||
MainConfigNames::CapitalLinks => true,
|
||||
MainConfigNames::ContentNamespaces => [ NS_MAIN ],
|
||||
MainConfigNames::ExtraSignatureNamespaces => [],
|
||||
MainConfigNames::NamespaceContentModels => [],
|
||||
MainConfigNames::NamespacesWithSubpages => [
|
||||
NS_TALK => true,
|
||||
NS_USER => true,
|
||||
NS_USER_TALK => true,
|
||||
|
@ -155,24 +155,25 @@ trait TestUtils {
|
|||
NS_HELP_TALK => true,
|
||||
NS_CATEGORY_TALK => true
|
||||
],
|
||||
'NonincludableNamespaces' => [],
|
||||
MainConfigNames::NonincludableNamespaces => [],
|
||||
|
||||
// Defaults for LanguageFactory
|
||||
'DummyLanguageCodes' => [],
|
||||
MainConfigNames::DummyLanguageCodes => [],
|
||||
|
||||
// Defaults for LanguageConverterFactory
|
||||
'UsePigLatinVariant' => false,
|
||||
'DisableLangConversion' => false,
|
||||
'DisableTitleConversion' => false,
|
||||
MainConfigNames::UsePigLatinVariant => false,
|
||||
MainConfigNames::DisableLangConversion => false,
|
||||
MainConfigNames::DisableTitleConversion => false,
|
||||
|
||||
// Defaults for Language
|
||||
'ExtraGenderNamespaces' => [],
|
||||
MainConfigNames::ExtraGenderNamespaces => [],
|
||||
|
||||
// Overrides
|
||||
'ExtraNamespaces' => array_diff_key( $config['wgFormattedNamespaces'], NamespaceInfo::CANONICAL_NAMES ),
|
||||
'MetaNamespace' => strtr( $config['wgFormattedNamespaces'][NS_PROJECT], ' ', '_' ),
|
||||
'MetaNamespaceTalk' => strtr( $config['wgFormattedNamespaces'][NS_PROJECT_TALK], ' ', '_' ),
|
||||
'NamespaceAliases' => $config['wgNamespaceIds'],
|
||||
MainConfigNames::ExtraNamespaces => array_diff_key(
|
||||
$config['wgFormattedNamespaces'], NamespaceInfo::CANONICAL_NAMES ),
|
||||
MainConfigNames::MetaNamespace => strtr( $config['wgFormattedNamespaces'][NS_PROJECT], ' ', '_' ),
|
||||
MainConfigNames::MetaNamespaceTalk => strtr( $config['wgFormattedNamespaces'][NS_PROJECT_TALK], ' ', '_' ),
|
||||
MainConfigNames::NamespaceAliases => $config['wgNamespaceIds'],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue