6 class TitlePermissionTest
extends MediaWikiTestCase
{
13 protected $altUserName;
16 global $wgLocaltimezone, $wgLocalTZoffset, $wgMemc, $wgContLang, $wgLang;
19 $wgMemc = new EmptyBagOStuff
;
21 $wgContLang = $wgLang = Language
::factory( 'en' );
23 $this->userName
= "Useruser";
24 $this->altUserName
= "Altuseruser";
25 date_default_timezone_set( $wgLocaltimezone );
26 $wgLocalTZoffset = date( "Z" ) / 60;
28 $this->title
= Title
::makeTitle( NS_MAIN
, "Main Page" );
29 if ( !isset( $this->userUser
) ||
!( $this->userUser
instanceOf User
) ) {
30 $this->userUser
= User
::newFromName( $this->userName
);
32 if ( !$this->userUser
->getID() ) {
33 $this->userUser
= User
::createNew( $this->userName
, array(
34 "email" => "test@example.com",
35 "real_name" => "Test User" ) );
36 $this->userUser
->load();
39 $this->altUser
= User
::newFromName( $this->altUserName
);
40 if ( !$this->altUser
->getID() ) {
41 $this->altUser
= User
::createNew( $this->altUserName
, array(
42 "email" => "alttest@example.com",
43 "real_name" => "Test User Alt" ) );
44 $this->altUser
->load();
47 $this->anonUser
= User
::newFromId( 0 );
49 $this->user
= $this->userUser
;
53 function setUserPerm( $perm ) {
54 if ( is_array( $perm ) ) {
55 $this->user
->mRights
= $perm;
57 $this->user
->mRights
= array( $perm );
61 function setTitle( $ns, $title = "Main_Page" ) {
62 $this->title
= Title
::makeTitle( $ns, $title );
65 function setUser( $userName = null ) {
66 if ( $userName === 'anon' ) {
67 $this->user
= $this->anonUser
;
68 } else if ( $userName === null ||
$userName === $this->userName
) {
69 $this->user
= $this->userUser
;
71 $this->user
= $this->altUser
;
75 $wgUser = $this->user
;
78 function testQuickPermissions() {
80 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT
);
82 $this->setUser( 'anon' );
83 $this->setTitle( NS_TALK
);
84 $this->setUserPerm( "createtalk" );
85 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
86 $this->assertEquals( array(), $res );
88 $this->setTitle( NS_TALK
);
89 $this->setUserPerm( "createpage" );
90 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
91 $this->assertEquals( array( array( "nocreatetext" ) ), $res );
93 $this->setTitle( NS_TALK
);
94 $this->setUserPerm( "" );
95 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
96 $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
98 $this->setTitle( NS_MAIN
);
99 $this->setUserPerm( "createpage" );
100 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
101 $this->assertEquals( array( ), $res );
103 $this->setTitle( NS_MAIN
);
104 $this->setUserPerm( "createtalk" );
105 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
106 $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
108 $this->setUser( $this->userName
);
109 $this->setTitle( NS_TALK
);
110 $this->setUserPerm( "createtalk" );
111 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
112 $this->assertEquals( array( ), $res );
114 $this->setTitle( NS_TALK
);
115 $this->setUserPerm( "createpage" );
116 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
117 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
119 $this->setTitle( NS_TALK
);
120 $this->setUserPerm( "" );
121 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
122 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
124 $this->setTitle( NS_MAIN
);
125 $this->setUserPerm( "createpage" );
126 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
127 $this->assertEquals( array( ), $res );
129 $this->setTitle( NS_MAIN
);
130 $this->setUserPerm( "createtalk" );
131 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
132 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
134 $this->setTitle( NS_MAIN
);
135 $this->setUserPerm( "" );
136 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
137 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
139 $this->setUser( 'anon' );
140 $this->setTitle( NS_USER
, $this->userName
. '' );
141 $this->setUserPerm( "" );
142 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
143 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
145 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
146 $this->setUserPerm( "" );
147 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
148 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
150 $this->setTitle( NS_USER
, $this->userName
. '' );
151 $this->setUserPerm( "move-rootuserpages" );
152 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
153 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
155 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
156 $this->setUserPerm( "move-rootuserpages" );
157 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
158 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
160 $this->setTitle( NS_USER
, $this->userName
. '' );
161 $this->setUserPerm( "" );
162 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
163 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
165 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
166 $this->setUserPerm( "" );
167 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
168 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
170 $this->setTitle( NS_USER
, $this->userName
. '' );
171 $this->setUserPerm( "move-rootuserpages" );
172 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
173 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
175 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
176 $this->setUserPerm( "move-rootuserpages" );
177 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
178 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
180 $this->setUser( $this->userName
);
181 $this->setTitle( NS_FILE
, "img.png" );
182 $this->setUserPerm( "" );
183 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
184 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ), $res );
186 $this->setTitle( NS_FILE
, "img.png" );
187 $this->setUserPerm( "movefile" );
188 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
189 $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
191 $this->setUser( 'anon' );
192 $this->setTitle( NS_FILE
, "img.png" );
193 $this->setUserPerm( "" );
194 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
195 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ), $res );
197 $this->setTitle( NS_FILE
, "img.png" );
198 $this->setUserPerm( "movefile" );
199 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
200 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
202 $this->setUser( $this->userName
);
203 $this->setUserPerm( "move" );
204 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
206 $this->setUserPerm( "" );
207 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ) );
209 $this->setUser( 'anon' );
210 $this->setUserPerm( "move" );
211 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
213 $this->setUserPerm( "" );
214 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ),
215 array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ) );
217 $this->setTitle( NS_MAIN
);
218 $this->setUser( 'anon' );
219 $this->setUserPerm( "move" );
220 $this->runGroupPermissions( 'move', array( ) );
222 $this->setUserPerm( "" );
223 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ),
224 array( array( 'movenologintext' ) ) );
226 $this->setUser( $this->userName
);
227 $this->setUserPerm( "" );
228 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ) );
230 $this->setUserPerm( "move" );
231 $this->runGroupPermissions( 'move', array( ) );
233 $this->setUser( 'anon' );
234 $this->setUserPerm( 'move' );
235 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
236 $this->assertEquals( array( ), $res );
238 $this->setUserPerm( '' );
239 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
240 $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
242 $this->setTitle( NS_USER
);
243 $this->setUser( $this->userName
);
244 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
245 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
246 $this->assertEquals( array( ), $res );
248 $this->setUserPerm( "move" );
249 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
250 $this->assertEquals( array( array( 'cant-move-to-user-page' ) ), $res );
252 $this->setUser( 'anon' );
253 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
254 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
255 $this->assertEquals( array( ), $res );
257 $this->setTitle( NS_USER
, "User/subpage" );
258 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
259 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
260 $this->assertEquals( array( ), $res );
262 $this->setUserPerm( "move" );
263 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
264 $this->assertEquals( array( ), $res );
266 $this->setUser( 'anon' );
267 $check = array( 'edit' => array( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ) ),
268 array( array( 'badaccess-group0' ) ),
270 'protect' => array( array( array( 'badaccess-groups', "[[$prefix:Administrators|Administrators]]", 1 ), array( 'protect-cantedit' ) ),
271 array( array( 'badaccess-group0' ), array( 'protect-cantedit' ) ),
272 array( array( 'protect-cantedit' ) ), false ),
273 '' => array( array( ), array( ), array( ), true ) );
275 $wgUser = $this->user
;
276 foreach ( array( "edit", "protect", "" ) as $action ) {
277 $this->setUserPerm( null );
278 $this->assertEquals( $check[$action][0],
279 $this->title
->getUserPermissionsErrors( $action, $this->user
, true ) );
281 global $wgGroupPermissions;
282 $old = $wgGroupPermissions;
283 $wgGroupPermissions = array();
285 $this->assertEquals( $check[$action][1],
286 $this->title
->getUserPermissionsErrors( $action, $this->user
, true ) );
287 $wgGroupPermissions = $old;
289 $this->setUserPerm( $action );
290 $this->assertEquals( $check[$action][2],
291 $this->title
->getUserPermissionsErrors( $action, $this->user
, true ) );
293 $this->setUserPerm( $action );
294 $this->assertEquals( $check[$action][3],
295 $this->title
->userCan( $action, true ) );
296 $this->assertEquals( $check[$action][3],
297 $this->title
->quickUserCan( $action, false ) );
299 # count( User::getGroupsWithPermissions( $action ) ) < 1
303 function runGroupPermissions( $action, $result, $result2 = null ) {
304 global $wgGroupPermissions;
306 if ( $result2 === null ) $result2 = $result;
308 $wgGroupPermissions['autoconfirmed']['move'] = false;
309 $wgGroupPermissions['user']['move'] = false;
310 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
311 $this->assertEquals( $result, $res );
313 $wgGroupPermissions['autoconfirmed']['move'] = true;
314 $wgGroupPermissions['user']['move'] = false;
315 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
316 $this->assertEquals( $result2, $res );
318 $wgGroupPermissions['autoconfirmed']['move'] = true;
319 $wgGroupPermissions['user']['move'] = true;
320 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
321 $this->assertEquals( $result2, $res );
323 $wgGroupPermissions['autoconfirmed']['move'] = false;
324 $wgGroupPermissions['user']['move'] = true;
325 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
326 $this->assertEquals( $result2, $res );
329 function testPermissionHooks() { }
330 function testSpecialsAndNSPermissions() {
331 $this->setUser( $this->userName
);
333 $wgUser = $this->user
;
335 $this->setTitle( NS_SPECIAL
);
337 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'ns-specialprotected' ) ),
338 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
339 $this->assertEquals( array( array( 'badaccess-group0' ) ),
340 $this->title
->getUserPermissionsErrors( 'execute', $this->user
) );
342 $this->setTitle( NS_MAIN
);
343 $this->setUserPerm( 'bogus' );
344 $this->assertEquals( array( ),
345 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
347 $this->setTitle( NS_MAIN
);
348 $this->setUserPerm( '' );
349 $this->assertEquals( array( array( 'badaccess-group0' ) ),
350 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
352 global $wgNamespaceProtection;
353 $wgNamespaceProtection[NS_USER
] = array ( 'bogus' );
354 $this->setTitle( NS_USER
);
355 $this->setUserPerm( '' );
356 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'namespaceprotected', 'User' ) ),
357 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
359 $this->setTitle( NS_MEDIAWIKI
);
360 $this->setUserPerm( 'bogus' );
361 $this->assertEquals( array( array( 'protectedinterface' ) ),
362 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
364 $this->setTitle( NS_MEDIAWIKI
);
365 $this->setUserPerm( 'bogus' );
366 $this->assertEquals( array( array( 'protectedinterface' ) ),
367 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
369 $wgNamespaceProtection = null;
370 $this->setUserPerm( 'bogus' );
371 $this->assertEquals( array( ),
372 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
373 $this->assertEquals( true,
374 $this->title
->userCan( 'bogus' ) );
376 $this->setUserPerm( '' );
377 $this->assertEquals( array( array( 'badaccess-group0' ) ),
378 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
379 $this->assertEquals( false,
380 $this->title
->userCan( 'bogus' ) );
383 function testCSSandJSPermissions() {
384 $this->setUser( $this->userName
);
386 $wgUser = $this->user
;
388 $this->setTitle( NS_USER
, $this->altUserName
. '/test.js' );
389 $this->runCSSandJSPermissions(
390 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
391 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
392 array( array( 'badaccess-group0' ) ) );
394 $this->setTitle( NS_USER
, $this->altUserName
. '/test.css' );
395 $this->runCSSandJSPermissions(
396 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
397 array( array( 'badaccess-group0' ) ),
398 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ) );
400 $this->setTitle( NS_USER
, $this->altUserName
. '/tempo' );
401 $this->runCSSandJSPermissions(
402 array( array( 'badaccess-group0' ) ),
403 array( array( 'badaccess-group0' ) ),
404 array( array( 'badaccess-group0' ) ) );
407 function runCSSandJSPermissions( $result0, $result1, $result2 ) {
408 $this->setUserPerm( '' );
409 $this->assertEquals( $result0,
410 $this->title
->getUserPermissionsErrors( 'bogus',
413 $this->setUserPerm( 'editusercss' );
414 $this->assertEquals( $result1,
415 $this->title
->getUserPermissionsErrors( 'bogus',
418 $this->setUserPerm( 'edituserjs' );
419 $this->assertEquals( $result2,
420 $this->title
->getUserPermissionsErrors( 'bogus',
423 $this->setUserPerm( 'editusercssjs' );
424 $this->assertEquals( array( array( 'badaccess-group0' ) ),
425 $this->title
->getUserPermissionsErrors( 'bogus',
428 $this->setUserPerm( array( 'edituserjs', 'editusercss' ) );
429 $this->assertEquals( array( array( 'badaccess-group0' ) ),
430 $this->title
->getUserPermissionsErrors( 'bogus',
434 function testPageRestrictions() {
435 global $wgUser, $wgContLang;
437 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT
);
439 $wgUser = $this->user
;
440 $this->setTitle( NS_MAIN
);
441 $this->title
->mRestrictionsLoaded
= true;
442 $this->setUserPerm( "edit" );
443 $this->title
->mRestrictions
= array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
445 $this->assertEquals( array( ),
446 $this->title
->getUserPermissionsErrors( 'edit',
449 $this->assertEquals( true,
450 $this->title
->quickUserCan( 'edit', false ) );
451 $this->title
->mRestrictions
= array( "edit" => array( 'bogus', "sysop", "protect", "" ),
452 "bogus" => array( 'bogus', "sysop", "protect", "" ) );
454 $this->assertEquals( array( array( 'badaccess-group0' ),
455 array( 'protectedpagetext', 'bogus' ),
456 array( 'protectedpagetext', 'protect' ),
457 array( 'protectedpagetext', 'protect' ) ),
458 $this->title
->getUserPermissionsErrors( 'bogus',
460 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
461 array( 'protectedpagetext', 'protect' ),
462 array( 'protectedpagetext', 'protect' ) ),
463 $this->title
->getUserPermissionsErrors( 'edit',
465 $this->setUserPerm( "" );
466 $this->assertEquals( array( array( 'badaccess-group0' ),
467 array( 'protectedpagetext', 'bogus' ),
468 array( 'protectedpagetext', 'protect' ),
469 array( 'protectedpagetext', 'protect' ) ),
470 $this->title
->getUserPermissionsErrors( 'bogus',
472 $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ),
473 array( 'protectedpagetext', 'bogus' ),
474 array( 'protectedpagetext', 'protect' ),
475 array( 'protectedpagetext', 'protect' ) ),
476 $this->title
->getUserPermissionsErrors( 'edit',
478 $this->setUserPerm( array( "edit", "editprotected" ) );
479 $this->assertEquals( array( array( 'badaccess-group0' ),
480 array( 'protectedpagetext', 'bogus' ),
481 array( 'protectedpagetext', 'protect' ),
482 array( 'protectedpagetext', 'protect' ) ),
483 $this->title
->getUserPermissionsErrors( 'bogus',
485 $this->assertEquals( array( ),
486 $this->title
->getUserPermissionsErrors( 'edit',
488 $this->title
->mCascadeRestriction
= true;
489 $this->assertEquals( false,
490 $this->title
->quickUserCan( 'bogus', false ) );
491 $this->assertEquals( false,
492 $this->title
->quickUserCan( 'edit', false ) );
493 $this->assertEquals( array( array( 'badaccess-group0' ),
494 array( 'protectedpagetext', 'bogus' ),
495 array( 'protectedpagetext', 'protect' ),
496 array( 'protectedpagetext', 'protect' ) ),
497 $this->title
->getUserPermissionsErrors( 'bogus',
499 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
500 array( 'protectedpagetext', 'protect' ),
501 array( 'protectedpagetext', 'protect' ) ),
502 $this->title
->getUserPermissionsErrors( 'edit',
506 function testCascadingSourcesRestrictions() {
508 $wgUser = $this->user
;
509 $this->setTitle( NS_MAIN
, "test page" );
510 $this->setUserPerm( array( "edit", "bogus" ) );
512 $this->title
->mCascadeSources
= array( Title
::makeTitle( NS_MAIN
, "Bogus" ), Title
::makeTitle( NS_MAIN
, "UnBogus" ) );
513 $this->title
->mCascadingRestrictions
= array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
515 $this->assertEquals( false,
516 $this->title
->userCan( 'bogus' ) );
517 $this->assertEquals( array( array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ),
518 array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ) ),
519 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
521 $this->assertEquals( true,
522 $this->title
->userCan( 'edit' ) );
523 $this->assertEquals( array( ),
524 $this->title
->getUserPermissionsErrors( 'edit', $this->user
) );
528 function testActionPermissions() {
530 $wgUser = $this->user
;
532 $this->setUserPerm( array( "createpage" ) );
533 $this->setTitle( NS_MAIN
, "test page" );
534 $this->title
->mTitleProtection
['pt_create_perm'] = '';
535 $this->title
->mTitleProtection
['pt_user'] = $this->user
->getID();
536 $this->title
->mTitleProtection
['pt_expiry'] = Block
::infinity();
537 $this->title
->mTitleProtection
['pt_reason'] = 'test';
538 $this->title
->mCascadeRestriction
= false;
540 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
541 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
542 $this->assertEquals( false,
543 $this->title
->userCan( 'create' ) );
545 $this->title
->mTitleProtection
['pt_create_perm'] = 'sysop';
546 $this->setUserPerm( array( 'createpage', 'protect' ) );
547 $this->assertEquals( array( ),
548 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
549 $this->assertEquals( true,
550 $this->title
->userCan( 'create' ) );
553 $this->setUserPerm( array( 'createpage' ) );
554 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
555 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
556 $this->assertEquals( false,
557 $this->title
->userCan( 'create' ) );
559 $this->setTitle( NS_MEDIA
, "test page" );
560 $this->setUserPerm( array( "move" ) );
561 $this->assertEquals( false,
562 $this->title
->userCan( 'move' ) );
563 $this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ),
564 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
566 $this->setTitle( NS_MAIN
, "test page" );
567 $this->assertEquals( array( ),
568 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
569 $this->assertEquals( true,
570 $this->title
->userCan( 'move' ) );
572 $this->title
->mInterwiki
= "no";
573 $this->assertEquals( array( array( 'immobile-page' ) ),
574 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
575 $this->assertEquals( false,
576 $this->title
->userCan( 'move' ) );
578 $this->setTitle( NS_MEDIA
, "test page" );
579 $this->assertEquals( false,
580 $this->title
->userCan( 'move-target' ) );
581 $this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ),
582 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
584 $this->setTitle( NS_MAIN
, "test page" );
585 $this->assertEquals( array( ),
586 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
587 $this->assertEquals( true,
588 $this->title
->userCan( 'move-target' ) );
590 $this->title
->mInterwiki
= "no";
591 $this->assertEquals( array( array( 'immobile-target-page' ) ),
592 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
593 $this->assertEquals( false,
594 $this->title
->userCan( 'move-target' ) );
598 function testUserBlock() {
599 global $wgUser, $wgEmailConfirmToEdit, $wgEmailAuthentication;
600 $wgEmailConfirmToEdit = true;
601 $wgEmailAuthentication = true;
602 $wgUser = $this->user
;
604 $this->setUserPerm( array( "createpage", "move" ) );
605 $this->setTitle( NS_MAIN
, "test page" );
608 $this->assertEquals( array( array( 'confirmedittext' ) ),
609 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
610 $wgEmailConfirmToEdit = false;
611 $this->assertEquals( true, $this->title
->userCan( 'move-target' ) );
613 # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
614 $this->assertEquals( array( ),
615 $this->title
->getUserPermissionsErrors( 'move-target',
621 $this->user
->mBlockedby
= $this->user
->getId();
622 $this->user
->mBlock
= new Block( '127.0.8.1', $this->user
->getId(), $this->user
->getId(),
623 'no reason given', $prev +
3600, 1, 0 );
624 $this->user
->mBlock
->mTimestamp
= 0;
625 $this->assertEquals( array( array( 'autoblockedtext',
626 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
627 'Useruser', null, 'infinite', '127.0.8.1',
628 $wgLang->timeanddate( wfTimestamp( TS_MW
, $prev ), true ) ) ),
629 $this->title
->getUserPermissionsErrors( 'move-target',
632 $this->assertEquals( false, $this->title
->userCan( 'move-target' ) );
633 // quickUserCan should ignore user blocks
634 $this->assertEquals( true, $this->title
->quickUserCan( 'move-target' ) );
636 global $wgLocalTZoffset;
637 $wgLocalTZoffset = -60;
638 $this->user
->mBlockedby
= $this->user
->getName();
639 $this->user
->mBlock
= new Block( '127.0.8.1', 2, 1, 'no reason given', $now, 0, 10 );
640 $this->assertEquals( array( array( 'blockedtext',
641 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
642 'Useruser', null, '23:00, 31 December 1969', '127.0.8.1',
643 $wgLang->timeanddate( wfTimestamp( TS_MW
, $now ), true ) ) ),
644 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
646 # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
647 # $user->blockedFor() == ''
648 # $user->mBlock->mExpiry == 'infinity'