Debian Codegraph @

tests/phpunit/unit/includes/installer/InstallDocFormatterTest.php

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