Merge "Provide direction hinting in the personal toolbar"
[lhc/web/wiklou.git] / tests / phpunit / includes / SpecialPageTest.php
1 <?php
2
3 /**
4 * @covers SpecialPage
5 *
6 * @group Database
7 *
8 * @licence GNU GPL v2+
9 * @author Katie Filbert < aude.wiki@gmail.com >
10 */
11 class SpecialPageTest extends MediaWikiTestCase {
12
13 protected function setUp() {
14 parent::setUp();
15
16 $this->setMwGlobals( array(
17 'wgScript' => '/index.php',
18 'wgContLang' => Language::factory( 'en' )
19 ) );
20 }
21
22 /**
23 * @dataProvider getTitleForProvider
24 */
25 public function testGetTitleFor( $expectedName, $name ) {
26 $title = SpecialPage::getTitleFor( $name );
27 $expected = Title::makeTitle( NS_SPECIAL, $expectedName );
28 $this->assertEquals( $expected, $title );
29 }
30
31 public function getTitleForProvider() {
32 return array(
33 array( 'UserLogin', 'Userlogin' )
34 );
35 }
36
37 /**
38 * @expectedException PHPUnit_Framework_Error_Notice
39 */
40 public function testInvalidGetTitleFor() {
41 $title = SpecialPage::getTitleFor( 'cat' );
42 $expected = Title::makeTitle( NS_SPECIAL, 'Cat' );
43 $this->assertEquals( $expected, $title );
44 }
45
46 /**
47 * @expectedException PHPUnit_Framework_Error_Notice
48 * @dataProvider getTitleForWithWarningProvider
49 */
50 public function testGetTitleForWithWarning( $expected, $name ) {
51 $title = SpecialPage::getTitleFor( $name );
52 $this->assertEquals( $expected, $title );
53 }
54
55 public function getTitleForWithWarningProvider() {
56 return array(
57 array( Title::makeTitle( NS_SPECIAL, 'UserLogin' ), 'UserLogin' )
58 );
59 }
60
61 /**
62 * @dataProvider requireLoginAnonProvider
63 */
64 public function testRequireLoginAnon( $expected, $reason, $title ) {
65 $specialPage = new SpecialPage( 'Watchlist', 'viewmywatchlist' );
66
67 $user = User::newFromId( 0 );
68 $specialPage->getContext()->setUser( $user );
69 $specialPage->getContext()->setLanguage( Language::factory( 'en' ) );
70
71 $this->setExpectedException( 'UserNotLoggedIn', $expected );
72
73 if ( $reason === 'blank' && $title === 'blank' ) {
74 $specialPage->requireLogin();
75 } else {
76 $specialPage->requireLogin( $reason, $title );
77 }
78 }
79
80 public function requireLoginAnonProvider() {
81 $lang = 'en';
82
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>';
86
87 $expected1 = wfMessage( 'exception-nologin-text-manual' )
88 ->params( $loginLink )->inLanguage( $lang )->text();
89
90 $expected2 = wfMessage( 'about' )->inLanguage( $lang )->text();
91
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' )
99 );
100 }
101
102 public function testRequireLoginNotAnon() {
103 $specialPage = new SpecialPage( 'Watchlist', 'viewmywatchlist' );
104
105 $user = User::newFromName( "UTSysop" );
106 $specialPage->getContext()->setUser( $user );
107
108 $specialPage->requireLogin();
109
110 // no exception thrown, logged in use can access special page
111 $this->assertTrue( true );
112 }
113
114 }