mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-12-13 09:03:35 +00:00
1c3fada1fb
Documentation: https://www.mediawiki.org/wiki/Manual:PHP_unit_testing/Writing_unit_tests_for_extensions#Two_types_of_tests We can do this because the tested methods do not depend on any globals or on MediaWiki being installed. In addition to being the new hotness, MediaWikiUnitTestCase allows the test classes that use it instead of MediaWikiTestCase to start up much faster. In my testing, running this test case individually now takes 0.35s, compared to 1.1s before. Try: * With new code: time php tests/phpunit/phpunit.php extensions/DiscussionTools/tests/phpunit/unit/CommentUtilsTest.php * With old code: time php tests/phpunit/phpunit.php extensions/DiscussionTools/tests/phpunit/CommentUtilsTest.php Change-Id: I771b1f3d101a394ee869e42547d9ae7839397752
49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\DiscussionTools\Tests;
|
|
|
|
use HashConfig;
|
|
use MediaWiki\Extension\DiscussionTools\Data;
|
|
|
|
/**
|
|
* @coversDefaultClass \MediaWiki\Extension\DiscussionTools\Data
|
|
*/
|
|
class DataTest extends IntegrationTestCase {
|
|
|
|
/**
|
|
* @dataProvider provideLocalData
|
|
* @covers ::getLocalData
|
|
*/
|
|
public function testGetLocalData( string $langCode, array $config, string $expectedPath ) : void {
|
|
$conf = new HashConfig( $config + [
|
|
'ContentLanguage' => $langCode,
|
|
'TranslateNumerals' => true,
|
|
'Localtimezone' => 'UTC',
|
|
] );
|
|
$expectedData = self::getJson( $expectedPath );
|
|
|
|
$data = Data::getLocalData( null, $conf, $langCode );
|
|
|
|
// Optionally write updated content to the JSON files
|
|
if ( getenv( 'DISCUSSIONTOOLS_OVERWRITE_TESTS' ) ) {
|
|
self::overwriteJsonFile( $expectedPath, $data );
|
|
}
|
|
|
|
self::assertEquals( $expectedData, $data );
|
|
}
|
|
|
|
public function provideLocalData() : array {
|
|
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' ],
|
|
];
|
|
}
|
|
|
|
}
|