r79377 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79376‎ | r79377 | r79378 >
Date:22:08, 31 December 2010
Author:soxred93
Status:resolved (Comments)
Tags:
Comment:
Solve 1 test by changing static variables to non-static
Modified paths:
  • /trunk/phase3/tests/phpunit/includes/TitlePermissionTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/TitlePermissionTest.php
@@ -2,16 +2,15 @@
33
44 /**
55 * @group Database
6 - * @group Destructive
76 */
87 class TitlePermissionTest extends MediaWikiTestCase {
9 - static $title;
10 - static $user;
11 - static $anonUser;
12 - static $userUser;
13 - static $altUser;
14 - static $userName;
15 - static $altUserName;
 8+ protected $title;
 9+ protected $user;
 10+ protected $anonUser;
 11+ protected $userUser;
 12+ protected $altUser;
 13+ protected $userName;
 14+ protected $altUserName;
1615
1716 function setUp() {
1817 global $wgLocaltimezone, $wgLocalTZoffset, $wgMemc, $wgContLang, $wgLang, $wgMessageCache;
@@ -22,57 +21,59 @@
2322 $wgMessageCache = new MessageCache( $wgMemc, true, 3600 );
2423 $wgContLang = $wgLang = Language::factory( 'en' );
2524
26 - self::$userName = "Useruser";
27 - self::$altUserName = "Altuseruser";
 25+ $this->userName = "Useruser";
 26+ $this->altUserName = "Altuseruser";
2827 date_default_timezone_set( $wgLocaltimezone );
2928 $wgLocalTZoffset = date( "Z" ) / 60;
3029
31 - self::$title = Title::makeTitle( NS_MAIN, "Main Page" );
32 - if ( !isset( self::$userUser ) || !( self::$userUser instanceOf User ) ) {
33 - self::$userUser = User::newFromName( self::$userName );
34 -
35 - if ( !self::$userUser->getID() ) {
36 - self::$userUser = User::createNew( self::$userName, array(
 30+ $this->title = Title::makeTitle( NS_MAIN, "Main Page" );
 31+ if ( !isset( $this->userUser ) || !( $this->userUser instanceOf User ) ) {
 32+ $this->userUser = User::newFromName( $this->userName );
 33+
 34+ if ( !$this->userUser->getID() ) {
 35+ $this->userUser = User::createNew( $this->userName, array(
3736 "email" => "test@example.com",
3837 "real_name" => "Test User" ) );
 38+ $this->userUser->load();
3939 }
40 -
41 - self::$altUser = User::newFromName( self::$altUserName );
42 - if ( !self::$altUser->getID() ) {
43 - self::$altUser = User::createNew( self::$altUserName, array(
 40+
 41+ $this->altUser = User::newFromName( $this->altUserName );
 42+ if ( !$this->altUser->getID() ) {
 43+ $this->altUser = User::createNew( $this->altUserName, array(
4444 "email" => "alttest@example.com",
4545 "real_name" => "Test User Alt" ) );
 46+ $this->altUser->load();
4647 }
4748
48 - self::$anonUser = User::newFromId( 0 );
 49+ $this->anonUser = User::newFromId( 0 );
4950
50 - self::$user = self::$userUser;
 51+ $this->user = $this->userUser;
5152 }
5253 }
5354
5455 function setUserPerm( $perm ) {
5556 if ( is_array( $perm ) ) {
56 - self::$user->mRights = $perm;
 57+ $this->user->mRights = $perm;
5758 } else {
58 - self::$user->mRights = array( $perm );
 59+ $this->user->mRights = array( $perm );
5960 }
6061 }
6162
6263 function setTitle( $ns, $title = "Main_Page" ) {
63 - self::$title = Title::makeTitle( $ns, $title );
 64+ $this->title = Title::makeTitle( $ns, $title );
6465 }
6566
6667 function setUser( $userName = null ) {
6768 if ( $userName === 'anon' ) {
68 - self::$user = self::$anonUser;
69 - } else if ( $userName === null || $userName === self::$userName ) {
70 - self::$user = self::$userUser;
 69+ $this->user = $this->anonUser;
 70+ } else if ( $userName === null || $userName === $this->userName ) {
 71+ $this->user = $this->userUser;
7172 } else {
72 - self::$user = self::$altUser;
 73+ $this->user = $this->altUser;
7374 }
7475
7576 global $wgUser;
76 - $wgUser = self::$user;
 77+ $wgUser = $this->user;
7778 }
7879
7980 function testQuickPermissions() {
@@ -82,124 +83,124 @@
8384 $this->setUser( 'anon' );
8485 $this->setTitle( NS_TALK );
8586 $this->setUserPerm( "createtalk" );
86 - $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
 87+ $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
8788 $this->assertEquals( array(), $res );
8889
8990 $this->setTitle( NS_TALK );
9091 $this->setUserPerm( "createpage" );
91 - $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
 92+ $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
9293 $this->assertEquals( array( array( "nocreatetext" ) ), $res );
9394
9495 $this->setTitle( NS_TALK );
9596 $this->setUserPerm( "" );
96 - $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
 97+ $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
9798 $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
9899
99100 $this->setTitle( NS_MAIN );
100101 $this->setUserPerm( "createpage" );
101 - $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
 102+ $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
102103 $this->assertEquals( array( ), $res );
103104
104105 $this->setTitle( NS_MAIN );
105106 $this->setUserPerm( "createtalk" );
106 - $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
 107+ $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
107108 $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
108109
109 - $this->setUser( self::$userName );
 110+ $this->setUser( $this->userName );
110111 $this->setTitle( NS_TALK );
111112 $this->setUserPerm( "createtalk" );
112 - $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
 113+ $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
113114 $this->assertEquals( array( ), $res );
114115
115116 $this->setTitle( NS_TALK );
116117 $this->setUserPerm( "createpage" );
117 - $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
 118+ $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
118119 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
119120
120121 $this->setTitle( NS_TALK );
121122 $this->setUserPerm( "" );
122 - $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
 123+ $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
123124 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
124125
125126 $this->setTitle( NS_MAIN );
126127 $this->setUserPerm( "createpage" );
127 - $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
 128+ $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
128129 $this->assertEquals( array( ), $res );
129130
130131 $this->setTitle( NS_MAIN );
131132 $this->setUserPerm( "createtalk" );
132 - $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
 133+ $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
133134 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
134135
135136 $this->setTitle( NS_MAIN );
136137 $this->setUserPerm( "" );
137 - $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
 138+ $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
138139 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
139140
140141 $this->setUser( 'anon' );
141 - $this->setTitle( NS_USER, self::$userName . '' );
 142+ $this->setTitle( NS_USER, $this->userName . '' );
142143 $this->setUserPerm( "" );
143 - $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
 144+ $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
144145 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
145146
146 - $this->setTitle( NS_USER, self::$userName . '/subpage' );
 147+ $this->setTitle( NS_USER, $this->userName . '/subpage' );
147148 $this->setUserPerm( "" );
148 - $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
 149+ $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
149150 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
150151
151 - $this->setTitle( NS_USER, self::$userName . '' );
 152+ $this->setTitle( NS_USER, $this->userName . '' );
152153 $this->setUserPerm( "move-rootuserpages" );
153 - $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
 154+ $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
154155 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
155156
156 - $this->setTitle( NS_USER, self::$userName . '/subpage' );
 157+ $this->setTitle( NS_USER, $this->userName . '/subpage' );
157158 $this->setUserPerm( "move-rootuserpages" );
158 - $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
 159+ $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
159160 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
160161
161 - $this->setTitle( NS_USER, self::$userName . '' );
 162+ $this->setTitle( NS_USER, $this->userName . '' );
162163 $this->setUserPerm( "" );
163 - $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
 164+ $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
164165 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
165166
166 - $this->setTitle( NS_USER, self::$userName . '/subpage' );
 167+ $this->setTitle( NS_USER, $this->userName . '/subpage' );
167168 $this->setUserPerm( "" );
168 - $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
 169+ $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
169170 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
170171
171 - $this->setTitle( NS_USER, self::$userName . '' );
 172+ $this->setTitle( NS_USER, $this->userName . '' );
172173 $this->setUserPerm( "move-rootuserpages" );
173 - $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
 174+ $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
174175 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
175176
176 - $this->setTitle( NS_USER, self::$userName . '/subpage' );
 177+ $this->setTitle( NS_USER, $this->userName . '/subpage' );
177178 $this->setUserPerm( "move-rootuserpages" );
178 - $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
 179+ $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
179180 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
180181
181 - $this->setUser( self::$userName );
 182+ $this->setUser( $this->userName );
182183 $this->setTitle( NS_FILE, "img.png" );
183184 $this->setUserPerm( "" );
184 - $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
 185+ $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
185186 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ), $res );
186187
187188 $this->setTitle( NS_FILE, "img.png" );
188189 $this->setUserPerm( "movefile" );
189 - $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
 190+ $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
190191 $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
191192
192193 $this->setUser( 'anon' );
193194 $this->setTitle( NS_FILE, "img.png" );
194195 $this->setUserPerm( "" );
195 - $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
 196+ $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
196197 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ), $res );
197198
198199 $this->setTitle( NS_FILE, "img.png" );
199200 $this->setUserPerm( "movefile" );
200 - $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
 201+ $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
201202 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
202203
203 - $this->setUser( self::$userName );
 204+ $this->setUser( $this->userName );
204205 $this->setUserPerm( "move" );
205206 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
206207
@@ -223,7 +224,7 @@
224225 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ),
225226 array( array( 'movenologintext' ) ) );
226227
227 - $this->setUser( self::$userName );
 228+ $this->setUser( $this->userName );
228229 $this->setUserPerm( "" );
229230 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ) );
230231
@@ -232,35 +233,35 @@
233234
234235 $this->setUser( 'anon' );
235236 $this->setUserPerm( 'move' );
236 - $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user );
 237+ $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
237238 $this->assertEquals( array( ), $res );
238239
239240 $this->setUserPerm( '' );
240 - $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user );
 241+ $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
241242 $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
242243
243244 $this->setTitle( NS_USER );
244 - $this->setUser( self::$userName );
 245+ $this->setUser( $this->userName );
245246 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
246 - $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user );
 247+ $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
247248 $this->assertEquals( array( ), $res );
248249
249250 $this->setUserPerm( "move" );
250 - $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user );
 251+ $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
251252 $this->assertEquals( array( array( 'cant-move-to-user-page' ) ), $res );
252253
253254 $this->setUser( 'anon' );
254255 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
255 - $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user );
 256+ $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
256257 $this->assertEquals( array( ), $res );
257258
258259 $this->setTitle( NS_USER, "User/subpage" );
259260 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
260 - $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user );
 261+ $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
261262 $this->assertEquals( array( ), $res );
262263
263264 $this->setUserPerm( "move" );
264 - $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user );
 265+ $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
265266 $this->assertEquals( array( ), $res );
266267
267268 $this->setUser( 'anon' );
@@ -272,29 +273,29 @@
273274 array( array( 'protect-cantedit' ) ), false ),
274275 '' => array( array( ), array( ), array( ), true ) );
275276 global $wgUser;
276 - $wgUser = self::$user;
 277+ $wgUser = $this->user;
277278 foreach ( array( "edit", "protect", "" ) as $action ) {
278279 $this->setUserPerm( null );
279280 $this->assertEquals( $check[$action][0],
280 - self::$title->getUserPermissionsErrors( $action, self::$user, true ) );
 281+ $this->title->getUserPermissionsErrors( $action, $this->user, true ) );
281282
282283 global $wgGroupPermissions;
283284 $old = $wgGroupPermissions;
284285 $wgGroupPermissions = array();
285286
286287 $this->assertEquals( $check[$action][1],
287 - self::$title->getUserPermissionsErrors( $action, self::$user, true ) );
 288+ $this->title->getUserPermissionsErrors( $action, $this->user, true ) );
288289 $wgGroupPermissions = $old;
289290
290291 $this->setUserPerm( $action );
291292 $this->assertEquals( $check[$action][2],
292 - self::$title->getUserPermissionsErrors( $action, self::$user, true ) );
 293+ $this->title->getUserPermissionsErrors( $action, $this->user, true ) );
293294
294295 $this->setUserPerm( $action );
295296 $this->assertEquals( $check[$action][3],
296 - self::$title->userCan( $action, true ) );
 297+ $this->title->userCan( $action, true ) );
297298 $this->assertEquals( $check[$action][3],
298 - self::$title->quickUserCan( $action, false ) );
 299+ $this->title->quickUserCan( $action, false ) );
299300
300301 # count( User::getGroupsWithPermissions( $action ) ) < 1
301302 }
@@ -307,100 +308,100 @@
308309
309310 $wgGroupPermissions['autoconfirmed']['move'] = false;
310311 $wgGroupPermissions['user']['move'] = false;
311 - $res = self::$title->getUserPermissionsErrors( $action, self::$user );
 312+ $res = $this->title->getUserPermissionsErrors( $action, $this->user );
312313 $this->assertEquals( $result, $res );
313314
314315 $wgGroupPermissions['autoconfirmed']['move'] = true;
315316 $wgGroupPermissions['user']['move'] = false;
316 - $res = self::$title->getUserPermissionsErrors( $action, self::$user );
 317+ $res = $this->title->getUserPermissionsErrors( $action, $this->user );
317318 $this->assertEquals( $result2, $res );
318319
319320 $wgGroupPermissions['autoconfirmed']['move'] = true;
320321 $wgGroupPermissions['user']['move'] = true;
321 - $res = self::$title->getUserPermissionsErrors( $action, self::$user );
 322+ $res = $this->title->getUserPermissionsErrors( $action, $this->user );
322323 $this->assertEquals( $result2, $res );
323324
324325 $wgGroupPermissions['autoconfirmed']['move'] = false;
325326 $wgGroupPermissions['user']['move'] = true;
326 - $res = self::$title->getUserPermissionsErrors( $action, self::$user );
 327+ $res = $this->title->getUserPermissionsErrors( $action, $this->user );
327328 $this->assertEquals( $result2, $res );
328329 }
329330
330331 function testPermissionHooks() { }
331332 function testSpecialsAndNSPermissions() {
332 - $this->setUser( self::$userName );
 333+ $this->setUser( $this->userName );
333334 global $wgUser, $wgContLang;
334 - $wgUser = self::$user;
 335+ $wgUser = $this->user;
335336 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT );
336337
337338 $this->setTitle( NS_SPECIAL );
338 -
 339+
339340 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'ns-specialprotected' ) ),
340 - self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
 341+ $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
341342 $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Administrators|Administrators]]", 2 ) ),
342 - self::$title->getUserPermissionsErrors( 'createaccount', self::$user ) );
 343+ $this->title->getUserPermissionsErrors( 'createaccount', $this->user ) );
343344 $this->assertEquals( array( array( 'badaccess-group0' ) ),
344 - self::$title->getUserPermissionsErrors( 'execute', self::$user ) );
 345+ $this->title->getUserPermissionsErrors( 'execute', $this->user ) );
345346
346347 $this->setTitle( NS_MAIN );
347348 $this->setUserPerm( 'bogus' );
348349 $this->assertEquals( array( ),
349 - self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
 350+ $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
350351
351352 $this->setTitle( NS_MAIN );
352353 $this->setUserPerm( '' );
353354 $this->assertEquals( array( array( 'badaccess-group0' ) ),
354 - self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
 355+ $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
355356
356357 global $wgNamespaceProtection;
357358 $wgNamespaceProtection[NS_USER] = array ( 'bogus' );
358359 $this->setTitle( NS_USER );
359360 $this->setUserPerm( '' );
360361 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'namespaceprotected', 'User' ) ),
361 - self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
 362+ $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
362363
363364 $this->setTitle( NS_MEDIAWIKI );
364365 $this->setUserPerm( 'bogus' );
365366 $this->assertEquals( array( array( 'protectedinterface' ) ),
366 - self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
 367+ $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
367368
368369 $this->setTitle( NS_MEDIAWIKI );
369370 $this->setUserPerm( 'bogus' );
370371 $this->assertEquals( array( array( 'protectedinterface' ) ),
371 - self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
 372+ $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
372373
373374 $wgNamespaceProtection = null;
374375 $this->setUserPerm( 'bogus' );
375376 $this->assertEquals( array( ),
376 - self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
 377+ $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
377378 $this->assertEquals( true,
378 - self::$title->userCan( 'bogus' ) );
 379+ $this->title->userCan( 'bogus' ) );
379380
380381 $this->setUserPerm( '' );
381382 $this->assertEquals( array( array( 'badaccess-group0' ) ),
382 - self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
 383+ $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
383384 $this->assertEquals( false,
384 - self::$title->userCan( 'bogus' ) );
 385+ $this->title->userCan( 'bogus' ) );
385386 }
386387
387388 function testCSSandJSPermissions() {
388 - $this->setUser( self::$userName );
 389+ $this->setUser( $this->userName );
389390 global $wgUser;
390 - $wgUser = self::$user;
 391+ $wgUser = $this->user;
391392
392 - $this->setTitle( NS_USER, self::$altUserName . '/test.js' );
 393+ $this->setTitle( NS_USER, $this->altUserName . '/test.js' );
393394 $this->runCSSandJSPermissions(
394395 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
395396 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
396397 array( array( 'badaccess-group0' ) ) );
397398
398 - $this->setTitle( NS_USER, self::$altUserName . '/test.css' );
 399+ $this->setTitle( NS_USER, $this->altUserName . '/test.css' );
399400 $this->runCSSandJSPermissions(
400401 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
401402 array( array( 'badaccess-group0' ) ),
402403 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ) );
403404
404 - $this->setTitle( NS_USER, self::$altUserName . '/tempo' );
 405+ $this->setTitle( NS_USER, $this->altUserName . '/tempo' );
405406 $this->runCSSandJSPermissions(
406407 array( array( 'badaccess-group0' ) ),
407408 array( array( 'badaccess-group0' ) ),
@@ -410,28 +411,28 @@
411412 function runCSSandJSPermissions( $result0, $result1, $result2 ) {
412413 $this->setUserPerm( '' );
413414 $this->assertEquals( $result0,
414 - self::$title->getUserPermissionsErrors( 'bogus',
415 - self::$user ) );
 415+ $this->title->getUserPermissionsErrors( 'bogus',
 416+ $this->user ) );
416417
417418 $this->setUserPerm( 'editusercss' );
418419 $this->assertEquals( $result1,
419 - self::$title->getUserPermissionsErrors( 'bogus',
420 - self::$user ) );
 420+ $this->title->getUserPermissionsErrors( 'bogus',
 421+ $this->user ) );
421422
422423 $this->setUserPerm( 'edituserjs' );
423424 $this->assertEquals( $result2,
424 - self::$title->getUserPermissionsErrors( 'bogus',
425 - self::$user ) );
 425+ $this->title->getUserPermissionsErrors( 'bogus',
 426+ $this->user ) );
426427
427428 $this->setUserPerm( 'editusercssjs' );
428429 $this->assertEquals( array( array( 'badaccess-group0' ) ),
429 - self::$title->getUserPermissionsErrors( 'bogus',
430 - self::$user ) );
 430+ $this->title->getUserPermissionsErrors( 'bogus',
 431+ $this->user ) );
431432
432433 $this->setUserPerm( array( 'edituserjs', 'editusercss' ) );
433434 $this->assertEquals( array( array( 'badaccess-group0' ) ),
434 - self::$title->getUserPermissionsErrors( 'bogus',
435 - self::$user ) );
 435+ $this->title->getUserPermissionsErrors( 'bogus',
 436+ $this->user ) );
436437 }
437438
438439 function testPageRestrictions() {
@@ -439,162 +440,162 @@
440441
441442 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT );
442443
443 - $wgUser = self::$user;
 444+ $wgUser = $this->user;
444445 $this->setTitle( NS_MAIN );
445 - self::$title->mRestrictionsLoaded = true;
 446+ $this->title->mRestrictionsLoaded = true;
446447 $this->setUserPerm( "edit" );
447 - self::$title->mRestrictions = array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
 448+ $this->title->mRestrictions = array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
448449
449450 $this->assertEquals( array( ),
450 - self::$title->getUserPermissionsErrors( 'edit',
451 - self::$user ) );
 451+ $this->title->getUserPermissionsErrors( 'edit',
 452+ $this->user ) );
452453
453454 $this->assertEquals( true,
454 - self::$title->quickUserCan( 'edit', false ) );
455 - self::$title->mRestrictions = array( "edit" => array( 'bogus', "sysop", "protect", "" ),
 455+ $this->title->quickUserCan( 'edit', false ) );
 456+ $this->title->mRestrictions = array( "edit" => array( 'bogus', "sysop", "protect", "" ),
456457 "bogus" => array( 'bogus', "sysop", "protect", "" ) );
457458
458459 $this->assertEquals( array( array( 'badaccess-group0' ),
459460 array( 'protectedpagetext', 'bogus' ),
460461 array( 'protectedpagetext', 'protect' ),
461462 array( 'protectedpagetext', 'protect' ) ),
462 - self::$title->getUserPermissionsErrors( 'bogus',
463 - self::$user ) );
 463+ $this->title->getUserPermissionsErrors( 'bogus',
 464+ $this->user ) );
464465 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
465466 array( 'protectedpagetext', 'protect' ),
466467 array( 'protectedpagetext', 'protect' ) ),
467 - self::$title->getUserPermissionsErrors( 'edit',
468 - self::$user ) );
 468+ $this->title->getUserPermissionsErrors( 'edit',
 469+ $this->user ) );
469470 $this->setUserPerm( "" );
470471 $this->assertEquals( array( array( 'badaccess-group0' ),
471472 array( 'protectedpagetext', 'bogus' ),
472473 array( 'protectedpagetext', 'protect' ),
473474 array( 'protectedpagetext', 'protect' ) ),
474 - self::$title->getUserPermissionsErrors( 'bogus',
475 - self::$user ) );
 475+ $this->title->getUserPermissionsErrors( 'bogus',
 476+ $this->user ) );
476477 $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ),
477478 array( 'protectedpagetext', 'bogus' ),
478479 array( 'protectedpagetext', 'protect' ),
479480 array( 'protectedpagetext', 'protect' ) ),
480 - self::$title->getUserPermissionsErrors( 'edit',
481 - self::$user ) );
 481+ $this->title->getUserPermissionsErrors( 'edit',
 482+ $this->user ) );
482483 $this->setUserPerm( array( "edit", "editprotected" ) );
483484 $this->assertEquals( array( array( 'badaccess-group0' ),
484485 array( 'protectedpagetext', 'bogus' ),
485486 array( 'protectedpagetext', 'protect' ),
486487 array( 'protectedpagetext', 'protect' ) ),
487 - self::$title->getUserPermissionsErrors( 'bogus',
488 - self::$user ) );
 488+ $this->title->getUserPermissionsErrors( 'bogus',
 489+ $this->user ) );
489490 $this->assertEquals( array( ),
490 - self::$title->getUserPermissionsErrors( 'edit',
491 - self::$user ) );
492 - self::$title->mCascadeRestriction = true;
 491+ $this->title->getUserPermissionsErrors( 'edit',
 492+ $this->user ) );
 493+ $this->title->mCascadeRestriction = true;
493494 $this->assertEquals( false,
494 - self::$title->quickUserCan( 'bogus', false ) );
 495+ $this->title->quickUserCan( 'bogus', false ) );
495496 $this->assertEquals( false,
496 - self::$title->quickUserCan( 'edit', false ) );
 497+ $this->title->quickUserCan( 'edit', false ) );
497498 $this->assertEquals( array( array( 'badaccess-group0' ),
498499 array( 'protectedpagetext', 'bogus' ),
499500 array( 'protectedpagetext', 'protect' ),
500501 array( 'protectedpagetext', 'protect' ) ),
501 - self::$title->getUserPermissionsErrors( 'bogus',
502 - self::$user ) );
 502+ $this->title->getUserPermissionsErrors( 'bogus',
 503+ $this->user ) );
503504 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
504505 array( 'protectedpagetext', 'protect' ),
505506 array( 'protectedpagetext', 'protect' ) ),
506 - self::$title->getUserPermissionsErrors( 'edit',
507 - self::$user ) );
 507+ $this->title->getUserPermissionsErrors( 'edit',
 508+ $this->user ) );
508509 }
509510
510511 function testCascadingSourcesRestrictions() {
511512 global $wgUser;
512 - $wgUser = self::$user;
 513+ $wgUser = $this->user;
513514 $this->setTitle( NS_MAIN, "test page" );
514515 $this->setUserPerm( array( "edit", "bogus" ) );
515516
516 - self::$title->mCascadeSources = array( Title::makeTitle( NS_MAIN, "Bogus" ), Title::makeTitle( NS_MAIN, "UnBogus" ) );
517 - self::$title->mCascadingRestrictions = array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
 517+ $this->title->mCascadeSources = array( Title::makeTitle( NS_MAIN, "Bogus" ), Title::makeTitle( NS_MAIN, "UnBogus" ) );
 518+ $this->title->mCascadingRestrictions = array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
518519
519520 $this->assertEquals( false,
520 - self::$title->userCan( 'bogus' ) );
 521+ $this->title->userCan( 'bogus' ) );
521522 $this->assertEquals( array( array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ),
522523 array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ) ),
523 - self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
 524+ $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
524525
525526 $this->assertEquals( true,
526 - self::$title->userCan( 'edit' ) );
 527+ $this->title->userCan( 'edit' ) );
527528 $this->assertEquals( array( ),
528 - self::$title->getUserPermissionsErrors( 'edit', self::$user ) );
 529+ $this->title->getUserPermissionsErrors( 'edit', $this->user ) );
529530
530531 }
531532
532533 function testActionPermissions() {
533534 global $wgUser;
534 - $wgUser = self::$user;
 535+ $wgUser = $this->user;
535536
536537 $this->setUserPerm( array( "createpage" ) );
537538 $this->setTitle( NS_MAIN, "test page" );
538 - self::$title->mTitleProtection['pt_create_perm'] = '';
539 - self::$title->mTitleProtection['pt_user'] = self::$user->getID();
540 - self::$title->mTitleProtection['pt_expiry'] = Block::infinity();
541 - self::$title->mTitleProtection['pt_reason'] = 'test';
542 - self::$title->mCascadeRestriction = false;
 539+ $this->title->mTitleProtection['pt_create_perm'] = '';
 540+ $this->title->mTitleProtection['pt_user'] = $this->user->getID();
 541+ $this->title->mTitleProtection['pt_expiry'] = Block::infinity();
 542+ $this->title->mTitleProtection['pt_reason'] = 'test';
 543+ $this->title->mCascadeRestriction = false;
543544
544545 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
545 - self::$title->getUserPermissionsErrors( 'create', self::$user ) );
 546+ $this->title->getUserPermissionsErrors( 'create', $this->user ) );
546547 $this->assertEquals( false,
547 - self::$title->userCan( 'create' ) );
 548+ $this->title->userCan( 'create' ) );
548549
549 - self::$title->mTitleProtection['pt_create_perm'] = 'sysop';
 550+ $this->title->mTitleProtection['pt_create_perm'] = 'sysop';
550551 $this->setUserPerm( array( 'createpage', 'protect' ) );
551552 $this->assertEquals( array( ),
552 - self::$title->getUserPermissionsErrors( 'create', self::$user ) );
 553+ $this->title->getUserPermissionsErrors( 'create', $this->user ) );
553554 $this->assertEquals( true,
554 - self::$title->userCan( 'create' ) );
 555+ $this->title->userCan( 'create' ) );
555556
556557
557558 $this->setUserPerm( array( 'createpage' ) );
558559 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
559 - self::$title->getUserPermissionsErrors( 'create', self::$user ) );
 560+ $this->title->getUserPermissionsErrors( 'create', $this->user ) );
560561 $this->assertEquals( false,
561 - self::$title->userCan( 'create' ) );
 562+ $this->title->userCan( 'create' ) );
562563
563564 $this->setTitle( NS_MEDIA, "test page" );
564565 $this->setUserPerm( array( "move" ) );
565566 $this->assertEquals( false,
566 - self::$title->userCan( 'move' ) );
 567+ $this->title->userCan( 'move' ) );
567568 $this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ),
568 - self::$title->getUserPermissionsErrors( 'move', self::$user ) );
 569+ $this->title->getUserPermissionsErrors( 'move', $this->user ) );
569570
570571 $this->setTitle( NS_MAIN, "test page" );
571572 $this->assertEquals( array( ),
572 - self::$title->getUserPermissionsErrors( 'move', self::$user ) );
 573+ $this->title->getUserPermissionsErrors( 'move', $this->user ) );
573574 $this->assertEquals( true,
574 - self::$title->userCan( 'move' ) );
 575+ $this->title->userCan( 'move' ) );
575576
576 - self::$title->mInterwiki = "no";
 577+ $this->title->mInterwiki = "no";
577578 $this->assertEquals( array( array( 'immobile-page' ) ),
578 - self::$title->getUserPermissionsErrors( 'move', self::$user ) );
 579+ $this->title->getUserPermissionsErrors( 'move', $this->user ) );
579580 $this->assertEquals( false,
580 - self::$title->userCan( 'move' ) );
 581+ $this->title->userCan( 'move' ) );
581582
582583 $this->setTitle( NS_MEDIA, "test page" );
583584 $this->assertEquals( false,
584 - self::$title->userCan( 'move-target' ) );
 585+ $this->title->userCan( 'move-target' ) );
585586 $this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ),
586 - self::$title->getUserPermissionsErrors( 'move-target', self::$user ) );
 587+ $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
587588
588589 $this->setTitle( NS_MAIN, "test page" );
589590 $this->assertEquals( array( ),
590 - self::$title->getUserPermissionsErrors( 'move-target', self::$user ) );
 591+ $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
591592 $this->assertEquals( true,
592 - self::$title->userCan( 'move-target' ) );
 593+ $this->title->userCan( 'move-target' ) );
593594
594 - self::$title->mInterwiki = "no";
 595+ $this->title->mInterwiki = "no";
595596 $this->assertEquals( array( array( 'immobile-target-page' ) ),
596 - self::$title->getUserPermissionsErrors( 'move-target', self::$user ) );
 597+ $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
597598 $this->assertEquals( false,
598 - self::$title->userCan( 'move-target' ) );
 599+ $this->title->userCan( 'move-target' ) );
599600
600601 }
601602
@@ -602,48 +603,48 @@
603604 global $wgUser, $wgEmailConfirmToEdit, $wgEmailAuthentication;
604605 $wgEmailConfirmToEdit = true;
605606 $wgEmailAuthentication = true;
606 - $wgUser = self::$user;
 607+ $wgUser = $this->user;
607608
608609 $this->setUserPerm( array( "createpage", "move" ) );
609610 $this->setTitle( NS_MAIN, "test page" );
610611
611612 # $short
612613 $this->assertEquals( array( array( 'confirmedittext' ) ),
613 - self::$title->getUserPermissionsErrors( 'move-target', self::$user ) );
 614+ $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
614615 $wgEmailConfirmToEdit = false;
615 - $this->assertEquals( true, self::$title->userCan( 'move-target' ) );
 616+ $this->assertEquals( true, $this->title->userCan( 'move-target' ) );
616617
617618 # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
618619 $this->assertEquals( array( ),
619 - self::$title->getUserPermissionsErrors( 'move-target',
620 - self::$user ) );
 620+ $this->title->getUserPermissionsErrors( 'move-target',
 621+ $this->user ) );
621622
622623 global $wgLang;
623624 $prev = time();
624625 $now = time() + 120;
625 - self::$user->mBlockedby = self::$user->getId();
626 - self::$user->mBlock = new Block( '127.0.8.1', self::$user->getId(), self::$user->getId(),
 626+ $this->user->mBlockedby = $this->user->getId();
 627+ $this->user->mBlock = new Block( '127.0.8.1', $this->user->getId(), $this->user->getId(),
627628 'no reason given', $prev + 3600, 1, 0 );
628 - self::$user->mBlock->mTimestamp = 0;
 629+ $this->user->mBlock->mTimestamp = 0;
629630 $this->assertEquals( array( array( 'autoblockedtext',
630631 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
631632 'Useruser', 0, 'infinite', '127.0.8.1',
632633 $wgLang->timeanddate( wfTimestamp( TS_MW, $prev ), true ) ) ),
633 - self::$title->getUserPermissionsErrors( 'move-target',
634 - self::$user ) );
 634+ $this->title->getUserPermissionsErrors( 'move-target',
 635+ $this->user ) );
635636
636637 $this->assertEquals( false,
637 - self::$title->userCan( 'move-target', self::$user ) );
 638+ $this->title->userCan( 'move-target', $this->user ) );
638639
639640 global $wgLocalTZoffset;
640641 $wgLocalTZoffset = -60;
641 - self::$user->mBlockedby = self::$user->getName();
642 - self::$user->mBlock = new Block( '127.0.8.1', 2, 1, 'no reason given', $now, 0, 10 );
 642+ $this->user->mBlockedby = $this->user->getName();
 643+ $this->user->mBlock = new Block( '127.0.8.1', 2, 1, 'no reason given', $now, 0, 10 );
643644 $this->assertEquals( array( array( 'blockedtext',
644645 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
645646 'Useruser', 0, '23:00, 31 December 1969', '127.0.8.1',
646647 $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ) ),
647 - self::$title->getUserPermissionsErrors( 'move-target', self::$user ) );
 648+ $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
648649
649650 # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
650651 # $user->blockedFor() == ''

Follow-up revisions

RevisionCommit summaryAuthorDate
r79685Remove the createaccount error check, failing since r79377....platonides23:20, 5 January 2011

Comments

#Comment by Platonides (talk | contribs)   20:14, 5 January 2011
  • Fixes TitlePermissionTest::testActionPermissions and TitlePermissionTest::testUserBlock
  • Breaks TitlePermissionTest::testSpecialsAndNSPermissions (the createaccount assert)

Status & tagging log