InstallDocFormatterTest.php 3.0 KB

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