MediaWiki  REL1_23
SpecialPageTest.php
Go to the documentation of this file.
00001 <?php
00002 
00011 class SpecialPageTest extends MediaWikiTestCase {
00012 
00013     protected function setUp() {
00014         parent::setUp();
00015 
00016         $this->setMwGlobals( array(
00017             'wgScript' => '/index.php',
00018             'wgContLang' => Language::factory( 'en' )
00019         ) );
00020     }
00021 
00025     public function testGetTitleFor( $expectedName, $name ) {
00026         $title = SpecialPage::getTitleFor( $name );
00027         $expected = Title::makeTitle( NS_SPECIAL, $expectedName );
00028         $this->assertEquals( $expected, $title );
00029     }
00030 
00031     public function getTitleForProvider() {
00032         return array(
00033             array( 'UserLogin', 'Userlogin' )
00034         );
00035     }
00036 
00040     public function testInvalidGetTitleFor() {
00041         $title = SpecialPage::getTitleFor( 'cat' );
00042         $expected = Title::makeTitle( NS_SPECIAL, 'Cat' );
00043         $this->assertEquals( $expected, $title );
00044     }
00045 
00050     public function testGetTitleForWithWarning( $expected, $name ) {
00051         $title = SpecialPage::getTitleFor( $name );
00052         $this->assertEquals( $expected, $title );
00053     }
00054 
00055     public function getTitleForWithWarningProvider() {
00056         return array(
00057             array( Title::makeTitle( NS_SPECIAL, 'UserLogin' ), 'UserLogin' )
00058         );
00059     }
00060 
00064     public function testRequireLoginAnon( $expected, $reason, $title ) {
00065         $specialPage = new SpecialPage( 'Watchlist', 'viewmywatchlist' );
00066 
00067         $user = User::newFromId( 0 );
00068         $specialPage->getContext()->setUser( $user );
00069         $specialPage->getContext()->setLanguage( Language::factory( 'en' ) );
00070 
00071         $this->setExpectedException( 'UserNotLoggedIn', $expected );
00072 
00073         if ( $reason === 'blank' && $title === 'blank' ) {
00074             $specialPage->requireLogin();
00075         } else {
00076             $specialPage->requireLogin( $reason, $title );
00077         }
00078     }
00079 
00080     public function requireLoginAnonProvider() {
00081         $lang = 'en';
00082 
00083         $msg = wfMessage( 'loginreqlink' )->inLanguage( $lang )->escaped();
00084         $loginLink = '<a href="/index.php?title=Special:UserLogin&amp;returnto=Special%3AWatchlist"'
00085             . ' title="Special:UserLogin">' . $msg . '</a>';
00086 
00087         $expected1 = wfMessage( 'exception-nologin-text-manual' )
00088             ->params( $loginLink )->inLanguage( $lang )->text();
00089 
00090         $expected2 = wfMessage( 'about' )->inLanguage( $lang )->text();
00091 
00092         return array(
00093             array( $expected1, null, null ),
00094             array( $expected2, 'about', null ),
00095             array( $expected2, wfMessage( 'about' ), null ),
00096             array( $expected2, 'about', 'about' ),
00097             array( $expected2, 'about', wfMessage( 'about' ) ),
00098             array( $expected1, 'blank', 'blank' )
00099         );
00100     }
00101 
00102     public function testRequireLoginNotAnon() {
00103         $specialPage = new SpecialPage( 'Watchlist', 'viewmywatchlist' );
00104 
00105         $user = User::newFromName( "UTSysop" );
00106         $specialPage->getContext()->setUser( $user );
00107 
00108         $specialPage->requireLogin();
00109 
00110         // no exception thrown, logged in use can access special page
00111         $this->assertTrue( true );
00112     }
00113 
00114 }