Merge "Type hint against LinkTarget in WatchedItemStore"
[lhc/web/wiklou.git] / tests / phpunit / unit / includes / installer / InstallDocFormatterTest.php
1 <?php
2
3 class InstallDocFormatterTest extends \MediaWikiUnitTestCase {
4 /**
5 * @covers InstallDocFormatter
6 * @dataProvider provideDocFormattingTests
7 */
8 public function testFormat( $expected, $unformattedText, $message = '' ) {
9 $this->assertEquals(
10 $expected,
11 InstallDocFormatter::format( $unformattedText ),
12 $message
13 );
14 }
15
16 /**
17 * Provider for testFormat()
18 */
19 public static function provideDocFormattingTests() {
20 # Format: (expected string, unformattedText string, optional message)
21 return [
22 # Escape some wikitext
23 [ 'Install &lt;tag>', 'Install <tag>', 'Escaping <' ],
24 [ 'Install &#123;&#123;template}}', 'Install {{template}}', 'Escaping [[' ],
25 [ 'Install &#91;&#91;page]]', 'Install [[page]]', 'Escaping {{' ],
26 [ 'Install &#95;&#95;TOC&#95;&#95;', 'Install __TOC__', 'Escaping __' ],
27 [ 'Install ', "Install \r", 'Removing \r' ],
28
29 # Transform \t{1,2} into :{1,2}
30 [ ':One indentation', "\tOne indentation", 'Replacing a single \t' ],
31 [ '::Two indentations', "\t\tTwo indentations", 'Replacing 2 x \t' ],
32
33 # Transform 'T123' links
34 [
35 '<span class="config-plainlink">[https://phabricator.wikimedia.org/T123 T123]</span>',
36 'T123', 'Testing T123 links' ],
37 [
38 'bug <span class="config-plainlink">[https://phabricator.wikimedia.org/T123 T123]</span>',
39 'bug T123', 'Testing bug T123 links' ],
40 [
41 '(<span class="config-plainlink">[https://phabricator.wikimedia.org/T987654 T987654]</span>)',
42 '(T987654)', 'Testing (T987654) links' ],
43
44 # "Tabc" shouldn't work
45 [ 'Tfoobar', 'Tfoobar', "Don't match T followed by non-digits" ],
46 [ 'T!!fakefake!!', 'T!!fakefake!!', "Don't match T followed by non-digits" ],
47
48 # Transform 'bug 123' links
49 [
50 '<span class="config-plainlink">[https://bugzilla.wikimedia.org/123 bug 123]</span>',
51 'bug 123', 'Testing bug 123 links' ],
52 [
53 '(<span class="config-plainlink">[https://bugzilla.wikimedia.org/987654 bug 987654]</span>)',
54 '(bug 987654)', 'Testing (bug 987654) links' ],
55
56 # "bug abc" shouldn't work
57 [ 'bug foobar', 'bug foobar', "Don't match bug followed by non-digits" ],
58 [ 'bug !!fakefake!!', 'bug !!fakefake!!', "Don't match bug followed by non-digits" ],
59
60 # Transform '$wgFooBar' links
61 [
62 '<span class="config-plainlink">'
63 . '[https://www.mediawiki.org/wiki/Manual:$wgFooBar $wgFooBar]</span>',
64 '$wgFooBar', 'Testing basic $wgFooBar' ],
65 [
66 '<span class="config-plainlink">'
67 . '[https://www.mediawiki.org/wiki/Manual:$wgFooBar45 $wgFooBar45]</span>',
68 '$wgFooBar45', 'Testing $wgFooBar45 (with numbers)' ],
69 [
70 '<span class="config-plainlink">'
71 . '[https://www.mediawiki.org/wiki/Manual:$wgFoo_Bar $wgFoo_Bar]</span>',
72 '$wgFoo_Bar', 'Testing $wgFoo_Bar (with underscore)' ],
73
74 # Icky variables that shouldn't link
75 [
76 '$myAwesomeVariable',
77 '$myAwesomeVariable',
78 'Testing $myAwesomeVariable (not starting with $wg)'
79 ],
80 [ '$()not!a&Var', '$()not!a&Var', 'Testing $()not!a&Var (obviously not a variable)' ],
81 ];
82 }
83 }