1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
<?php
/**
* @author Niklas Laxström
* @file
* @license GPL-2.0-or-later
*/
class MessageGroupStatsTest extends MediaWikiIntegrationTestCase {
protected function setUp() : void {
parent::setUp();
$this->setTemporaryHook(
'TranslatePostInitGroups',
function ( &$list ) {
$exampleMessageGroup = new WikiMessageGroup( 'theid', 'thesource' );
$exampleMessageGroup->setLabel( 'thelabel' ); // Example
$exampleMessageGroup->setNamespace( 5 ); // Example
$list['theid'] = $exampleMessageGroup;
}
);
$mg = MessageGroups::singleton();
$mg->setCache( new WANObjectCache( [ 'cache' => wfGetCache( 'hash' ) ] ) );
$mg->recache();
}
public function testGetDatabaseIdForGroupId() {
$shortId = 'abab';
$longId = str_repeat( 'ab', 100 );
$this->assertLessThanOrEqual(
100,
strlen( MessageGroupStats::getDatabaseIdForGroupId( $shortId ) ),
'Short id is <= 100 bytes long'
);
$this->assertLessThanOrEqual(
100,
strlen( MessageGroupStats::getDatabaseIdForGroupId( $longId ) ),
'Long id is <= 100 bytes long'
);
$longId1 = str_repeat( 'ab', 100 ) . '1';
$longId2 = str_repeat( 'ab', 100 ) . '2';
$this->assertNotEquals(
MessageGroupStats::getDatabaseIdForGroupId( $longId1 ),
MessageGroupStats::getDatabaseIdForGroupId( $longId2 ),
'Two long ids with the same prefix do not collide'
);
}
public function testFunctionReturnFormat() {
$validLang = MessageGroupStats::forLanguage( 'en', MessageGroupStats::FLAG_CACHE_ONLY );
$invalidLang = MessageGroupStats::forLanguage( 'ffff', MessageGroupStats::FLAG_CACHE_ONLY );
$validGroup = MessageGroupStats::forGroup( 'theid', MessageGroupStats::FLAG_CACHE_ONLY );
$invalidGroup = MessageGroupStats::forGroup( 'invalid-mg-group',
MessageGroupStats::FLAG_CACHE_ONLY );
$this->assertIsArray( current( $validLang ),
'forLanguage returns data in valid format for valid language' );
$this->assertIsArray( current( $invalidLang ),
'forLanguage returns data in valid format for invalid language' );
$this->assertIsArray( current( $validGroup ),
'forGroup returns data in valid format for valid group' );
$this->assertIsArray( current( $invalidGroup ),
'forGroup returns data in valid format for invalid group' );
}
}
|