MediaWiki  REL1_24
LinkerTest.php
Go to the documentation of this file.
00001 <?php
00002 
00007 class LinkerTest extends MediaWikiLangTestCase {
00008 
00013     public function testUserLink( $expected, $userId, $userName, $altUserName = false, $msg = '' ) {
00014         $this->setMwGlobals( array(
00015             'wgArticlePath' => '/wiki/$1',
00016             'wgWellFormedXml' => true,
00017         ) );
00018 
00019         $this->assertEquals( $expected,
00020             Linker::userLink( $userId, $userName, $altUserName, $msg )
00021         );
00022     }
00023 
00024     public static function provideCasesForUserLink() {
00025         # Format:
00026         # - expected
00027         # - userid
00028         # - username
00029         # - optional altUserName
00030         # - optional message
00031         return array(
00032 
00033             ### ANONYMOUS USER ########################################
00034             array(
00035                 '<a href="/wiki/Special:Contributions/JohnDoe" '
00036                     . 'title="Special:Contributions/JohnDoe" '
00037                     . 'class="mw-userlink mw-anonuserlink">JohnDoe</a>',
00038                 0, 'JohnDoe', false,
00039             ),
00040             array(
00041                 '<a href="/wiki/Special:Contributions/::1" '
00042                     . 'title="Special:Contributions/::1" '
00043                     . 'class="mw-userlink mw-anonuserlink">::1</a>',
00044                 0, '::1', false,
00045                 'Anonymous with pretty IPv6'
00046             ),
00047             array(
00048                 '<a href="/wiki/Special:Contributions/0:0:0:0:0:0:0:1" '
00049                     . 'title="Special:Contributions/0:0:0:0:0:0:0:1" '
00050                     . 'class="mw-userlink mw-anonuserlink">::1</a>',
00051                 0, '0:0:0:0:0:0:0:1', false,
00052                 'Anonymous with almost pretty IPv6'
00053             ),
00054             array(
00055                 '<a href="/wiki/Special:Contributions/0000:0000:0000:0000:0000:0000:0000:0001" '
00056                     . 'title="Special:Contributions/0000:0000:0000:0000:0000:0000:0000:0001" '
00057                     . 'class="mw-userlink mw-anonuserlink">::1</a>',
00058                 0, '0000:0000:0000:0000:0000:0000:0000:0001', false,
00059                 'Anonymous with full IPv6'
00060             ),
00061             array(
00062                 '<a href="/wiki/Special:Contributions/::1" '
00063                     . 'title="Special:Contributions/::1" '
00064                     . 'class="mw-userlink mw-anonuserlink">AlternativeUsername</a>',
00065                 0, '::1', 'AlternativeUsername',
00066                 'Anonymous with pretty IPv6 and an alternative username'
00067             ),
00068 
00069             # IPV4
00070             array(
00071                 '<a href="/wiki/Special:Contributions/127.0.0.1" '
00072                     . 'title="Special:Contributions/127.0.0.1" '
00073                     . 'class="mw-userlink mw-anonuserlink">127.0.0.1</a>',
00074                 0, '127.0.0.1', false,
00075                 'Anonymous with IPv4'
00076             ),
00077             array(
00078                 '<a href="/wiki/Special:Contributions/127.0.0.1" '
00079                     . 'title="Special:Contributions/127.0.0.1" '
00080                     . 'class="mw-userlink mw-anonuserlink">AlternativeUsername</a>',
00081                 0, '127.0.0.1', 'AlternativeUsername',
00082                 'Anonymous with IPv4 and an alternative username'
00083             ),
00084 
00085             ### Regular user ##########################################
00086             # TODO!
00087         );
00088     }
00089 
00096     public function testFormatComment( $expected, $comment, $title = false, $local = false ) {
00097         $this->setMwGlobals( array(
00098             'wgScript' => '/wiki/index.php',
00099             'wgArticlePath' => '/wiki/$1',
00100             'wgWellFormedXml' => true,
00101             'wgCapitalLinks' => true,
00102         ) );
00103 
00104         if ( $title === false ) {
00105             // We need a page title that exists
00106             $title = Title::newFromText( 'Special:BlankPage' );
00107         }
00108 
00109         $this->assertEquals(
00110             $expected,
00111             Linker::formatComment( $comment, $title, $local )
00112         );
00113     }
00114 
00115     public static function provideCasesForFormatComment() {
00116         return array(
00117             // Linker::formatComment
00118             array(
00119                 'a&lt;script&gt;b',
00120                 'a<script>b',
00121             ),
00122             array(
00123                 'a—b',
00124                 'a&mdash;b',
00125             ),
00126             array(
00127                 "&#039;&#039;&#039;not bolded&#039;&#039;&#039;",
00128                 "'''not bolded'''",
00129             ),
00130             // Linker::formatAutocomments
00131             array(
00132                 '<a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→</a>‎<span dir="auto"><span class="autocomment">autocomment</span></span>',
00133                 "/* autocomment */",
00134             ),
00135             array(
00136                 '<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>',
00137                 "/* [[linkie?]] */",
00138             ),
00139             array(
00140                 '<a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→</a>‎<span dir="auto"><span class="autocomment">autocomment: </span> post</span>',
00141                 "/* autocomment */ post",
00142             ),
00143             array(
00144                 'pre <a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→</a>‎<span dir="auto"><span class="autocomment">autocomment</span></span>',
00145                 "pre /* autocomment */",
00146             ),
00147             array(
00148                 'pre <a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→</a>‎<span dir="auto"><span class="autocomment">autocomment: </span> post</span>',
00149                 "pre /* autocomment */ post",
00150             ),
00151             array(
00152                 '/* autocomment */ multiple? <a href="/wiki/Special:BlankPage#autocomment2" title="Special:BlankPage">→</a>‎<span dir="auto"><span class="autocomment">autocomment2: </span> </span>',
00153                 "/* autocomment */ multiple? /* autocomment2 */ ",
00154             ),
00155             array(
00156                 '<a href="#autocomment">→</a>‎<span dir="auto"><span class="autocomment">autocomment</span></span>',
00157                 "/* autocomment */",
00158                 false, true
00159             ),
00160             array(
00161                 '‎<span dir="auto"><span class="autocomment">autocomment</span></span>',
00162                 "/* autocomment */",
00163                 null
00164             ),
00165             // Linker::formatLinksInComment
00166             array(
00167                 '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',
00168                 "abc [[link]] def",
00169             ),
00170             array(
00171                 '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',
00172                 "abc [[link|text]] def",
00173             ),
00174             array(
00175                 'abc <a href="/wiki/Special:BlankPage" title="Special:BlankPage">Special:BlankPage</a> def',
00176                 "abc [[Special:BlankPage|]] def",
00177             ),
00178             array(
00179                 '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',
00180                 "abc [[%C4%85%C5%9B%C5%BC]] def",
00181             ),
00182             array(
00183                 'abc <a href="/wiki/Special:BlankPage#section" title="Special:BlankPage">#section</a> def',
00184                 "abc [[#section]] def",
00185             ),
00186             array(
00187                 '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',
00188                 "abc [[/subpage]] def",
00189             ),
00190         );
00191     }
00192 }