2020-10-14 19:53:00 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace MediaWiki\Extension\DiscussionTools\Tests;
|
|
|
|
|
2022-02-19 04:03:09 +00:00
|
|
|
use MediaWiki\Extension\DiscussionTools\LanguageData;
|
|
|
|
use MediaWiki\MediaWikiServices;
|
2020-10-14 19:53:00 +00:00
|
|
|
|
|
|
|
/**
|
2022-09-15 12:08:30 +00:00
|
|
|
* @covers \MediaWiki\Extension\DiscussionTools\LanguageData
|
2020-10-14 19:53:00 +00:00
|
|
|
*/
|
2022-02-19 04:03:09 +00:00
|
|
|
class LanguageDataTest extends IntegrationTestCase {
|
2020-10-14 19:53:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provideLocalData
|
|
|
|
*/
|
2021-07-22 07:25:13 +00:00
|
|
|
public function testGetLocalData( string $langCode, array $config, string $expectedPath ): void {
|
2022-11-08 17:47:22 +00:00
|
|
|
$config += [
|
2020-10-14 19:53:00 +00:00
|
|
|
'ContentLanguage' => $langCode,
|
2022-11-08 17:47:22 +00:00
|
|
|
'UsePigLatinVariant' => false,
|
2020-10-14 19:53:00 +00:00
|
|
|
'TranslateNumerals' => true,
|
|
|
|
'Localtimezone' => 'UTC',
|
2022-11-08 17:47:22 +00:00
|
|
|
];
|
|
|
|
$this->overrideConfigValues( $config );
|
|
|
|
|
2022-06-09 13:51:33 +00:00
|
|
|
$expectedData = static::getJson( $expectedPath );
|
2020-10-14 19:53:00 +00:00
|
|
|
|
Change CommentParser into a service
Goal:
-----
To have a method like CommentParser::parse(), which just takes a node
to parse and a title and returns plain data, so that we don't need to
keep track of the config to construct a CommentParser object (the
required config like content language is provided by services) and
we don't need to keep that object around after parsing.
Changes:
--------
CommentParser.php:
* …is now a service. Constructor only takes services as arguments.
The node and title are passed to a new parse() method.
* parse() should return plain data, but I split this part to a separate
patch for ease of review: I49bfe019aa460651447fd383f73eafa9d7180a92.
* CommentParser still cheats and accesses global state in a few places,
e.g. calling Title::makeTitleSafe or CommentUtils::getTitleFromUrl,
so we can't turn its tests into true unit tests. This work is left
for future commits.
LanguageData.php:
* …is now a service, instead of a static class.
Parser.js:
* …is not a real service, but it's changed to behave in a similar way.
Constructor takes only the required config as argument,
and node and title are instead passed to a new parse() method.
CommentParserTest.php:
parser.test.js:
* Can be simplified, now that we don't need a useless node and title
to test internal methods that don't use them.
testUtils.js:
* Can be simplified, now that we don't need to override internal
ResourceLoader stuff just to change the parser config.
Change-Id: Iadb7757debe000025e52770ca51ebcf24ca8ee66
2022-02-19 02:43:21 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
$languageData = new LanguageData(
|
2022-11-08 17:47:22 +00:00
|
|
|
$services->getMainConfig(),
|
|
|
|
$services->getLanguageFactory()->getLanguage( $langCode ),
|
Change CommentParser into a service
Goal:
-----
To have a method like CommentParser::parse(), which just takes a node
to parse and a title and returns plain data, so that we don't need to
keep track of the config to construct a CommentParser object (the
required config like content language is provided by services) and
we don't need to keep that object around after parsing.
Changes:
--------
CommentParser.php:
* …is now a service. Constructor only takes services as arguments.
The node and title are passed to a new parse() method.
* parse() should return plain data, but I split this part to a separate
patch for ease of review: I49bfe019aa460651447fd383f73eafa9d7180a92.
* CommentParser still cheats and accesses global state in a few places,
e.g. calling Title::makeTitleSafe or CommentUtils::getTitleFromUrl,
so we can't turn its tests into true unit tests. This work is left
for future commits.
LanguageData.php:
* …is now a service, instead of a static class.
Parser.js:
* …is not a real service, but it's changed to behave in a similar way.
Constructor takes only the required config as argument,
and node and title are instead passed to a new parse() method.
CommentParserTest.php:
parser.test.js:
* Can be simplified, now that we don't need a useless node and title
to test internal methods that don't use them.
testUtils.js:
* Can be simplified, now that we don't need to override internal
ResourceLoader stuff just to change the parser config.
Change-Id: Iadb7757debe000025e52770ca51ebcf24ca8ee66
2022-02-19 02:43:21 +00:00
|
|
|
$services->getLanguageConverterFactory(),
|
|
|
|
$services->getSpecialPageFactory()
|
|
|
|
);
|
|
|
|
|
|
|
|
$data = $languageData->getLocalData();
|
2020-10-14 19:53:00 +00:00
|
|
|
|
2020-10-19 20:51:43 +00:00
|
|
|
// Optionally write updated content to the JSON files
|
|
|
|
if ( getenv( 'DISCUSSIONTOOLS_OVERWRITE_TESTS' ) ) {
|
2022-06-09 13:51:33 +00:00
|
|
|
static::overwriteJsonFile( $expectedPath, $data );
|
2020-10-19 20:51:43 +00:00
|
|
|
}
|
2020-10-14 19:53:00 +00:00
|
|
|
|
2022-06-09 13:51:33 +00:00
|
|
|
static::assertEquals( $expectedData, $data );
|
2020-10-14 19:53:00 +00:00
|
|
|
}
|
|
|
|
|
2021-07-22 07:25:13 +00:00
|
|
|
public function provideLocalData(): array {
|
2020-10-14 19:53:00 +00:00
|
|
|
return [
|
|
|
|
// Boring
|
|
|
|
[ 'en', [], '../cases/datatest-en.json' ],
|
|
|
|
// Has language variants (T259818)
|
|
|
|
[ 'sr', [], '../cases/datatest-sr.json' ],
|
|
|
|
// Has localised digits (T261706)
|
|
|
|
[ 'ckb', [], '../cases/datatest-ckb.json' ],
|
|
|
|
// Has unusual timezone abbreviation (T265500)
|
|
|
|
[ 'th', [ 'Localtimezone' => 'Asia/Bangkok' ], '../cases/datatest-th.json' ],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|