Merge "DatabaseMssql: Don't duplicate body of makeList()"
[mediawiki.git] / tests / phpunit / includes / specialpage / SpecialPageTest.php
blob245cdffdd413d7d9d2aa10fee221a07ce7151424
1 <?php
3 /**
4 * @covers SpecialPage
6 * @group Database
8 * @licence GNU GPL v2+
9 * @author Katie Filbert < aude.wiki@gmail.com >
11 class SpecialPageTest extends MediaWikiTestCase {
13 protected function setUp() {
14 parent::setUp();
16 $this->setMwGlobals( array(
17 'wgScript' => '/index.php',
18 'wgContLang' => Language::factory( 'en' )
19 ) );
22 /**
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() {
32 return array(
33 array( 'UserLogin', 'Userlogin' )
37 /**
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 );
46 /**
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() {
56 return array(
57 array( Title::makeTitle( NS_SPECIAL, 'UserLogin' ), 'UserLogin' )
61 /**
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 // $specialPage->requireLogin( [ $reason [, $title ] ] )
74 call_user_func_array(
75 array( $specialPage, 'requireLogin' ),
76 array_filter( array( $reason, $title ) )
80 public function requireLoginAnonProvider() {
81 $lang = 'en';
83 $expected1 = wfMessage( 'exception-nologin-text' )->inLanguage( $lang )->text();
84 $expected2 = wfMessage( 'about' )->inLanguage( $lang )->text();
86 return array(
87 array( $expected1, null, null ),
88 array( $expected2, 'about', null ),
89 array( $expected2, 'about', 'about' ),
93 public function testRequireLoginNotAnon() {
94 $specialPage = new SpecialPage( 'Watchlist', 'viewmywatchlist' );
96 $user = User::newFromName( "UTSysop" );
97 $specialPage->getContext()->setUser( $user );
99 $specialPage->requireLogin();
101 // no exception thrown, logged in use can access special page
102 $this->assertTrue( true );