MediaWiki REL1_33
SpecialPageTest.php
Go to the documentation of this file.
1<?php
2
4
13
14 protected function setUp() {
15 parent::setUp();
16
17 $this->setContentLang( 'en' );
18 $this->setMwGlobals( [
19 'wgScript' => '/index.php',
20 ] );
21 }
22
26 public function testGetTitleFor( $expectedName, $name ) {
27 $title = SpecialPage::getTitleFor( $name );
28 $expected = Title::makeTitle( NS_SPECIAL, $expectedName );
29 $this->assertEquals( $expected, $title );
30 }
31
32 public function getTitleForProvider() {
33 return [
34 [ 'UserLogin', 'Userlogin' ]
35 ];
36 }
37
41 public function testInvalidGetTitleFor() {
42 $title = SpecialPage::getTitleFor( 'cat' );
43 $expected = Title::makeTitle( NS_SPECIAL, 'Cat' );
44 $this->assertEquals( $expected, $title );
45 }
46
51 public function testGetTitleForWithWarning( $expected, $name ) {
52 $title = SpecialPage::getTitleFor( $name );
53 $this->assertEquals( $expected, $title );
54 }
55
57 return [
58 [ Title::makeTitle( NS_SPECIAL, 'UserLogin' ), 'UserLogin' ]
59 ];
60 }
61
65 public function testRequireLoginAnon( $expected, $reason, $title ) {
66 $specialPage = new SpecialPage( 'Watchlist', 'viewmywatchlist' );
67
68 $user = User::newFromId( 0 );
69 $specialPage->getContext()->setUser( $user );
70 $specialPage->getContext()->setLanguage( Language::factory( 'en' ) );
71
72 $this->setExpectedException( UserNotLoggedIn::class, $expected );
73
74 // $specialPage->requireLogin( [ $reason [, $title ] ] )
76 [ $specialPage, 'requireLogin' ],
77 array_filter( [ $reason, $title ] )
78 );
79 }
80
81 public function requireLoginAnonProvider() {
82 $lang = 'en';
83
84 $expected1 = wfMessage( 'exception-nologin-text' )->inLanguage( $lang )->text();
85 $expected2 = wfMessage( 'about' )->inLanguage( $lang )->text();
86
87 return [
88 [ $expected1, null, null ],
89 [ $expected2, 'about', null ],
90 [ $expected2, 'about', 'about' ],
91 ];
92 }
93
94 public function testRequireLoginNotAnon() {
95 $specialPage = new SpecialPage( 'Watchlist', 'viewmywatchlist' );
96
97 $user = User::newFromName( "UTSysop" );
98 $specialPage->getContext()->setUser( $user );
99
100 $specialPage->requireLogin();
101
102 // no exception thrown, logged in use can access special page
103 $this->assertTrue( true );
104 }
105
107 yield [ 0, 20, false, false ];
108 yield [ 17, 20, false, false ];
109 yield [ 0, 17, false, false ];
110 yield [ 0, 20, true, 'Foo' ];
111 yield [ 17, 20, true, 'Föö_Bär' ];
112 }
113
117 public function testBuildPrevNextNavigation( $offset, $limit, $atEnd, $subPage ) {
118 $this->setUserLang( Language::factory( 'qqx' ) ); // disable i18n
119
120 $specialPage = new SpecialPage( 'Watchlist' );
121 $specialPage = TestingAccessWrapper::newFromObject( $specialPage );
122
123 $html = $specialPage->buildPrevNextNavigation(
124 $offset,
125 $limit,
126 [ 'x' => 25 ],
127 $atEnd,
128 $subPage
129 );
130
131 $this->assertStringStartsWith( '(viewprevnext:', $html );
132
133 preg_match_all( '!<a.*?</a>!', $html, $m, PREG_PATTERN_ORDER );
134 $links = $m[0];
135
136 foreach ( $links as $a ) {
137 if ( $subPage ) {
138 $this->assertContains( 'Special:Watchlist/' . wfUrlencode( $subPage ), $a );
139 } else {
140 $this->assertContains( 'Special:Watchlist', $a );
141 $this->assertNotContains( 'Special:Watchlist/', $a );
142 }
143 $this->assertContains( 'x=25', $a );
144 }
145
146 $i = 0;
147
148 if ( $offset > 0 ) {
149 $this->assertContains(
150 'limit=' . $limit . '&amp;offset=' . max( 0, $offset - $limit ) . '&amp;',
151 $links[ $i ]
152 );
153 $this->assertContains( 'title="(prevn-title: ' . $limit . ')"', $links[$i] );
154 $this->assertContains( 'class="mw-prevlink"', $links[$i] );
155 $this->assertContains( '>(prevn: ' . $limit . ')<', $links[$i] );
156 $i += 1;
157 }
158
159 if ( !$atEnd ) {
160 $this->assertContains(
161 'limit=' . $limit . '&amp;offset=' . ( $offset + $limit ) . '&amp;',
162 $links[ $i ]
163 );
164 $this->assertContains( 'title="(nextn-title: ' . $limit . ')"', $links[$i] );
165 $this->assertContains( 'class="mw-nextlink"', $links[$i] );
166 $this->assertContains( '>(nextn: ' . $limit . ')<', $links[$i] );
167 $i += 1;
168 }
169
170 $this->assertCount( 5 + $i, $links );
171
172 $this->assertContains( 'limit=20&amp;offset=' . $offset, $links[$i] );
173 $this->assertContains( 'title="(shown-title: 20)"', $links[$i] );
174 $this->assertContains( 'class="mw-numlink"', $links[$i] );
175 $this->assertContains( '>20<', $links[$i] );
176 $i += 4;
177
178 $this->assertContains( 'limit=500&amp;offset=' . $offset, $links[$i] );
179 $this->assertContains( 'title="(shown-title: 500)"', $links[$i] );
180 $this->assertContains( 'class="mw-numlink"', $links[$i] );
181 $this->assertContains( '>500<', $links[$i] );
182 }
183
184}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
testBuildPrevNextNavigation( $offset, $limit, $atEnd, $subPage)
provideBuildPrevNextNavigation
testInvalidGetTitleFor()
PHPUnit_Framework_Error_Notice.
testGetTitleForWithWarning( $expected, $name)
PHPUnit_Framework_Error_Notice getTitleForWithWarningProvider.
testGetTitleFor( $expectedName, $name)
getTitleForProvider
testRequireLoginAnon( $expected, $reason, $title)
requireLoginAnonProvider
Parent class for all special pages.
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition User.php:585
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition User.php:609
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition hooks.txt:783
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt;div ...>$1&lt;/div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition hooks.txt:2011
processing should stop and the error should be shown to the user * false
Definition hooks.txt:187
const NS_SPECIAL
Definition Defines.php:62
if(!isset( $args[0])) $lang