MediaWiki  REL1_24
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         // $specialPage->requireLogin( [ $reason [, $title ] ] )
00074         call_user_func_array(
00075             array( $specialPage, 'requireLogin' ),
00076             array_filter( array( $reason, $title ) )
00077         );
00078     }
00079 
00080     public function requireLoginAnonProvider() {
00081         $lang = 'en';
00082 
00083         $expected1 = wfMessage( 'exception-nologin-text' )->inLanguage( $lang )->text();
00084         $expected2 = wfMessage( 'about' )->inLanguage( $lang )->text();
00085 
00086         return array(
00087             array( $expected1, null, null ),
00088             array( $expected2, 'about', null ),
00089             array( $expected2, 'about', 'about' ),
00090         );
00091     }
00092 
00093     public function testRequireLoginNotAnon() {
00094         $specialPage = new SpecialPage( 'Watchlist', 'viewmywatchlist' );
00095 
00096         $user = User::newFromName( "UTSysop" );
00097         $specialPage->getContext()->setUser( $user );
00098 
00099         $specialPage->requireLogin();
00100 
00101         // no exception thrown, logged in use can access special page
00102         $this->assertTrue( true );
00103     }
00104 
00105 }