Remove messages.inc, rebuildLanguage.php, writeMessagesArray.inc
[mediawiki.git] / tests / phpunit / includes / SpecialPageTest.php
blob0ee335a6095da52612ed57d651b7d18b9ddb00e8
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 if ( $reason === 'blank' && $title === 'blank' ) {
74 $specialPage->requireLogin();
75 } else {
76 $specialPage->requireLogin( $reason, $title );
80 public function requireLoginAnonProvider() {
81 $lang = 'en';
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>';
87 $expected1 = wfMessage( 'exception-nologin-text-manual' )
88 ->params( $loginLink )->inLanguage( $lang )->text();
90 $expected2 = wfMessage( 'about' )->inLanguage( $lang )->text();
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' )
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 );