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
|
<?php
declare( strict_types = 1 );
/**
* @author Niklas Laxström
* @license GPL-2.0-or-later
* @covers \TPSection
*/
class TPSectionTest extends \MediaWikiUnitTestCase {
/** @dataProvider providerTestGetMarkedText */
public function testGetMarkedText(
string $name, string $text, bool $inline, string $expected
) {
$section = new TPSection();
$section->name = $name;
$section->text = $text;
$section->setIsInline( $inline );
$output = $section->getMarkedText();
$this->assertEquals( $expected, $output );
}
/** @dataProvider providerTestGetTextWithVariables */
public function testGetTextWithVariables( string $text, string $expected ) {
$section = new TPSection();
$section->text = $text;
$output = $section->getTextWithVariables();
$this->assertEquals( $expected, $output );
}
/** @dataProvider providerTestGetTextForTrans */
public function testGetTextForTrans( string $text, string $expected ) {
$section = new TPSection();
$section->text = $text;
$output = $section->getTextForTrans();
$this->assertEquals( $expected, $output );
}
public static function providerTestGetMarkedText() {
$cases = [];
// Inline syntax
$cases[] = [
'name',
'Hello',
true,
'<!--T:name--> Hello',
];
// Normal syntax
$cases[] = [
'name',
'Hello',
false,
"<!--T:name-->\nHello",
];
// Inline should not matter for headings, which have special syntax, but test both values
$cases[] = [
'name',
'== Hello ==',
true,
'== Hello == <!--T:name-->',
];
$cases[] = [
'name',
'====== Hello ======',
false,
'====== Hello ====== <!--T:name-->',
];
return $cases;
}
public static function providerTestGetTextWithVariables() {
$cases = [];
// syntax
$cases[] = [
"<tvar|abc>Peter\n cat!</>",
'$abc',
];
$cases[] = [
"<tvar|1>Hello</>\n<tvar|2>Hello</>",
"$1\n$2",
];
return $cases;
}
public static function providerTestGetTextForTrans() {
$cases = [];
// syntax
$cases[] = [
"<tvar|abc>Peter\n cat!</>",
"Peter\n cat!",
];
$cases[] = [
"<tvar|1>Hello</>\n<tvar|2>Hello</>",
"Hello\nHello",
];
return $cases;
}
}
|