Limit test leakage, $wgCapitalLinks expected to be true
[lhc/web/wiklou.git] / tests / phpunit / includes / LinkerTest.php
index 110cbac..72114e9 100644 (file)
@@ -82,4 +82,107 @@ class LinkerTest extends MediaWikiLangTestCase {
                        # TODO!
                );
        }
+
+       /**
+        * @dataProvider provideCasesForFormatComment
+        * @covers Linker::formatComment
+        * @covers Linker::formatAutocomments
+        * @covers Linker::formatLinksInComment
+        */
+       public function testFormatComment( $expected, $comment, $title = false, $local = false ) {
+               $this->setMwGlobals( array(
+                       'wgScript' => '/wiki/index.php',
+                       'wgArticlePath' => '/wiki/$1',
+                       'wgWellFormedXml' => true,
+                       'wgCapitalLinks' => true,
+               ) );
+
+               if ( $title === false ) {
+                       // We need a page title that exists
+                       $title = Title::newFromText( 'Special:BlankPage' );
+               }
+
+               $this->assertEquals(
+                       $expected,
+                       Linker::formatComment( $comment, $title, $local )
+               );
+       }
+
+       public static function provideCasesForFormatComment() {
+               return array(
+                       // Linker::formatComment
+                       array(
+                               'a<script>b',
+                               'a<script>b',
+                       ),
+                       array(
+                               'a—b',
+                               'a&mdash;b',
+                       ),
+                       array(
+                               "&#039;&#039;&#039;not bolded&#039;&#039;&#039;",
+                               "'''not bolded'''",
+                       ),
+                       // Linker::formatAutocomments
+                       array(
+                               '<a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→</a>‎<span dir="auto"><span class="autocomment">autocomment</span></span>',
+                               "/* autocomment */",
+                       ),
+                       array(
+                               '<a href="/wiki/Special:BlankPage#linkie.3F" title="Special:BlankPage">→</a>‎<span dir="auto"><span class="autocomment"><a href="/wiki/index.php?title=Linkie%3F&amp;action=edit&amp;redlink=1" class="new" title="Linkie? (page does not exist)">linkie?</a></span></span>',
+                               "/* [[linkie?]] */",
+                       ),
+                       array(
+                               '<a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→</a>‎<span dir="auto"><span class="autocomment">autocomment: </span> post</span>',
+                               "/* autocomment */ post",
+                       ),
+                       array(
+                               'pre <a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→</a>‎<span dir="auto"><span class="autocomment">autocomment</span></span>',
+                               "pre /* autocomment */",
+                       ),
+                       array(
+                               'pre <a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→</a>‎<span dir="auto"><span class="autocomment">autocomment: </span> post</span>',
+                               "pre /* autocomment */ post",
+                       ),
+                       array(
+                               '/* autocomment */ multiple? <a href="/wiki/Special:BlankPage#autocomment2" title="Special:BlankPage">→</a>‎<span dir="auto"><span class="autocomment">autocomment2: </span> </span>',
+                               "/* autocomment */ multiple? /* autocomment2 */ ",
+                       ),
+                       array(
+                               '<a href="#autocomment">→</a>‎<span dir="auto"><span class="autocomment">autocomment</span></span>',
+                               "/* autocomment */",
+                               false, true
+                       ),
+                       array(
+                               '‎<span dir="auto"><span class="autocomment">autocomment</span></span>',
+                               "/* autocomment */",
+                               null
+                       ),
+                       // Linker::formatLinksInComment
+                       array(
+                               'abc <a href="/wiki/index.php?title=Link&amp;action=edit&amp;redlink=1" class="new" title="Link (page does not exist)">link</a> def',
+                               "abc [[link]] def",
+                       ),
+                       array(
+                               'abc <a href="/wiki/index.php?title=Link&amp;action=edit&amp;redlink=1" class="new" title="Link (page does not exist)">text</a> def',
+                               "abc [[link|text]] def",
+                       ),
+                       array(
+                               'abc <a href="/wiki/Special:BlankPage" title="Special:BlankPage">Special:BlankPage</a> def',
+                               "abc [[Special:BlankPage|]] def",
+                       ),
+                       array(
+                               'abc <a href="/wiki/index.php?title=%C4%84%C5%9B%C5%BC&amp;action=edit&amp;redlink=1" class="new" title="Ąśż (page does not exist)">ąśż</a> def',
+                               "abc [[%C4%85%C5%9B%C5%BC]] def",
+                       ),
+                       array(
+                               'abc <a href="/wiki/Special:BlankPage#section" title="Special:BlankPage">#section</a> def',
+                               "abc [[#section]] def",
+                       ),
+                       array(
+                               'abc <a href="/wiki/index.php?title=/subpage&amp;action=edit&amp;redlink=1" class="new" title="/subpage (page does not exist)">/subpage</a> def',
+                               "abc [[/subpage]] def",
+                       ),
+               );
+       }
 }