9 * @author Katie Filbert < aude.wiki@gmail.com >
11 class SpecialPageTest
extends MediaWikiTestCase
{
13 protected function setUp() {
16 $this->setMwGlobals( array(
17 'wgScript' => '/index.php',
18 'wgContLang' => Language
::factory( 'en' )
23 * @dataProvider getTitleForProvider
25 public function testGetTitleFor( $expectedName, $name ) {
26 $title = SpecialPage
::getTitleFor( $name );
27 $expected = Title
::makeTitle( NS_SPECIAL
, $expectedName );
28 $this->assertEquals( $expected, $title );
31 public function getTitleForProvider() {
33 array( 'UserLogin', 'Userlogin' )
38 * @expectedException PHPUnit_Framework_Error_Notice
40 public function testInvalidGetTitleFor() {
41 $title = SpecialPage
::getTitleFor( 'cat' );
42 $expected = Title
::makeTitle( NS_SPECIAL
, 'Cat' );
43 $this->assertEquals( $expected, $title );
47 * @expectedException PHPUnit_Framework_Error_Notice
48 * @dataProvider getTitleForWithWarningProvider
50 public function testGetTitleForWithWarning( $expected, $name ) {
51 $title = SpecialPage
::getTitleFor( $name );
52 $this->assertEquals( $expected, $title );
55 public function getTitleForWithWarningProvider() {
57 array( Title
::makeTitle( NS_SPECIAL
, 'UserLogin' ), 'UserLogin' )
62 * @dataProvider requireLoginAnonProvider
64 public function testRequireLoginAnon( $expected, $reason, $title ) {
65 $specialPage = new SpecialPage( 'Watchlist', 'viewmywatchlist' );
67 $user = User
::newFromId( 0 );
68 $specialPage->getContext()->setUser( $user );
69 $specialPage->getContext()->setLanguage( Language
::factory( 'en' ) );
71 $this->setExpectedException( 'UserNotLoggedIn', $expected );
73 if ( $reason === 'blank' && $title === 'blank' ) {
74 $specialPage->requireLogin();
76 $specialPage->requireLogin( $reason, $title );
80 public function requireLoginAnonProvider() {
83 $msg = wfMessage( 'loginreqlink' )->inLanguage( $lang )->escaped();
84 $loginLink = '<a href="/index.php?title=Special:UserLogin&returnto=Special%3AWatchlist"'
85 . ' title="Special:UserLogin">' . $msg . '</a>';
87 $expected1 = wfMessage( 'exception-nologin-text-manual' )
88 ->params( $loginLink )->inLanguage( $lang )->text();
90 $expected2 = wfMessage( 'about' )->inLanguage( $lang )->text();
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' )
102 public function testRequireLoginNotAnon() {
103 $specialPage = new SpecialPage( 'Watchlist', 'viewmywatchlist' );
105 $user = User
::newFromName( "UTSysop" );
106 $specialPage->getContext()->setUser( $user );
108 $specialPage->requireLogin();
110 // no exception thrown, logged in use can access special page
111 $this->assertTrue( true );