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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
<?php
use MediaWiki\MediaWikiServices;
/**
* @group Database
* @group medium
*/
class PageTranslationTaggingTest extends MediaWikiIntegrationTestCase {
protected function setUp(): void {
parent::setUp();
$this->setMwGlobals( [
'wgEnablePageTranslation' => true,
'wgTranslateTranslationServices' => [],
] );
TranslateHooks::setupTranslate();
$this->setTemporaryHook( 'TranslateInitGroupLoaders',
[ 'TranslatablePageMessageGroupStore::registerLoader' ] );
$mg = MessageGroups::singleton();
$mg->setCache( new WANObjectCache( [ 'cache' => wfGetCache( 'hash' ) ] ) );
$mg->recache();
MessageIndex::setInstance( new HashMessageIndex() );
MessageIndex::singleton()->rebuild();
}
public function testNormalPage() {
$title = Title::newFromText( 'Fréttinga' );
$this->assertNotNull( $title, 'Title is valid' );
$page = WikiPage::factory( $title );
$this->assertNotNull( $page, 'WikiPage is valid' );
$translatablePage = TranslatablePage::newFromTitle( $title );
$content = ContentHandler::makeContent( 'kissa', $title );
$page->doEditContent( $content, 'Test case' );
$this->assertFalse( $translatablePage->getReadyTag(), 'No ready tag was added' );
$this->assertFalse( $translatablePage->getMarkedTag(), 'No marked tag was added' );
}
public function testTranslatablePage() {
$title = Title::newFromText( 'Fréttinga' );
$this->assertNotNull( $title, 'Title is valid' );
$page = WikiPage::factory( $title );
$this->assertNotNull( $page, 'WikiPage is valid' );
$translatablePage = TranslatablePage::newFromTitle( $title );
$content = ContentHandler::makeContent( '<translate>kissa</translate>', $title );
$status = $page->doEditContent( $content, 'Test case' );
$latest = $status->value['revision-record']->getId();
$this->assertSame( $latest, $translatablePage->getReadyTag(), 'Ready tag was added' );
$this->assertFalse( $translatablePage->getMarkedTag(), 'No marked tag was added' );
}
public function testTranslatablePageWithMarked() {
$title = Title::newFromText( 'Fréttinga' );
$this->assertNotNull( $title, 'Title is valid' );
$page = WikiPage::factory( $title );
$this->assertNotNull( $page, 'WikiPage is valid' );
$translatablePage = TranslatablePage::newFromTitle( $title );
$content = ContentHandler::makeContent( '<translate>koira</translate>', $title );
$status = $page->doEditContent( $content, 'Test case' );
$latest = $status->value['revision-record']->getId();
$translatablePage->addMarkedTag( $latest, [ 'foo' ] );
$this->assertSame( $latest, $translatablePage->getReadyTag(), 'Ready tag was added' );
$this->assertSame( $latest, $translatablePage->getMarkedTag(), 'Marked tag was added' );
$cascade = false;
$user = $this->getTestSysop()->getUser();
$page->doUpdateRestrictions(
[ 'edit' => 'sysop' ],
[],
$cascade,
'Test case',
$user
);
$newLatest = $latest + 1;
$this->assertSame(
$newLatest,
$translatablePage->getReadyTag(),
'Ready tag was updated after protection'
);
$this->assertSame(
$latest,
$translatablePage->getMarkedTag(),
'Marked tag was not updated after protection'
);
$page->doUpdateRestrictions( [], [], $cascade, 'Test case', $user );
}
public function testTranslationPageRestrictions() {
$superUser = $this->getTestSysop()->getUser();
$title = Title::newFromText( 'Translatable page' );
$page = WikiPage::factory( $title );
$content = ContentHandler::makeContent( '<translate>Hello</translate>', $title );
$status = $page->doEditContent(
$content,
'New page',
0,
false,
$superUser
);
$revisionId = $status->value['revision-record']->getId();
$translatablePage = TranslatablePage::newFromRevision( $title, $revisionId );
$translatablePage->addMarkedTag( $revisionId );
MessageGroups::singleton()->recache();
$translationPage = Title::newFromText( 'Translatable page/fi' );
$pm = MediaWikiServices::getInstance()->getPermissionManager();
TranslateRenderJob::newJob( $translationPage )->run();
$this->assertTrue( $pm->userCan( 'read', $superUser, $translationPage ),
'Users can read existing translation pages' );
$this->assertFalse( $pm->userCan( 'edit', $superUser, $translationPage ),
'Users can not edit existing translation pages' );
$translationPage = Title::newFromText( 'Translatable page/ab' );
$this->assertTrue( $pm->userCan( 'read', $superUser, $translationPage ),
'Users can read non-existing translation pages' );
$this->assertFalse( $pm->userCan( 'edit', $superUser, $translationPage ),
'Users can not edit non-existing translation pages' );
}
}
|