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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
<?php
/**
* @file
* @author Niklas Laxström
* @license GPL-2.0-or-later
*/
use MediaWiki\MediaWikiServices;
/** @group Database */
class ApiTranslationReviewTest extends MediaWikiIntegrationTestCase {
protected function setUp(): void {
parent::setUp();
$this->setMwGlobals( [
'wgGroupPermissions' => [
'sysop' => [
'translate-messagereview' => true,
],
],
'wgTranslateMessageNamespaces' => [ NS_MEDIAWIKI ],
] );
$this->setTemporaryHook( 'TranslatePostInitGroups', [ $this, 'getTestGroups' ] );
$mg = MessageGroups::singleton();
$mg->setCache( new WANObjectCache( [ 'cache' => wfGetCache( 'hash' ) ] ) );
$mg->recache();
MessageIndex::setInstance( new HashMessageIndex() );
MessageIndex::singleton()->rebuild();
}
public function getTestGroups( &$list ) {
$messages = [
'ugakey1' => 'value1',
'ugakey2' => 'value2',
];
$list['testgroup'] = new MockWikiMessageGroup( 'testgroup', $messages );
return false;
}
public function testgetReviewBlockers() {
$superUser1 = $this->getMutableTestUser( [ 'sysop', 'bureaucrat' ] )->getUser();
$superUser2 = $this->getMutableTestUser( [ 'sysop', 'bureaucrat' ] )->getUser();
$plainUser = $this->getMutableTestUser()->getUser();
$title = Title::makeTitle( NS_MEDIAWIKI, 'Ugakey1/fi' );
$content = ContentHandler::makeContent( 'trans1', $title );
WikiPage::factory( $title )->doEditContent( $content, __METHOD__, 0, false, $superUser1 );
$title = Title::makeTitle( NS_MEDIAWIKI, 'Ugakey2/fi' );
$content = ContentHandler::makeContent( '!!FUZZY!!trans2', $title );
WikiPage::factory( $title )->doEditContent( $content, __METHOD__, 0, false, $superUser2 );
$title = Title::makeTitle( NS_MEDIAWIKI, 'Ugakey3/fi' );
$content = ContentHandler::makeContent( 'unknown message', $title );
WikiPage::factory( $title )->doEditContent( $content, __METHOD__, 0, false, $superUser1 );
$testcases = [
[
'permissiondenied',
$plainUser,
'Ugakey1/fi',
'Unpriviledged user is not allowed to change state'
],
[
'owntranslation',
$superUser1,
'Ugakey1/fi',
'Cannot approve own translation'
],
[
'fuzzymessage',
$superUser1,
'Ugakey2/fi',
'Cannot approve fuzzy translation'
],
[
'unknownmessage',
$superUser1,
'Ugakey3/fi',
'Cannot approve unknown translation'
],
[
'',
$superUser2,
'Ugakey1/fi',
'Can approve non-fuzzy known non-own translation'
],
];
foreach ( $testcases as $case ) {
list( $expected, $user, $page, $comment ) = $case;
$revRecord = MediaWikiServices::getInstance()
->getRevisionLookup()
->getRevisionByTitle( new TitleValue( NS_MEDIAWIKI, $page ) );
$ok = ApiTranslationReview::getReviewBlockers( $user, $revRecord );
$this->assertEquals( $expected, $ok, $comment );
}
}
}
|