MediaWiki  1.23.12
SpecialPageTest.php
Go to the documentation of this file.
1 <?php
2 
12 
13  protected function setUp() {
14  parent::setUp();
15 
16  $this->setMwGlobals( array(
17  'wgScript' => '/index.php',
18  'wgContLang' => Language::factory( 'en' )
19  ) );
20  }
21 
25  public function testGetTitleFor( $expectedName, $name ) {
27  $expected = Title::makeTitle( NS_SPECIAL, $expectedName );
28  $this->assertEquals( $expected, $title );
29  }
30 
31  public function getTitleForProvider() {
32  return array(
33  array( 'UserLogin', 'Userlogin' )
34  );
35  }
36 
40  public function testInvalidGetTitleFor() {
42  $expected = Title::makeTitle( NS_SPECIAL, 'Cat' );
43  $this->assertEquals( $expected, $title );
44  }
45 
50  public function testGetTitleForWithWarning( $expected, $name ) {
52  $this->assertEquals( $expected, $title );
53  }
54 
55  public function getTitleForWithWarningProvider() {
56  return array(
57  array( Title::makeTitle( NS_SPECIAL, 'UserLogin' ), 'UserLogin' )
58  );
59  }
60 
64  public function testRequireLoginAnon( $expected, $reason, $title ) {
65  $specialPage = new SpecialPage( 'Watchlist', 'viewmywatchlist' );
66 
67  $user = User::newFromId( 0 );
68  $specialPage->getContext()->setUser( $user );
69  $specialPage->getContext()->setLanguage( Language::factory( 'en' ) );
70 
71  $this->setExpectedException( 'UserNotLoggedIn', $expected );
72 
73  if ( $reason === 'blank' && $title === 'blank' ) {
74  $specialPage->requireLogin();
75  } else {
76  $specialPage->requireLogin( $reason, $title );
77  }
78  }
79 
80  public function requireLoginAnonProvider() {
81  $lang = 'en';
82 
83  $msg = wfMessage( 'loginreqlink' )->inLanguage( $lang )->escaped();
84  $loginLink = '<a href="/index.php?title=Special:UserLogin&amp;returnto=Special%3AWatchlist"'
85  . ' title="Special:UserLogin">' . $msg . '</a>';
86 
87  $expected1 = wfMessage( 'exception-nologin-text-manual' )
88  ->params( $loginLink )->inLanguage( $lang )->text();
89 
90  $expected2 = wfMessage( 'about' )->inLanguage( $lang )->text();
91 
92  return array(
93  array( $expected1, null, null ),
94  array( $expected2, 'about', null ),
95  array( $expected2, wfMessage( 'about' ), null ),
96  array( $expected2, 'about', 'about' ),
97  array( $expected2, 'about', wfMessage( 'about' ) ),
98  array( $expected1, 'blank', 'blank' )
99  );
100  }
101 
102  public function testRequireLoginNotAnon() {
103  $specialPage = new SpecialPage( 'Watchlist', 'viewmywatchlist' );
104 
105  $user = User::newFromName( "UTSysop" );
106  $specialPage->getContext()->setUser( $user );
107 
108  $specialPage->requireLogin();
109 
110  // no exception thrown, logged in use can access special page
111  $this->assertTrue( true );
112  }
113 
114 }
SpecialPageTest\getTitleForProvider
getTitleForProvider()
Definition: SpecialPageTest.php:31
Title\makeTitle
static & makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:398
User\newFromId
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition: User.php:412
SpecialPageTest\testInvalidGetTitleFor
testInvalidGetTitleFor()
@expectedException PHPUnit_Framework_Error_Notice
Definition: SpecialPageTest.php:40
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:389
SpecialPage\getTitleFor
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name.
Definition: SpecialPage.php:74
NS_SPECIAL
const NS_SPECIAL
Definition: Defines.php:68
SpecialPageTest\requireLoginAnonProvider
requireLoginAnonProvider()
Definition: SpecialPageTest.php:80
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Definition: MediaWikiTestCase.php:302
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
SpecialPageTest\getTitleForWithWarningProvider
getTitleForWithWarningProvider()
Definition: SpecialPageTest.php:55
SpecialPageTest\testGetTitleFor
testGetTitleFor( $expectedName, $name)
@dataProvider getTitleForProvider
Definition: SpecialPageTest.php:25
wfMessage
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form externallinks including delete and has completed for all link tables default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt
SpecialPageTest\setUp
setUp()
Definition: SpecialPageTest.php:13
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
SpecialPageTest
@covers SpecialPage
Definition: SpecialPageTest.php:11
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
SpecialPageTest\testRequireLoginAnon
testRequireLoginAnon( $expected, $reason, $title)
@dataProvider requireLoginAnonProvider
Definition: SpecialPageTest.php:64
SpecialPage
Parent class for all special pages.
Definition: SpecialPage.php:33
SpecialPageTest\testGetTitleForWithWarning
testGetTitleForWithWarning( $expected, $name)
@expectedException PHPUnit_Framework_Error_Notice @dataProvider getTitleForWithWarningProvider
Definition: SpecialPageTest.php:50
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:237
Language\factory
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:184
SpecialPageTest\testRequireLoginNotAnon
testRequireLoginNotAnon()
Definition: SpecialPageTest.php:102