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
|
<?php
declare( strict_types = 1 );
namespace MediaWiki\Extension\Translate\PageTranslation;
use MediaWiki\Linker\LinkTarget;
use MediaWikiUnitTestCase;
use TitleValue;
/**
* @author Niklas Laxström
* @license GPL-2.0-or-later
* @covers MediaWiki\Extension\Translate\PageTranslation\TranslatablePage
*/
class TranslatablePageTest extends MediaWikiUnitTestCase {
/** @dataProvider provideTestParseTranslationUnit */
public function testParseTranslationUnit( LinkTarget $input, array $expected ) {
$output = TranslatablePage::parseTranslationUnit( $input );
$this->assertEquals( $expected, $output );
}
public static function provideTestParseTranslationUnit() {
// The namespace constant is not defined in unit tests. But it is ignored anway.
$ns = 1198;
yield [
new TitleValue( $ns, 'Template:Foo/bar/SectionName/LanguageCode' ),
[
'sourcepage' => 'Template:Foo/bar',
'section' => 'SectionName',
'language' => 'LanguageCode',
]
];
yield [
new TitleValue( $ns, 'Template:Foo/bar/SectionName' ),
[
'sourcepage' => 'Template:Foo',
'section' => 'bar',
'language' => 'SectionName',
]
];
yield [
new TitleValue( $ns, 'Foo' ),
[
'sourcepage' => '',
'section' => '',
'language' => 'Foo',
]
];
}
/** @dataProvider provideDetermineStatus */
public function testDetermineStatus(
?int $readyRevisionId,
?int $markRevisionId,
int $latestRevisionId,
?int $expectedStatus
): void {
$status = TranslatablePage::determineStatus( $readyRevisionId, $markRevisionId, $latestRevisionId );
if ( $expectedStatus ) {
$this->assertEquals( $expectedStatus, $status->getId() );
} else {
$this->assertNull( $status );
}
}
public static function provideDetermineStatus() {
$readyRevisionId = 1;
$markRevisionId = null;
$latestRevisionId = 1;
yield 'Proposed pages' => [
$readyRevisionId,
$markRevisionId,
$latestRevisionId,
TranslatablePageStatus::PROPOSED
];
$readyRevisionId = $markRevisionId = $latestRevisionId = 1;
yield 'Active pages' => [
$readyRevisionId,
$markRevisionId,
$latestRevisionId,
TranslatablePageStatus::ACTIVE
];
$markRevisionId = 1;
$readyRevisionId = $latestRevisionId = 2;
yield 'Outdated pages' => [
$readyRevisionId,
$markRevisionId,
$latestRevisionId,
TranslatablePageStatus::OUTDATED
];
$readyRevisionId = $markRevisionId = 1;
$latestRevisionId = 2;
yield 'Broken pages' => [
$readyRevisionId,
$markRevisionId,
$latestRevisionId,
TranslatablePageStatus::BROKEN
];
$readyRevisionId = $markRevisionId = null;
$latestRevisionId = 1;
yield 'Not a translatable page' => [
$readyRevisionId,
$markRevisionId,
$latestRevisionId,
null
];
}
}
|