3 class TitlePermissionTest
extends PhpUnit_Framework_TestCase
{
13 global $wgAutoloadLocalClasses, $wgLocaltimezone, $wgLocalTZoffset;
14 self
::$userName = "Useruser";
15 self
::$altUserName = "Altuseruser";
16 date_default_timezone_set( $wgLocaltimezone );
17 $wgLocalTZoffset = date( "Z" ) / 60;
19 self
::$title = Title
::makeTitle( NS_MAIN
, "Main Page" );
20 if ( !isset( self
::$userUser ) ||
!( self
::$userUser instanceOf User
) ) {
21 self
::$userUser = User
::newFromName( self
::$userName );
23 if ( !self
::$userUser->getID() ) {
24 self
::$userUser = User
::createNew( self
::$userName, array(
25 "email" => "test@example.com",
26 "real_name" => "Test User" ) );
29 self
::$altUser = User
::newFromName( self
::$altUserName );
30 if ( !self
::$altUser->getID() ) {
31 self
::$altUser = User
::createNew( self
::$altUserName, array(
32 "email" => "alttest@example.com",
33 "real_name" => "Test User Alt" ) );
36 self
::$anonUser = User
::newFromId( 0 );
38 self
::$user = self
::$userUser;
42 function setUserPerm( $perm ) {
43 global $wgUseRCPatrol, $wgUseNPPatrol;
44 if ( is_array( $perm ) ) {
45 self
::$user->mRights
= $perm;
47 self
::$user->mRights
= array( $perm );
51 function setTitle( $ns, $title = "Main_Page" ) {
52 self
::$title = Title
::makeTitle( $ns, $title );
55 function setUser( $userName = null ) {
56 if ( $userName === 'anon' ) {
57 self
::$user = self
::$anonUser;
58 } else if ( $userName === null ||
$userName === self
::$userName ) {
59 self
::$user = self
::$userUser;
61 self
::$user = self
::$altUser;
65 $wgUser = self
::$user;
68 function testQuickPermissions() {
70 $prefix = $wgContLang->getNsText( NS_PROJECT
);
72 $this->setUser( 'anon' );
73 $this->setTitle( NS_TALK
);
74 $this->setUserPerm( "createtalk" );
75 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
76 $this->assertEquals( array(), $res );
78 $this->setTitle( NS_TALK
);
79 $this->setUserPerm( "createpage" );
80 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
81 $this->assertEquals( array( array( "nocreatetext" ) ), $res );
83 $this->setTitle( NS_TALK
);
84 $this->setUserPerm( "" );
85 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
86 $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
88 $this->setTitle( NS_MAIN
);
89 $this->setUserPerm( "createpage" );
90 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
91 $this->assertEquals( array( ), $res );
93 $this->setTitle( NS_MAIN
);
94 $this->setUserPerm( "createtalk" );
95 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
96 $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
98 $this->setUser( self
::$userName );
99 $this->setTitle( NS_TALK
);
100 $this->setUserPerm( "createtalk" );
101 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
102 $this->assertEquals( array( ), $res );
104 $this->setTitle( NS_TALK
);
105 $this->setUserPerm( "createpage" );
106 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
107 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
109 $this->setTitle( NS_TALK
);
110 $this->setUserPerm( "" );
111 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
112 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
114 $this->setTitle( NS_MAIN
);
115 $this->setUserPerm( "createpage" );
116 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
117 $this->assertEquals( array( ), $res );
119 $this->setTitle( NS_MAIN
);
120 $this->setUserPerm( "createtalk" );
121 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
122 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
124 $this->setTitle( NS_MAIN
);
125 $this->setUserPerm( "" );
126 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
127 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
129 $this->setUser( 'anon' );
130 $this->setTitle( NS_USER
, self
::$userName . '' );
131 $this->setUserPerm( "" );
132 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
133 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
135 $this->setTitle( NS_USER
, self
::$userName . '/subpage' );
136 $this->setUserPerm( "" );
137 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
138 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
140 $this->setTitle( NS_USER
, self
::$userName . '' );
141 $this->setUserPerm( "move-rootuserpages" );
142 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
143 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
145 $this->setTitle( NS_USER
, self
::$userName . '/subpage' );
146 $this->setUserPerm( "move-rootuserpages" );
147 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
148 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
150 $this->setTitle( NS_USER
, self
::$userName . '' );
151 $this->setUserPerm( "" );
152 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
153 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
155 $this->setTitle( NS_USER
, self
::$userName . '/subpage' );
156 $this->setUserPerm( "" );
157 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
158 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
160 $this->setTitle( NS_USER
, self
::$userName . '' );
161 $this->setUserPerm( "move-rootuserpages" );
162 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
163 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
165 $this->setTitle( NS_USER
, self
::$userName . '/subpage' );
166 $this->setUserPerm( "move-rootuserpages" );
167 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
168 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
170 $this->setUser( self
::$userName );
171 $this->setTitle( NS_FILE
, "img.png" );
172 $this->setUserPerm( "" );
173 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
174 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ), $res );
176 $this->setTitle( NS_FILE
, "img.png" );
177 $this->setUserPerm( "movefile" );
178 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
179 $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
181 $this->setUser( 'anon' );
182 $this->setTitle( NS_FILE
, "img.png" );
183 $this->setUserPerm( "" );
184 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
185 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ), $res );
187 $this->setTitle( NS_FILE
, "img.png" );
188 $this->setUserPerm( "movefile" );
189 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
190 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
192 $this->setUser( self
::$userName );
193 $this->setUserPerm( "move" );
194 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
196 $this->setUserPerm( "" );
197 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ) );
199 $this->setUser( 'anon' );
200 $this->setUserPerm( "move" );
201 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
203 $this->setUserPerm( "" );
204 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ),
205 array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ) );
207 $this->setTitle( NS_MAIN
);
208 $this->setUser( 'anon' );
209 $this->setUserPerm( "move" );
210 $this->runGroupPermissions( 'move', array( ) );
212 $this->setUserPerm( "" );
213 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ),
214 array( array( 'movenologintext' ) ) );
216 $this->setUser( self
::$userName );
217 $this->setUserPerm( "" );
218 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ) );
220 $this->setUserPerm( "move" );
221 $this->runGroupPermissions( 'move', array( ) );
223 $this->setUser( 'anon' );
224 $this->setUserPerm( 'move' );
225 $res = self
::$title->getUserPermissionsErrors( 'move-target', self
::$user );
226 $this->assertEquals( array( ), $res );
228 $this->setUserPerm( '' );
229 $res = self
::$title->getUserPermissionsErrors( 'move-target', self
::$user );
230 $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
232 $this->setTitle( NS_USER
);
233 $this->setUser( self
::$userName );
234 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
235 $res = self
::$title->getUserPermissionsErrors( 'move-target', self
::$user );
236 $this->assertEquals( array( ), $res );
238 $this->setUserPerm( "move" );
239 $res = self
::$title->getUserPermissionsErrors( 'move-target', self
::$user );
240 $this->assertEquals( array( array( 'cant-move-to-user-page' ) ), $res );
242 $this->setUser( 'anon' );
243 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
244 $res = self
::$title->getUserPermissionsErrors( 'move-target', self
::$user );
245 $this->assertEquals( array( ), $res );
247 $this->setTitle( NS_USER
, "User/subpage" );
248 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
249 $res = self
::$title->getUserPermissionsErrors( 'move-target', self
::$user );
250 $this->assertEquals( array( ), $res );
252 $this->setUserPerm( "move" );
253 $res = self
::$title->getUserPermissionsErrors( 'move-target', self
::$user );
254 $this->assertEquals( array( ), $res );
256 $this->setUser( 'anon' );
257 $check = array( 'edit' => array( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ) ),
258 array( array( 'badaccess-group0' ) ),
260 'protect' => array( array( array( 'badaccess-groups', "[[$prefix:Administrators|Administrators]]", 1 ), array( 'protect-cantedit' ) ),
261 array( array( 'badaccess-group0' ), array( 'protect-cantedit' ) ),
262 array( array( 'protect-cantedit' ) ), false ),
263 '' => array( array( ), array( ), array( ), true ) );
265 $wgUser = self
::$user;
266 foreach ( array( "edit", "protect", "" ) as $action ) {
267 $this->setUserPerm( null );
268 $this->assertEquals( $check[$action][0],
269 self
::$title->getUserPermissionsErrors( $action, self
::$user, true ) );
271 global $wgGroupPermissions;
272 $old = $wgGroupPermissions;
273 $wgGroupPermissions = array();
275 $this->assertEquals( $check[$action][1],
276 self
::$title->getUserPermissionsErrors( $action, self
::$user, true ) );
277 $wgGroupPermissions = $old;
279 $this->setUserPerm( $action );
280 $this->assertEquals( $check[$action][2],
281 self
::$title->getUserPermissionsErrors( $action, self
::$user, true ) );
283 $this->setUserPerm( $action );
284 $this->assertEquals( $check[$action][3],
285 self
::$title->userCan( $action, true ) );
286 $this->assertEquals( $check[$action][3],
287 self
::$title->quickUserCan( $action, false ) );
289 # count( User::getGroupsWithPermissions( $action ) ) < 1
293 function runGroupPermissions( $action, $result, $result2 = null ) {
294 global $wgGroupPermissions;
296 if ( $result2 === null ) $result2 = $result;
298 $wgGroupPermissions['autoconfirmed']['move'] = false;
299 $wgGroupPermissions['user']['move'] = false;
300 $res = self
::$title->getUserPermissionsErrors( $action, self
::$user );
301 $this->assertEquals( $result, $res );
303 $wgGroupPermissions['autoconfirmed']['move'] = true;
304 $wgGroupPermissions['user']['move'] = false;
305 $res = self
::$title->getUserPermissionsErrors( $action, self
::$user );
306 $this->assertEquals( $result2, $res );
308 $wgGroupPermissions['autoconfirmed']['move'] = true;
309 $wgGroupPermissions['user']['move'] = true;
310 $res = self
::$title->getUserPermissionsErrors( $action, self
::$user );
311 $this->assertEquals( $result2, $res );
313 $wgGroupPermissions['autoconfirmed']['move'] = false;
314 $wgGroupPermissions['user']['move'] = true;
315 $res = self
::$title->getUserPermissionsErrors( $action, self
::$user );
316 $this->assertEquals( $result2, $res );
319 function testPermissionHooks() { }
320 function testSpecialsAndNSPermissions() {
321 $this->setUser( self
::$userName );
322 global $wgUser, $wgContLang;
323 $wgUser = self
::$user;
324 $prefix = $wgContLang->getNsText( NS_PROJECT
);
326 $this->setTitle( NS_SPECIAL
);
328 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'ns-specialprotected' ) ),
329 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
330 $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Administrators|Administrators]]", 2 ) ),
331 self
::$title->getUserPermissionsErrors( 'createaccount', self
::$user ) );
332 $this->assertEquals( array( array( 'badaccess-group0' ) ),
333 self
::$title->getUserPermissionsErrors( 'execute', self
::$user ) );
335 $this->setTitle( NS_MAIN
);
336 $this->setUserPerm( 'bogus' );
337 $this->assertEquals( array( ),
338 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
340 $this->setTitle( NS_MAIN
);
341 $this->setUserPerm( '' );
342 $this->assertEquals( array( array( 'badaccess-group0' ) ),
343 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
345 global $wgNamespaceProtection;
346 $wgNamespaceProtection[NS_USER
] = array ( 'bogus' );
347 $this->setTitle( NS_USER
);
348 $this->setUserPerm( '' );
349 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'namespaceprotected', 'User' ) ),
350 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
352 $this->setTitle( NS_MEDIAWIKI
);
353 $this->setUserPerm( 'bogus' );
354 $this->assertEquals( array( array( 'protectedinterface' ) ),
355 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
357 $this->setTitle( NS_MEDIAWIKI
);
358 $this->setUserPerm( 'bogus' );
359 $this->assertEquals( array( array( 'protectedinterface' ) ),
360 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
362 $wgNamespaceProtection = null;
363 $this->setUserPerm( 'bogus' );
364 $this->assertEquals( array( ),
365 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
366 $this->assertEquals( true,
367 self
::$title->userCan( 'bogus' ) );
369 $this->setUserPerm( '' );
370 $this->assertEquals( array( array( 'badaccess-group0' ) ),
371 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
372 $this->assertEquals( false,
373 self
::$title->userCan( 'bogus' ) );
376 function testCSSandJSPermissions() {
377 $this->setUser( self
::$userName );
379 $wgUser = self
::$user;
381 $this->setTitle( NS_USER
, self
::$altUserName . '/test.js' );
382 $this->runCSSandJSPermissions(
383 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
384 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
385 array( array( 'badaccess-group0' ) ) );
387 $this->setTitle( NS_USER
, self
::$altUserName . '/test.css' );
388 $this->runCSSandJSPermissions(
389 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
390 array( array( 'badaccess-group0' ) ),
391 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ) );
393 $this->setTitle( NS_USER
, self
::$altUserName . '/tempo' );
394 $this->runCSSandJSPermissions(
395 array( array( 'badaccess-group0' ) ),
396 array( array( 'badaccess-group0' ) ),
397 array( array( 'badaccess-group0' ) ) );
400 function runCSSandJSPermissions( $result0, $result1, $result2 ) {
401 $this->setUserPerm( '' );
402 $this->assertEquals( $result0,
403 self
::$title->getUserPermissionsErrors( 'bogus',
406 $this->setUserPerm( 'editusercss' );
407 $this->assertEquals( $result1,
408 self
::$title->getUserPermissionsErrors( 'bogus',
411 $this->setUserPerm( 'edituserjs' );
412 $this->assertEquals( $result2,
413 self
::$title->getUserPermissionsErrors( 'bogus',
416 $this->setUserPerm( 'editusercssjs' );
417 $this->assertEquals( array( array( 'badaccess-group0' ) ),
418 self
::$title->getUserPermissionsErrors( 'bogus',
421 $this->setUserPerm( array( 'edituserjs', 'editusercss' ) );
422 $this->assertEquals( array( array( 'badaccess-group0' ) ),
423 self
::$title->getUserPermissionsErrors( 'bogus',
427 function testPageRestrictions() {
428 global $wgUser, $wgContLang;
430 $prefix = $wgContLang->getNsText( NS_PROJECT
);
432 $wgUser = self
::$user;
433 $this->setTitle( NS_MAIN
);
434 self
::$title->mRestrictionsLoaded
= true;
435 $this->setUserPerm( "edit" );
436 self
::$title->mRestrictions
= array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
438 $this->assertEquals( array( ),
439 self
::$title->getUserPermissionsErrors( 'edit',
442 $this->assertEquals( true,
443 self
::$title->quickUserCan( 'edit', false ) );
444 self
::$title->mRestrictions
= array( "edit" => array( 'bogus', "sysop", "protect", "" ),
445 "bogus" => array( 'bogus', "sysop", "protect", "" ) );
447 $this->assertEquals( array( array( 'badaccess-group0' ),
448 array( 'protectedpagetext', 'bogus' ),
449 array( 'protectedpagetext', 'protect' ),
450 array( 'protectedpagetext', 'protect' ) ),
451 self
::$title->getUserPermissionsErrors( 'bogus',
453 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
454 array( 'protectedpagetext', 'protect' ),
455 array( 'protectedpagetext', 'protect' ) ),
456 self
::$title->getUserPermissionsErrors( 'edit',
458 $this->setUserPerm( "" );
459 $this->assertEquals( array( array( 'badaccess-group0' ),
460 array( 'protectedpagetext', 'bogus' ),
461 array( 'protectedpagetext', 'protect' ),
462 array( 'protectedpagetext', 'protect' ) ),
463 self
::$title->getUserPermissionsErrors( 'bogus',
465 $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ),
466 array( 'protectedpagetext', 'bogus' ),
467 array( 'protectedpagetext', 'protect' ),
468 array( 'protectedpagetext', 'protect' ) ),
469 self
::$title->getUserPermissionsErrors( 'edit',
471 $this->setUserPerm( array( "edit", "editprotected" ) );
472 $this->assertEquals( array( array( 'badaccess-group0' ),
473 array( 'protectedpagetext', 'bogus' ),
474 array( 'protectedpagetext', 'protect' ),
475 array( 'protectedpagetext', 'protect' ) ),
476 self
::$title->getUserPermissionsErrors( 'bogus',
478 $this->assertEquals( array( ),
479 self
::$title->getUserPermissionsErrors( 'edit',
481 self
::$title->mCascadeRestriction
= true;
482 $this->assertEquals( false,
483 self
::$title->quickUserCan( 'bogus', false ) );
484 $this->assertEquals( false,
485 self
::$title->quickUserCan( 'edit', false ) );
486 $this->assertEquals( array( array( 'badaccess-group0' ),
487 array( 'protectedpagetext', 'bogus' ),
488 array( 'protectedpagetext', 'protect' ),
489 array( 'protectedpagetext', 'protect' ) ),
490 self
::$title->getUserPermissionsErrors( 'bogus',
492 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
493 array( 'protectedpagetext', 'protect' ),
494 array( 'protectedpagetext', 'protect' ) ),
495 self
::$title->getUserPermissionsErrors( 'edit',
499 function testCascadingSourcesRestrictions() {
501 $wgUser = self
::$user;
502 $this->setTitle( NS_MAIN
, "test page" );
503 $this->setUserPerm( array( "edit", "bogus" ) );
505 self
::$title->mCascadeSources
= array( Title
::makeTitle( NS_MAIN
, "Bogus" ), Title
::makeTitle( NS_MAIN
, "UnBogus" ) );
506 self
::$title->mCascadingRestrictions
= array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
508 $this->assertEquals( false,
509 self
::$title->userCan( 'bogus' ) );
510 $this->assertEquals( array( array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ),
511 array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ) ),
512 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
514 $this->assertEquals( true,
515 self
::$title->userCan( 'edit' ) );
516 $this->assertEquals( array( ),
517 self
::$title->getUserPermissionsErrors( 'edit', self
::$user ) );
521 function testActionPermissions() {
523 $wgUser = self
::$user;
525 $this->setUserPerm( array( "createpage" ) );
526 $this->setTitle( NS_MAIN
, "test page" );
527 self
::$title->mTitleProtection
['pt_create_perm'] = '';
528 self
::$title->mTitleProtection
['pt_user'] = self
::$user->getID();
529 self
::$title->mTitleProtection
['pt_expiry'] = Block
::infinity();
530 self
::$title->mTitleProtection
['pt_reason'] = 'test';
531 self
::$title->mCascadeRestriction
= false;
533 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
534 self
::$title->getUserPermissionsErrors( 'create', self
::$user ) );
535 $this->assertEquals( false,
536 self
::$title->userCan( 'create' ) );
538 self
::$title->mTitleProtection
['pt_create_perm'] = 'sysop';
539 $this->setUserPerm( array( 'createpage', 'protect' ) );
540 $this->assertEquals( array( ),
541 self
::$title->getUserPermissionsErrors( 'create', self
::$user ) );
542 $this->assertEquals( true,
543 self
::$title->userCan( 'create' ) );
546 $this->setUserPerm( array( 'createpage' ) );
547 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
548 self
::$title->getUserPermissionsErrors( 'create', self
::$user ) );
549 $this->assertEquals( false,
550 self
::$title->userCan( 'create' ) );
552 $this->setTitle( NS_MEDIA
, "test page" );
553 $this->setUserPerm( array( "move" ) );
554 $this->assertEquals( false,
555 self
::$title->userCan( 'move' ) );
556 $this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ),
557 self
::$title->getUserPermissionsErrors( 'move', self
::$user ) );
559 $this->setTitle( NS_MAIN
, "test page" );
560 $this->assertEquals( array( ),
561 self
::$title->getUserPermissionsErrors( 'move', self
::$user ) );
562 $this->assertEquals( true,
563 self
::$title->userCan( 'move' ) );
565 self
::$title->mInterwiki
= "no";
566 $this->assertEquals( array( array( 'immobile-page' ) ),
567 self
::$title->getUserPermissionsErrors( 'move', self
::$user ) );
568 $this->assertEquals( false,
569 self
::$title->userCan( 'move' ) );
571 $this->setTitle( NS_MEDIA
, "test page" );
572 $this->assertEquals( false,
573 self
::$title->userCan( 'move-target' ) );
574 $this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ),
575 self
::$title->getUserPermissionsErrors( 'move-target', self
::$user ) );
577 $this->setTitle( NS_MAIN
, "test page" );
578 $this->assertEquals( array( ),
579 self
::$title->getUserPermissionsErrors( 'move-target', self
::$user ) );
580 $this->assertEquals( true,
581 self
::$title->userCan( 'move-target' ) );
583 self
::$title->mInterwiki
= "no";
584 $this->assertEquals( array( array( 'immobile-target-page' ) ),
585 self
::$title->getUserPermissionsErrors( 'move-target', self
::$user ) );
586 $this->assertEquals( false,
587 self
::$title->userCan( 'move-target' ) );
591 function testUserBlock() {
592 global $wgUser, $wgEmailConfirmToEdit, $wgEmailAuthentication;
593 $wgEmailConfirmToEdit = true;
594 $wgEmailAuthentication = true;
595 $wgUser = self
::$user;
597 $this->setUserPerm( array( "createpage", "move" ) );
598 $this->setTitle( NS_MAIN
, "test page" );
601 $this->assertEquals( array( array( 'confirmedittext' ) ),
602 self
::$title->getUserPermissionsErrors( 'move-target', self
::$user ) );
603 $this->assertEquals( true, self
::$title->userCan( 'move-target' ) );
605 $wgEmailConfirmToEdit = false;
606 # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
607 $this->assertEquals( array( ),
608 self
::$title->getUserPermissionsErrors( 'move-target',
614 self
::$user->mBlockedby
= self
::$user->getId();
615 self
::$user->mBlock
= new Block( '127.0.8.1', self
::$user->getId(), self
::$user->getId(),
616 'no reason given', $prev +
3600, 1, 0 );
617 self
::$user->mBlock
->mTimestamp
= 0;
618 $this->assertEquals( array( array( 'autoblockedtext',
619 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
620 'Useruser', 0, 'infinite', '127.0.8.1',
621 $wgLang->timeanddate( wfTimestamp( TS_MW
, $prev ), true ) ) ),
622 self
::$title->getUserPermissionsErrors( 'move-target',
625 $this->assertEquals( true,
626 self
::$title->userCan( 'move-target', self
::$user ) );
628 global $wgLocalTZoffset;
629 $wgLocalTZoffset = -60;
630 self
::$user->mBlockedby
= self
::$user->getName();
631 self
::$user->mBlock
= new Block( '127.0.8.1', 2, 1, 'no reason given', $now, 0, 10 );
632 $this->assertEquals( array( array( 'blockedtext',
633 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
634 'Useruser', 0, '23:00, 31 December 1969', '127.0.8.1',
635 $wgLang->timeanddate( wfTimestamp( TS_MW
, $now ), true ) ) ),
636 self
::$title->getUserPermissionsErrors( 'move-target', self
::$user ) );
638 # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
639 # $user->blockedFor() == ''
640 # $user->mBlock->mExpiry == 'infinity'