2012-05-22 23:30:07 +00:00
< ? php
2014-08-15 21:11:26 +00:00
/**
* @ group Database
*/
2012-12-06 17:53:43 +00:00
class LinkerTest extends MediaWikiLangTestCase {
2012-05-22 23:30:07 +00:00
/**
* @ dataProvider provideCasesForUserLink
2013-03-11 03:16:28 +00:00
* @ covers Linker :: userLink
2012-05-22 23:30:07 +00:00
*/
2013-10-23 22:51:31 +00:00
public function testUserLink ( $expected , $userId , $userName , $altUserName = false , $msg = '' ) {
2016-02-17 09:09:32 +00:00
$this -> setMwGlobals ( [
2012-05-22 23:30:07 +00:00
'wgArticlePath' => '/wiki/$1' ,
2016-02-17 09:09:32 +00:00
] );
2012-05-22 23:30:07 +00:00
2019-05-06 08:58:09 +00:00
// We'd also test the warning, but injecting a mock logger into a static method is tricky.
2019-05-22 20:12:11 +00:00
if ( ! $userName ) {
2019-05-06 08:58:09 +00:00
Wikimedia\suppressWarnings ();
}
$actual = Linker :: userLink ( $userId , $userName , $altUserName );
2019-05-22 20:12:11 +00:00
if ( ! $userName ) {
2019-05-06 08:58:09 +00:00
Wikimedia\restoreWarnings ();
}
$this -> assertEquals ( $expected , $actual , $msg );
2012-05-22 23:30:07 +00:00
}
2013-03-22 02:12:37 +00:00
public static function provideCasesForUserLink () {
2012-05-22 23:30:07 +00:00
# Format:
# - expected
# - userid
# - username
# - optional altUserName
# - optional message
2016-02-17 09:09:32 +00:00
return [
2019-05-06 08:58:09 +00:00
# Empty name (T222529)
'Empty username, userid 0' => [ '(no username available)' , 0 , '' ],
'Empty username, userid > 0' => [ '(no username available)' , 73 , '' ],
2012-05-22 23:30:07 +00:00
2019-05-22 20:12:11 +00:00
'false instead of username' => [ '(no username available)' , 73 , false ],
'null instead of username' => [ '(no username available)' , 0 , null ],
2015-09-11 13:44:59 +00:00
# ## ANONYMOUS USER ########################################
2016-02-17 09:09:32 +00:00
[
2014-04-24 10:05:52 +00:00
'<a href="/wiki/Special:Contributions/JohnDoe" '
2016-05-25 23:37:21 +00:00
. 'class="mw-userlink mw-anonuserlink" '
2016-08-31 20:58:05 +00:00
. 'title="Special:Contributions/JohnDoe"><bdi>JohnDoe</bdi></a>' ,
2012-05-22 23:30:07 +00:00
0 , 'JohnDoe' , false ,
2016-02-17 09:09:32 +00:00
],
[
2014-04-24 10:05:52 +00:00
'<a href="/wiki/Special:Contributions/::1" '
2016-05-25 23:37:21 +00:00
. 'class="mw-userlink mw-anonuserlink" '
2016-08-31 20:58:05 +00:00
. 'title="Special:Contributions/::1"><bdi>::1</bdi></a>' ,
2012-05-22 23:30:07 +00:00
0 , '::1' , false ,
'Anonymous with pretty IPv6'
2016-02-17 09:09:32 +00:00
],
[
2014-04-24 10:05:52 +00:00
'<a href="/wiki/Special:Contributions/0:0:0:0:0:0:0:1" '
2016-05-25 23:37:21 +00:00
. 'class="mw-userlink mw-anonuserlink" '
2016-08-31 20:58:05 +00:00
. 'title="Special:Contributions/0:0:0:0:0:0:0:1"><bdi>::1</bdi></a>' ,
2012-05-22 23:30:07 +00:00
0 , '0:0:0:0:0:0:0:1' , false ,
'Anonymous with almost pretty IPv6'
2016-02-17 09:09:32 +00:00
],
[
2014-04-24 10:05:52 +00:00
'<a href="/wiki/Special:Contributions/0000:0000:0000:0000:0000:0000:0000:0001" '
2016-05-25 23:37:21 +00:00
. 'class="mw-userlink mw-anonuserlink" '
2016-08-31 20:58:05 +00:00
. 'title="Special:Contributions/0000:0000:0000:0000:0000:0000:0000:0001"><bdi>::1</bdi></a>' ,
2012-05-22 23:30:07 +00:00
0 , '0000:0000:0000:0000:0000:0000:0000:0001' , false ,
'Anonymous with full IPv6'
2016-02-17 09:09:32 +00:00
],
[
2014-04-24 10:05:52 +00:00
'<a href="/wiki/Special:Contributions/::1" '
2016-05-25 23:37:21 +00:00
. 'class="mw-userlink mw-anonuserlink" '
2016-08-31 20:58:05 +00:00
. 'title="Special:Contributions/::1"><bdi>AlternativeUsername</bdi></a>' ,
2012-05-22 23:30:07 +00:00
0 , '::1' , 'AlternativeUsername' ,
'Anonymous with pretty IPv6 and an alternative username'
2016-02-17 09:09:32 +00:00
],
2012-05-22 23:30:07 +00:00
# IPV4
2016-02-17 09:09:32 +00:00
[
2014-04-24 10:05:52 +00:00
'<a href="/wiki/Special:Contributions/127.0.0.1" '
2016-05-25 23:37:21 +00:00
. 'class="mw-userlink mw-anonuserlink" '
2016-08-31 20:58:05 +00:00
. 'title="Special:Contributions/127.0.0.1"><bdi>127.0.0.1</bdi></a>' ,
2012-05-22 23:30:07 +00:00
0 , '127.0.0.1' , false ,
'Anonymous with IPv4'
2016-02-17 09:09:32 +00:00
],
[
2014-04-24 10:05:52 +00:00
'<a href="/wiki/Special:Contributions/127.0.0.1" '
2016-05-25 23:37:21 +00:00
. 'class="mw-userlink mw-anonuserlink" '
2016-08-31 20:58:05 +00:00
. 'title="Special:Contributions/127.0.0.1"><bdi>AlternativeUsername</bdi></a>' ,
2012-05-22 23:30:07 +00:00
0 , '127.0.0.1' , 'AlternativeUsername' ,
'Anonymous with IPv4 and an alternative username'
2016-02-17 09:09:32 +00:00
],
2012-05-22 23:30:07 +00:00
2015-09-11 13:44:59 +00:00
# ## Regular user ##########################################
2012-05-22 23:30:07 +00:00
# TODO!
2016-02-17 09:09:32 +00:00
];
2012-05-22 23:30:07 +00:00
}
2014-06-10 19:37:37 +00:00
2019-05-06 08:58:09 +00:00
/**
* @ dataProvider provideUserToolLinks
* @ covers Linker :: userToolLinks
* @ param string $expected
* @ param int $userId
* @ param string $userText
*/
public function testUserToolLinks ( $expected , $userId , $userText ) {
// We'd also test the warning, but injecting a mock logger into a static method is tricky.
if ( $userText === '' ) {
Wikimedia\suppressWarnings ();
}
$actual = Linker :: userToolLinks ( $userId , $userText );
if ( $userText === '' ) {
Wikimedia\restoreWarnings ();
}
$this -> assertSame ( $expected , $actual );
}
public static function provideUserToolLinks () {
return [
// Empty name (T222529)
'Empty username, userid 0' => [ ' (no username available)' , 0 , '' ],
'Empty username, userid > 0' => [ ' (no username available)' , 73 , '' ],
];
}
/**
* @ dataProvider provideUserTalkLink
* @ covers Linker :: userTalkLink
* @ param string $expected
* @ param int $userId
* @ param string $userText
*/
public function testUserTalkLink ( $expected , $userId , $userText ) {
// We'd also test the warning, but injecting a mock logger into a static method is tricky.
if ( $userText === '' ) {
Wikimedia\suppressWarnings ();
}
$actual = Linker :: userTalkLink ( $userId , $userText );
if ( $userText === '' ) {
Wikimedia\restoreWarnings ();
}
$this -> assertSame ( $expected , $actual );
}
public static function provideUserTalkLink () {
return [
// Empty name (T222529)
'Empty username, userid 0' => [ '(no username available)' , 0 , '' ],
'Empty username, userid > 0' => [ '(no username available)' , 73 , '' ],
];
}
/**
* @ dataProvider provideBlockLink
* @ covers Linker :: blockLink
* @ param string $expected
* @ param int $userId
* @ param string $userText
*/
public function testBlockLink ( $expected , $userId , $userText ) {
// We'd also test the warning, but injecting a mock logger into a static method is tricky.
if ( $userText === '' ) {
Wikimedia\suppressWarnings ();
}
$actual = Linker :: blockLink ( $userId , $userText );
if ( $userText === '' ) {
Wikimedia\restoreWarnings ();
}
$this -> assertSame ( $expected , $actual );
}
public static function provideBlockLink () {
return [
// Empty name (T222529)
'Empty username, userid 0' => [ '(no username available)' , 0 , '' ],
'Empty username, userid > 0' => [ '(no username available)' , 73 , '' ],
];
}
/**
* @ dataProvider provideEmailLink
* @ covers Linker :: emailLink
* @ param string $expected
* @ param int $userId
* @ param string $userText
*/
public function testEmailLink ( $expected , $userId , $userText ) {
// We'd also test the warning, but injecting a mock logger into a static method is tricky.
if ( $userText === '' ) {
Wikimedia\suppressWarnings ();
}
$actual = Linker :: emailLink ( $userId , $userText );
if ( $userText === '' ) {
Wikimedia\restoreWarnings ();
}
$this -> assertSame ( $expected , $actual );
}
public static function provideEmailLink () {
return [
// Empty name (T222529)
'Empty username, userid 0' => [ '(no username available)' , 0 , '' ],
'Empty username, userid > 0' => [ '(no username available)' , 73 , '' ],
];
}
2014-06-10 19:37:37 +00:00
/**
* @ dataProvider provideCasesForFormatComment
* @ covers Linker :: formatComment
* @ covers Linker :: formatAutocomments
* @ covers Linker :: formatLinksInComment
*/
2015-09-26 18:09:08 +00:00
public function testFormatComment (
$expected , $comment , $title = false , $local = false , $wikiId = null
) {
2015-09-07 17:02:24 +00:00
$conf = new SiteConfiguration ();
2016-02-17 09:09:32 +00:00
$conf -> settings = [
'wgServer' => [
2015-09-07 17:02:24 +00:00
'enwiki' => '//en.example.org' ,
'dewiki' => '//de.example.org' ,
2016-02-17 09:09:32 +00:00
],
'wgArticlePath' => [
2015-09-07 17:02:24 +00:00
'enwiki' => '/w/$1' ,
'dewiki' => '/w/$1' ,
2016-02-17 09:09:32 +00:00
],
];
$conf -> suffixes = [ 'wiki' ];
2015-09-07 17:02:24 +00:00
2016-02-17 09:09:32 +00:00
$this -> setMwGlobals ( [
2014-06-24 07:39:17 +00:00
'wgScript' => '/wiki/index.php' ,
2014-06-10 19:37:37 +00:00
'wgArticlePath' => '/wiki/$1' ,
2014-07-07 23:21:09 +00:00
'wgCapitalLinks' => true ,
2015-09-07 17:02:24 +00:00
'wgConf' => $conf ,
2019-10-06 19:22:13 +00:00
// TODO: update tests when the default changes
'wgFragmentMode' => [ 'legacy' ],
2016-02-17 09:09:32 +00:00
] );
2014-06-10 19:37:37 +00:00
if ( $title === false ) {
// We need a page title that exists
$title = Title :: newFromText ( 'Special:BlankPage' );
}
$this -> assertEquals (
$expected ,
2015-09-07 17:02:24 +00:00
Linker :: formatComment ( $comment , $title , $local , $wikiId )
2014-06-10 19:37:37 +00:00
);
}
2015-09-07 17:02:24 +00:00
public function provideCasesForFormatComment () {
$wikiId = 'enwiki' ; // $wgConf has a fake entry for this
2018-01-01 13:10:16 +00:00
// phpcs:disable Generic.Files.LineLength
2016-03-19 01:05:19 +00:00
return [
2014-06-10 19:37:37 +00:00
// Linker::formatComment
2016-03-19 01:05:19 +00:00
[
2014-06-10 19:37:37 +00:00
'a<script>b' ,
'a<script>b' ,
2016-03-19 01:05:19 +00:00
],
[
2014-06-10 19:37:37 +00:00
'a—b' ,
'a—b' ,
2016-03-19 01:05:19 +00:00
],
[
2014-06-10 19:37:37 +00:00
" '''not bolded''' " ,
" '''not bolded''' " ,
2016-03-19 01:05:19 +00:00
],
[
2015-09-07 17:02:24 +00:00
" try <script>evil</scipt> things " ,
" try <script>evil</scipt> things " ,
2016-03-19 01:05:19 +00:00
],
2014-06-10 19:37:37 +00:00
// Linker::formatAutocomments
2016-03-19 01:05:19 +00:00
[
2018-12-01 08:47:03 +00:00
'<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→ autocomment</a></span></span>' ,
2014-06-10 19:37:37 +00:00
" /* autocomment */ " ,
2016-03-19 01:05:19 +00:00
],
[
2018-12-01 09:19:33 +00:00
'<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#linkie.3F" title="Special:BlankPage">→[[linkie?]]</a></span></span>' ,
2014-06-10 19:37:37 +00:00
" /* [[linkie?]] */ " ,
2016-03-19 01:05:19 +00:00
],
2019-05-19 11:17:23 +00:00
[
2019-05-21 10:16:22 +00:00
'<span dir="auto"><span class="autocomment">: </span> // Edit via via</span>' ,
2019-05-19 11:17:23 +00:00
// Regression test for T222857
" /* */ // Edit via via " ,
],
2019-10-06 19:16:53 +00:00
[
'<span dir="auto"><span class="autocomment">: </span> foobar</span>' ,
// Regression test for T222857
" /**/ foobar " ,
],
2016-03-19 01:05:19 +00:00
[
2018-12-01 08:47:03 +00:00
'<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→ autocomment</a>: </span> post</span>' ,
2014-06-10 19:37:37 +00:00
" /* autocomment */ post " ,
2016-03-19 01:05:19 +00:00
],
[
2018-12-01 08:47:03 +00:00
'pre <span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→ autocomment</a></span></span>' ,
2014-06-10 19:37:37 +00:00
" pre /* autocomment */ " ,
2016-03-19 01:05:19 +00:00
],
[
2018-12-01 08:47:03 +00:00
'pre <span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→ autocomment</a>: </span> post</span>' ,
2014-06-10 19:37:37 +00:00
" pre /* autocomment */ post " ,
2016-03-19 01:05:19 +00:00
],
[
2018-12-01 08:47:03 +00:00
'<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→ autocomment</a>: </span> multiple? <span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment2" title="Special:BlankPage">→ autocomment2</a></span></span></span>' ,
2018-11-21 22:48:16 +00:00
" /* autocomment */ multiple? /* autocomment2 */ " ,
2016-03-19 01:05:19 +00:00
],
[
2018-12-01 08:47:03 +00:00
'<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment_containing_.2F.2A" title="Special:BlankPage">→ autocomment containing /*</a>: </span> T70361</span>' ,
2014-09-09 15:25:10 +00:00
" /* autocomment containing /* */ T70361 "
2016-03-19 01:05:19 +00:00
],
[
2018-12-01 08:47:03 +00:00
'<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment_containing_.22quotes.22" title="Special:BlankPage">→ autocomment containing "quotes"</a></span></span>' ,
2015-09-07 17:02:24 +00:00
" /* autocomment containing \" quotes \" */ "
2016-03-19 01:05:19 +00:00
],
[
2018-12-01 08:47:03 +00:00
'<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment_containing_.3Cscript.3Etags.3C.2Fscript.3E" title="Special:BlankPage">→ autocomment containing <script>tags</script></a></span></span>' ,
2015-09-07 17:02:24 +00:00
" /* autocomment containing <script>tags</script> */ "
2016-03-19 01:05:19 +00:00
],
[
2018-12-01 08:47:03 +00:00
'<span dir="auto"><span class="autocomment"><a href="#autocomment">→ autocomment</a></span></span>' ,
2014-06-10 19:37:37 +00:00
" /* autocomment */ " ,
false , true
2016-03-19 01:05:19 +00:00
],
[
2018-12-01 08:47:03 +00:00
'<span dir="auto"><span class="autocomment">autocomment</span></span>' ,
2014-06-10 19:37:37 +00:00
" /* autocomment */ " ,
null
2016-03-19 01:05:19 +00:00
],
2019-05-21 10:16:22 +00:00
[
'' ,
" /* */ " ,
false , true
],
[
'' ,
" /* */ " ,
null
],
[
'<span dir="auto"><span class="autocomment">[[</span></span>' ,
" /* [[ */ " ,
false , true
],
[
'<span dir="auto"><span class="autocomment">[[</span></span>' ,
" /* [[ */ " ,
null
],
[
" foo <span dir= \" auto \" ><span class= \" autocomment \" ><a href= \" #.23 \" >→[[#_ \t _]]</a></span></span> " ,
" foo /* [[#_ \t _]] */ " ,
false , true
],
[
" foo <span dir= \" auto \" ><span class= \" autocomment \" ><a href= \" #_.09 \" >#_ \t _</a></span></span> " ,
" foo /* [[#_ \t _]] */ " ,
null
],
2016-03-19 01:05:19 +00:00
[
2018-12-01 08:47:03 +00:00
'<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→ autocomment</a></span></span>' ,
2015-09-07 17:02:24 +00:00
" /* autocomment */ " ,
false , false
2016-03-19 01:05:19 +00:00
],
[
2018-12-01 08:47:03 +00:00
'<span dir="auto"><span class="autocomment"><a class="external" rel="nofollow" href="//en.example.org/w/Special:BlankPage#autocomment">→ autocomment</a></span></span>' ,
2015-09-07 17:02:24 +00:00
" /* autocomment */ " ,
false , false , $wikiId
2016-03-19 01:05:19 +00:00
],
2014-06-10 19:37:37 +00:00
// Linker::formatLinksInComment
2016-03-19 01:05:19 +00:00
[
2014-06-10 19:37:37 +00:00
'abc <a href="/wiki/index.php?title=Link&action=edit&redlink=1" class="new" title="Link (page does not exist)">link</a> def' ,
" abc [[link]] def " ,
2016-03-19 01:05:19 +00:00
],
[
2014-06-10 19:37:37 +00:00
'abc <a href="/wiki/index.php?title=Link&action=edit&redlink=1" class="new" title="Link (page does not exist)">text</a> def' ,
" abc [[link|text]] def " ,
2016-03-19 01:05:19 +00:00
],
[
2014-06-10 19:37:37 +00:00
'abc <a href="/wiki/Special:BlankPage" title="Special:BlankPage">Special:BlankPage</a> def' ,
" abc [[Special:BlankPage|]] def " ,
2016-03-19 01:05:19 +00:00
],
[
2014-06-10 19:37:37 +00:00
'abc <a href="/wiki/index.php?title=%C4%84%C5%9B%C5%BC&action=edit&redlink=1" class="new" title="Ąśż (page does not exist)">ąśż</a> def' ,
" abc [[%C4%85%C5%9B%C5%BC]] def " ,
2016-03-19 01:05:19 +00:00
],
[
2014-06-10 19:37:37 +00:00
'abc <a href="/wiki/Special:BlankPage#section" title="Special:BlankPage">#section</a> def' ,
" abc [[#section]] def " ,
2016-03-19 01:05:19 +00:00
],
[
2014-06-10 19:37:37 +00:00
'abc <a href="/wiki/index.php?title=/subpage&action=edit&redlink=1" class="new" title="/subpage (page does not exist)">/subpage</a> def' ,
" abc [[/subpage]] def " ,
2016-03-19 01:05:19 +00:00
],
[
2015-09-07 17:02:24 +00:00
'abc <a href="/wiki/index.php?title=%22evil!%22&action=edit&redlink=1" class="new" title=""evil!" (page does not exist)">"evil!"</a> def' ,
" abc [[ \" evil! \" ]] def " ,
2016-03-19 01:05:19 +00:00
],
[
2015-09-07 17:02:24 +00:00
'abc [[<script>very evil</script>]] def' ,
" abc [[<script>very evil</script>]] def " ,
2016-03-19 01:05:19 +00:00
],
[
2015-09-07 17:02:24 +00:00
'abc [[|]] def' ,
" abc [[|]] def " ,
2016-03-19 01:05:19 +00:00
],
[
2015-09-07 17:02:24 +00:00
'abc <a href="/wiki/index.php?title=Link&action=edit&redlink=1" class="new" title="Link (page does not exist)">link</a> def' ,
" abc [[link]] def " ,
false , false
2016-03-19 01:05:19 +00:00
],
[
2015-09-07 17:02:24 +00:00
'abc <a class="external" rel="nofollow" href="//en.example.org/w/Link">link</a> def' ,
" abc [[link]] def " ,
false , false , $wikiId
2016-03-19 01:05:19 +00:00
],
];
2018-01-01 13:10:16 +00:00
// phpcs:enable
2014-06-10 19:37:37 +00:00
}
2015-01-02 18:33:04 +00:00
/**
* @ covers Linker :: formatLinksInComment
* @ dataProvider provideCasesForFormatLinksInComment
*/
public function testFormatLinksInComment ( $expected , $input , $wiki ) {
$conf = new SiteConfiguration ();
2016-02-17 09:09:32 +00:00
$conf -> settings = [
'wgServer' => [
2015-01-02 18:33:04 +00:00
'enwiki' => '//en.example.org'
2016-02-17 09:09:32 +00:00
],
'wgArticlePath' => [
2015-01-02 18:33:04 +00:00
'enwiki' => '/w/$1' ,
2016-02-17 09:09:32 +00:00
],
];
$conf -> suffixes = [ 'wiki' ];
$this -> setMwGlobals ( [
2015-01-02 18:33:04 +00:00
'wgScript' => '/wiki/index.php' ,
'wgArticlePath' => '/wiki/$1' ,
'wgCapitalLinks' => true ,
'wgConf' => $conf ,
2016-02-17 09:09:32 +00:00
] );
2015-01-02 18:33:04 +00:00
$this -> assertEquals (
$expected ,
Linker :: formatLinksInComment ( $input , Title :: newFromText ( 'Special:BlankPage' ), false , $wiki )
);
}
2019-02-05 13:31:53 +00:00
/**
* @ covers Linker :: generateRollback
* @ dataProvider provideCasesForRollbackGeneration
*/
2019-05-29 21:05:10 +00:00
public function testGenerateRollback ( $rollbackEnabled , $expectedModules , $title ) {
2019-02-05 13:31:53 +00:00
$this -> markTestSkippedIfDbType ( 'postgres' );
$context = RequestContext :: getMain ();
$user = $context -> getUser ();
$user -> setOption ( 'showrollbackconfirmation' , $rollbackEnabled );
2019-09-17 14:31:49 +00:00
$this -> assertSame ( 0 , Title :: newFromText ( $title ) -> getArticleID () );
2019-05-29 21:05:10 +00:00
$pageData = $this -> insertPage ( $title );
2019-02-05 13:31:53 +00:00
$page = WikiPage :: factory ( $pageData [ 'title' ] );
$updater = $page -> newPageUpdater ( $user );
$updater -> setContent ( \MediaWiki\Revision\SlotRecord :: MAIN ,
new TextContent ( 'Technical Wishes 123!' )
);
$summary = CommentStoreComment :: newUnsavedComment ( 'Some comment!' );
$updater -> saveRevision ( $summary );
$rollbackOutput = Linker :: generateRollback ( $page -> getRevision (), $context );
$modules = $context -> getOutput () -> getModules ();
2019-05-29 21:05:10 +00:00
$currentRev = $page -> getRevision ();
$oldestRev = $page -> getOldestRevision ();
2019-02-05 13:31:53 +00:00
$this -> assertEquals ( $expectedModules , $modules );
2019-05-29 21:05:10 +00:00
$this -> assertEquals ( $user -> getName (), $currentRev -> getUserText () );
$this -> assertEquals (
static :: getTestSysop () -> getUser (),
$oldestRev -> getUserText ()
);
$ids = [];
$r = $oldestRev ;
while ( $r ) {
$ids [] = $r -> getId ();
$r = $r -> getNext ();
}
$this -> assertEquals ( [ $oldestRev -> getId (), $currentRev -> getId () ], $ids );
2019-02-05 13:31:53 +00:00
$this -> assertContains ( 'rollback 1 edit' , $rollbackOutput );
}
public static function provideCasesForRollbackGeneration () {
return [
[
true ,
2019-05-29 21:05:10 +00:00
[ 'mediawiki.page.rollback.confirmation' ],
'Rollback_Test_Page'
2019-02-05 13:31:53 +00:00
],
[
false ,
2019-05-29 21:05:10 +00:00
[],
'Rollback_Test_Page2'
2019-02-05 13:31:53 +00:00
]
];
}
2015-01-02 18:33:04 +00:00
public static function provideCasesForFormatLinksInComment () {
2018-01-01 13:10:16 +00:00
// phpcs:disable Generic.Files.LineLength
2016-03-19 01:05:19 +00:00
return [
[
2015-01-02 18:33:04 +00:00
'foo bar <a href="/wiki/Special:BlankPage" title="Special:BlankPage">Special:BlankPage</a>' ,
'foo bar [[Special:BlankPage]]' ,
null ,
2016-03-19 01:05:19 +00:00
],
2018-06-26 09:55:21 +00:00
[
'<a href="/wiki/Special:BlankPage" title="Special:BlankPage">Special:BlankPage</a>' ,
'[[ :Special:BlankPage]]' ,
null ,
],
2016-03-19 01:05:19 +00:00
[
2015-01-14 23:48:54 +00:00
'<a class="external" rel="nofollow" href="//en.example.org/w/Foo%27bar">Foo\'bar</a>' ,
" [[Foo'bar]] " ,
'enwiki' ,
2016-03-19 01:05:19 +00:00
],
[
2015-01-02 18:33:04 +00:00
'foo bar <a class="external" rel="nofollow" href="//en.example.org/w/Special:BlankPage">Special:BlankPage</a>' ,
'foo bar [[Special:BlankPage]]' ,
'enwiki' ,
2016-03-19 01:05:19 +00:00
],
2017-06-29 13:06:24 +00:00
[
'foo bar <a class="external" rel="nofollow" href="//en.example.org/w/File:Example">Image:Example</a>' ,
'foo bar [[Image:Example]]' ,
'enwiki' ,
],
2016-03-19 01:05:19 +00:00
];
2018-01-01 13:10:16 +00:00
// phpcs:enable
2015-01-02 18:33:04 +00:00
}
2016-05-11 04:39:22 +00:00
2016-05-11 22:50:29 +00:00
public static function provideLinkBeginHook () {
2018-01-01 13:10:16 +00:00
// phpcs:disable Generic.Files.LineLength
2016-05-11 22:50:29 +00:00
return [
// Modify $html
[
2018-01-01 13:10:16 +00:00
function ( $dummy , $title , & $html , & $attribs , & $query , & $options , & $ret ) {
2016-05-11 22:50:29 +00:00
$html = 'foobar' ;
},
'<a href="/wiki/Special:BlankPage" title="Special:BlankPage">foobar</a>'
],
// Modify $attribs
[
2018-01-01 13:10:16 +00:00
function ( $dummy , $title , & $html , & $attribs , & $query , & $options , & $ret ) {
2016-05-11 22:50:29 +00:00
$attribs [ 'bar' ] = 'baz' ;
},
'<a href="/wiki/Special:BlankPage" title="Special:BlankPage" bar="baz">Special:BlankPage</a>'
],
// Modify $query
[
2018-01-01 13:10:16 +00:00
function ( $dummy , $title , & $html , & $attribs , & $query , & $options , & $ret ) {
2016-05-11 22:50:29 +00:00
$query [ 'bar' ] = 'baz' ;
},
'<a href="/w/index.php?title=Special:BlankPage&bar=baz" title="Special:BlankPage">Special:BlankPage</a>'
],
// Force HTTP $options
[
2018-01-01 13:10:16 +00:00
function ( $dummy , $title , & $html , & $attribs , & $query , & $options , & $ret ) {
2016-05-11 22:50:29 +00:00
$options = [ 'http' ];
},
'<a href="http://example.org/wiki/Special:BlankPage" title="Special:BlankPage">Special:BlankPage</a>'
],
// Force 'forcearticlepath' in $options
[
2018-01-01 13:10:16 +00:00
function ( $dummy , $title , & $html , & $attribs , & $query , & $options , & $ret ) {
2016-05-11 22:50:29 +00:00
$options = [ 'forcearticlepath' ];
$query [ 'foo' ] = 'bar' ;
},
'<a href="/wiki/Special:BlankPage?foo=bar" title="Special:BlankPage">Special:BlankPage</a>'
],
// Abort early
[
2018-01-01 13:10:16 +00:00
function ( $dummy , $title , & $html , & $attribs , & $query , & $options , & $ret ) {
2016-05-11 22:50:29 +00:00
$ret = 'foobar' ;
return false ;
},
'foobar'
],
];
2018-01-01 13:10:16 +00:00
// phpcs:enable
2016-05-11 22:50:29 +00:00
}
/**
2016-05-28 02:30:42 +00:00
* @ covers MediaWiki\Linker\LinkRenderer :: runLegacyBeginHook
2016-05-11 22:50:29 +00:00
* @ dataProvider provideLinkBeginHook
*/
public function testLinkBeginHook ( $callback , $expected ) {
2018-06-10 18:30:15 +00:00
$this -> hideDeprecated ( 'LinkBegin hook (used in hook-LinkBegin-closure)' );
2016-05-11 22:50:29 +00:00
$this -> setMwGlobals ( [
'wgArticlePath' => '/wiki/$1' ,
'wgServer' => '//example.org' ,
'wgCanonicalServer' => 'http://example.org' ,
'wgScriptPath' => '/w' ,
'wgScript' => '/w/index.php' ,
] );
$this -> setMwGlobals ( 'wgHooks' , [ 'LinkBegin' => [ $callback ] ] );
$title = SpecialPage :: getTitleFor ( 'Blankpage' );
$out = Linker :: link ( $title );
$this -> assertEquals ( $expected , $out );
}
2016-05-11 04:39:22 +00:00
public static function provideLinkEndHook () {
return [
// Override $html
[
2017-06-26 16:35:31 +00:00
function ( $dummy , $title , $options , & $html , & $attribs , & $ret ) {
2016-05-11 04:39:22 +00:00
$html = 'foobar' ;
},
'<a href="/wiki/Special:BlankPage" title="Special:BlankPage">foobar</a>'
],
// Modify $attribs
[
2017-06-26 16:35:31 +00:00
function ( $dummy , $title , $options , & $html , & $attribs , & $ret ) {
2016-05-11 04:39:22 +00:00
$attribs [ 'bar' ] = 'baz' ;
},
'<a href="/wiki/Special:BlankPage" title="Special:BlankPage" bar="baz">Special:BlankPage</a>'
],
// Fully override return value and abort hook
[
2017-06-26 16:35:31 +00:00
function ( $dummy , $title , $options , & $html , & $attribs , & $ret ) {
2016-05-11 04:39:22 +00:00
$ret = 'blahblahblah' ;
return false ;
},
'blahblahblah'
],
];
}
/**
2016-05-28 02:30:42 +00:00
* @ covers MediaWiki\Linker\LinkRenderer :: buildAElement
2016-05-11 04:39:22 +00:00
* @ dataProvider provideLinkEndHook
*/
public function testLinkEndHook ( $callback , $expected ) {
2018-06-10 18:30:15 +00:00
$this -> hideDeprecated ( 'LinkEnd hook (used in hook-LinkEnd-closure)' );
2016-05-11 04:39:22 +00:00
$this -> setMwGlobals ( [
'wgArticlePath' => '/wiki/$1' ,
] );
$this -> setMwGlobals ( 'wgHooks' , [ 'LinkEnd' => [ $callback ] ] );
$title = SpecialPage :: getTitleFor ( 'Blankpage' );
$out = Linker :: link ( $title );
$this -> assertEquals ( $expected , $out );
}
2012-05-22 23:30:07 +00:00
}