6 class TitlePermissionTest
extends MediaWikiLangTestCase
{
13 protected $altUserName;
16 global $wgLocaltimezone, $wgLocalTZoffset, $wgMemc, $wgContLang, $wgLang;
20 $wgMemc = new EmptyBagOStuff
;
22 $wgContLang = $wgLang = Language
::factory( 'en' );
24 $this->userName
= "Useruser";
25 $this->altUserName
= "Altuseruser";
26 date_default_timezone_set( $wgLocaltimezone );
27 $wgLocalTZoffset = date( "Z" ) / 60;
29 $this->title
= Title
::makeTitle( NS_MAIN
, "Main Page" );
30 if ( !isset( $this->userUser
) ||
!( $this->userUser
instanceOf User
) ) {
31 $this->userUser
= User
::newFromName( $this->userName
);
33 if ( !$this->userUser
->getID() ) {
34 $this->userUser
= User
::createNew( $this->userName
, array(
35 "email" => "test@example.com",
36 "real_name" => "Test User" ) );
37 $this->userUser
->load();
40 $this->altUser
= User
::newFromName( $this->altUserName
);
41 if ( !$this->altUser
->getID() ) {
42 $this->altUser
= User
::createNew( $this->altUserName
, array(
43 "email" => "alttest@example.com",
44 "real_name" => "Test User Alt" ) );
45 $this->altUser
->load();
48 $this->anonUser
= User
::newFromId( 0 );
50 $this->user
= $this->userUser
;
58 function setUserPerm( $perm ) {
59 if ( is_array( $perm ) ) {
60 $this->user
->mRights
= $perm;
62 $this->user
->mRights
= array( $perm );
66 function setTitle( $ns, $title = "Main_Page" ) {
67 $this->title
= Title
::makeTitle( $ns, $title );
70 function setUser( $userName = null ) {
71 if ( $userName === 'anon' ) {
72 $this->user
= $this->anonUser
;
73 } elseif ( $userName === null ||
$userName === $this->userName
) {
74 $this->user
= $this->userUser
;
76 $this->user
= $this->altUser
;
80 $wgUser = $this->user
;
83 function testQuickPermissions() {
85 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT
);
87 $this->setUser( 'anon' );
88 $this->setTitle( NS_TALK
);
89 $this->setUserPerm( "createtalk" );
90 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
91 $this->assertEquals( array(), $res );
93 $this->setTitle( NS_TALK
);
94 $this->setUserPerm( "createpage" );
95 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
96 $this->assertEquals( array( array( "nocreatetext" ) ), $res );
98 $this->setTitle( NS_TALK
);
99 $this->setUserPerm( "" );
100 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
101 $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
103 $this->setTitle( NS_MAIN
);
104 $this->setUserPerm( "createpage" );
105 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
106 $this->assertEquals( array( ), $res );
108 $this->setTitle( NS_MAIN
);
109 $this->setUserPerm( "createtalk" );
110 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
111 $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
113 $this->setUser( $this->userName
);
114 $this->setTitle( NS_TALK
);
115 $this->setUserPerm( "createtalk" );
116 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
117 $this->assertEquals( array( ), $res );
119 $this->setTitle( NS_TALK
);
120 $this->setUserPerm( "createpage" );
121 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
122 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
124 $this->setTitle( NS_TALK
);
125 $this->setUserPerm( "" );
126 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
127 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
129 $this->setTitle( NS_MAIN
);
130 $this->setUserPerm( "createpage" );
131 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
132 $this->assertEquals( array( ), $res );
134 $this->setTitle( NS_MAIN
);
135 $this->setUserPerm( "createtalk" );
136 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
137 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
139 $this->setTitle( NS_MAIN
);
140 $this->setUserPerm( "" );
141 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
142 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
144 $this->setUser( 'anon' );
145 $this->setTitle( NS_USER
, $this->userName
. '' );
146 $this->setUserPerm( "" );
147 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
148 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
150 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
151 $this->setUserPerm( "" );
152 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
153 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
155 $this->setTitle( NS_USER
, $this->userName
. '' );
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
. '/subpage' );
161 $this->setUserPerm( "move-rootuserpages" );
162 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
163 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
165 $this->setTitle( NS_USER
, $this->userName
. '' );
166 $this->setUserPerm( "" );
167 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
168 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
170 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
171 $this->setUserPerm( "" );
172 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
173 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
175 $this->setTitle( NS_USER
, $this->userName
. '' );
176 $this->setUserPerm( "move-rootuserpages" );
177 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
178 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
180 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
181 $this->setUserPerm( "move-rootuserpages" );
182 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
183 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
185 $this->setUser( $this->userName
);
186 $this->setTitle( NS_FILE
, "img.png" );
187 $this->setUserPerm( "" );
188 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
189 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ), $res );
191 $this->setTitle( NS_FILE
, "img.png" );
192 $this->setUserPerm( "movefile" );
193 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
194 $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
196 $this->setUser( 'anon' );
197 $this->setTitle( NS_FILE
, "img.png" );
198 $this->setUserPerm( "" );
199 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
200 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ), $res );
202 $this->setTitle( NS_FILE
, "img.png" );
203 $this->setUserPerm( "movefile" );
204 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
205 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
207 $this->setUser( $this->userName
);
208 $this->setUserPerm( "move" );
209 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
211 $this->setUserPerm( "" );
212 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ) );
214 $this->setUser( 'anon' );
215 $this->setUserPerm( "move" );
216 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
218 $this->setUserPerm( "" );
219 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ),
220 array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ) );
222 $this->setTitle( NS_MAIN
);
223 $this->setUser( 'anon' );
224 $this->setUserPerm( "move" );
225 $this->runGroupPermissions( 'move', array( ) );
227 $this->setUserPerm( "" );
228 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ),
229 array( array( 'movenologintext' ) ) );
231 $this->setUser( $this->userName
);
232 $this->setUserPerm( "" );
233 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ) );
235 $this->setUserPerm( "move" );
236 $this->runGroupPermissions( 'move', array( ) );
238 $this->setUser( 'anon' );
239 $this->setUserPerm( 'move' );
240 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
241 $this->assertEquals( array( ), $res );
243 $this->setUserPerm( '' );
244 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
245 $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
247 $this->setTitle( NS_USER
);
248 $this->setUser( $this->userName
);
249 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
250 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
251 $this->assertEquals( array( ), $res );
253 $this->setUserPerm( "move" );
254 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
255 $this->assertEquals( array( array( 'cant-move-to-user-page' ) ), $res );
257 $this->setUser( 'anon' );
258 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
259 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
260 $this->assertEquals( array( ), $res );
262 $this->setTitle( NS_USER
, "User/subpage" );
263 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
264 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
265 $this->assertEquals( array( ), $res );
267 $this->setUserPerm( "move" );
268 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
269 $this->assertEquals( array( ), $res );
271 $this->setUser( 'anon' );
272 $check = array( 'edit' => array( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ) ),
273 array( array( 'badaccess-group0' ) ),
275 'protect' => array( array( array( 'badaccess-groups', "[[$prefix:Administrators|Administrators]]", 1 ), array( 'protect-cantedit' ) ),
276 array( array( 'badaccess-group0' ), array( 'protect-cantedit' ) ),
277 array( array( 'protect-cantedit' ) ), false ),
278 '' => array( array( ), array( ), array( ), true ) );
280 $wgUser = $this->user
;
281 foreach ( array( "edit", "protect", "" ) as $action ) {
282 $this->setUserPerm( null );
283 $this->assertEquals( $check[$action][0],
284 $this->title
->getUserPermissionsErrors( $action, $this->user
, true ) );
286 global $wgGroupPermissions;
287 $old = $wgGroupPermissions;
288 $wgGroupPermissions = array();
290 $this->assertEquals( $check[$action][1],
291 $this->title
->getUserPermissionsErrors( $action, $this->user
, true ) );
292 $wgGroupPermissions = $old;
294 $this->setUserPerm( $action );
295 $this->assertEquals( $check[$action][2],
296 $this->title
->getUserPermissionsErrors( $action, $this->user
, true ) );
298 $this->setUserPerm( $action );
299 $this->assertEquals( $check[$action][3],
300 $this->title
->userCan( $action, true ) );
301 $this->assertEquals( $check[$action][3],
302 $this->title
->quickUserCan( $action, false ) );
304 # count( User::getGroupsWithPermissions( $action ) ) < 1
308 function runGroupPermissions( $action, $result, $result2 = null ) {
309 global $wgGroupPermissions;
311 if ( $result2 === null ) $result2 = $result;
313 $wgGroupPermissions['autoconfirmed']['move'] = false;
314 $wgGroupPermissions['user']['move'] = false;
315 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
316 $this->assertEquals( $result, $res );
318 $wgGroupPermissions['autoconfirmed']['move'] = true;
319 $wgGroupPermissions['user']['move'] = false;
320 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
321 $this->assertEquals( $result2, $res );
323 $wgGroupPermissions['autoconfirmed']['move'] = true;
324 $wgGroupPermissions['user']['move'] = true;
325 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
326 $this->assertEquals( $result2, $res );
328 $wgGroupPermissions['autoconfirmed']['move'] = false;
329 $wgGroupPermissions['user']['move'] = true;
330 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
331 $this->assertEquals( $result2, $res );
334 function testSpecialsAndNSPermissions() {
335 $this->setUser( $this->userName
);
337 $wgUser = $this->user
;
339 $this->setTitle( NS_SPECIAL
);
341 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'ns-specialprotected' ) ),
342 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
343 $this->assertEquals( array( array( 'badaccess-group0' ) ),
344 $this->title
->getUserPermissionsErrors( 'execute', $this->user
) );
346 $this->setTitle( NS_MAIN
);
347 $this->setUserPerm( 'bogus' );
348 $this->assertEquals( array( ),
349 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
351 $this->setTitle( NS_MAIN
);
352 $this->setUserPerm( '' );
353 $this->assertEquals( array( array( 'badaccess-group0' ) ),
354 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
356 global $wgNamespaceProtection;
357 $wgNamespaceProtection[NS_USER
] = array ( 'bogus' );
358 $this->setTitle( NS_USER
);
359 $this->setUserPerm( '' );
360 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'namespaceprotected', 'User' ) ),
361 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
363 $this->setTitle( NS_MEDIAWIKI
);
364 $this->setUserPerm( 'bogus' );
365 $this->assertEquals( array( array( 'protectedinterface' ) ),
366 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
368 $this->setTitle( NS_MEDIAWIKI
);
369 $this->setUserPerm( 'bogus' );
370 $this->assertEquals( array( array( 'protectedinterface' ) ),
371 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
373 $wgNamespaceProtection = null;
374 $this->setUserPerm( 'bogus' );
375 $this->assertEquals( array( ),
376 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
377 $this->assertEquals( true,
378 $this->title
->userCan( 'bogus' ) );
380 $this->setUserPerm( '' );
381 $this->assertEquals( array( array( 'badaccess-group0' ) ),
382 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
383 $this->assertEquals( false,
384 $this->title
->userCan( 'bogus' ) );
387 function testCSSandJSPermissions() {
388 $this->setUser( $this->userName
);
390 $wgUser = $this->user
;
392 $this->setTitle( NS_USER
, $this->altUserName
. '/test.js' );
393 $this->runCSSandJSPermissions(
394 array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
395 array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
396 array( array( 'badaccess-group0' ) ) );
398 $this->setTitle( NS_USER
, $this->altUserName
. '/test.css' );
399 $this->runCSSandJSPermissions(
400 array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ),
401 array( array( 'badaccess-group0' ) ),
402 array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ) );
404 $this->setTitle( NS_USER
, $this->altUserName
. '/tempo' );
405 $this->runCSSandJSPermissions(
406 array( array( 'badaccess-group0' ) ),
407 array( array( 'badaccess-group0' ) ),
408 array( array( 'badaccess-group0' ) ) );
411 function runCSSandJSPermissions( $result0, $result1, $result2 ) {
412 $this->setUserPerm( '' );
413 $this->assertEquals( $result0,
414 $this->title
->getUserPermissionsErrors( 'bogus',
417 $this->setUserPerm( 'editusercss' );
418 $this->assertEquals( $result1,
419 $this->title
->getUserPermissionsErrors( 'bogus',
422 $this->setUserPerm( 'edituserjs' );
423 $this->assertEquals( $result2,
424 $this->title
->getUserPermissionsErrors( 'bogus',
427 $this->setUserPerm( 'editusercssjs' );
428 $this->assertEquals( array( array( 'badaccess-group0' ) ),
429 $this->title
->getUserPermissionsErrors( 'bogus',
432 $this->setUserPerm( array( 'edituserjs', 'editusercss' ) );
433 $this->assertEquals( array( array( 'badaccess-group0' ) ),
434 $this->title
->getUserPermissionsErrors( 'bogus',
438 function testPageRestrictions() {
439 global $wgUser, $wgContLang;
441 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT
);
443 $wgUser = $this->user
;
444 $this->setTitle( NS_MAIN
);
445 $this->title
->mRestrictionsLoaded
= true;
446 $this->setUserPerm( "edit" );
447 $this->title
->mRestrictions
= array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
449 $this->assertEquals( array( ),
450 $this->title
->getUserPermissionsErrors( 'edit',
453 $this->assertEquals( true,
454 $this->title
->quickUserCan( 'edit', false ) );
455 $this->title
->mRestrictions
= array( "edit" => array( 'bogus', "sysop", "protect", "" ),
456 "bogus" => array( 'bogus', "sysop", "protect", "" ) );
458 $this->assertEquals( array( array( 'badaccess-group0' ),
459 array( 'protectedpagetext', 'bogus' ),
460 array( 'protectedpagetext', 'protect' ),
461 array( 'protectedpagetext', 'protect' ) ),
462 $this->title
->getUserPermissionsErrors( 'bogus',
464 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
465 array( 'protectedpagetext', 'protect' ),
466 array( 'protectedpagetext', 'protect' ) ),
467 $this->title
->getUserPermissionsErrors( 'edit',
469 $this->setUserPerm( "" );
470 $this->assertEquals( array( array( 'badaccess-group0' ),
471 array( 'protectedpagetext', 'bogus' ),
472 array( 'protectedpagetext', 'protect' ),
473 array( 'protectedpagetext', 'protect' ) ),
474 $this->title
->getUserPermissionsErrors( 'bogus',
476 $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ),
477 array( 'protectedpagetext', 'bogus' ),
478 array( 'protectedpagetext', 'protect' ),
479 array( 'protectedpagetext', 'protect' ) ),
480 $this->title
->getUserPermissionsErrors( 'edit',
482 $this->setUserPerm( array( "edit", "editprotected" ) );
483 $this->assertEquals( array( array( 'badaccess-group0' ),
484 array( 'protectedpagetext', 'bogus' ),
485 array( 'protectedpagetext', 'protect' ),
486 array( 'protectedpagetext', 'protect' ) ),
487 $this->title
->getUserPermissionsErrors( 'bogus',
489 $this->assertEquals( array( ),
490 $this->title
->getUserPermissionsErrors( 'edit',
492 $this->title
->mCascadeRestriction
= true;
493 $this->assertEquals( false,
494 $this->title
->quickUserCan( 'bogus', false ) );
495 $this->assertEquals( false,
496 $this->title
->quickUserCan( 'edit', false ) );
497 $this->assertEquals( array( array( 'badaccess-group0' ),
498 array( 'protectedpagetext', 'bogus' ),
499 array( 'protectedpagetext', 'protect' ),
500 array( 'protectedpagetext', 'protect' ) ),
501 $this->title
->getUserPermissionsErrors( 'bogus',
503 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
504 array( 'protectedpagetext', 'protect' ),
505 array( 'protectedpagetext', 'protect' ) ),
506 $this->title
->getUserPermissionsErrors( 'edit',
510 function testCascadingSourcesRestrictions() {
512 $wgUser = $this->user
;
513 $this->setTitle( NS_MAIN
, "test page" );
514 $this->setUserPerm( array( "edit", "bogus" ) );
516 $this->title
->mCascadeSources
= array( Title
::makeTitle( NS_MAIN
, "Bogus" ), Title
::makeTitle( NS_MAIN
, "UnBogus" ) );
517 $this->title
->mCascadingRestrictions
= array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
519 $this->assertEquals( false,
520 $this->title
->userCan( 'bogus' ) );
521 $this->assertEquals( array( array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ),
522 array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ) ),
523 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
525 $this->assertEquals( true,
526 $this->title
->userCan( 'edit' ) );
527 $this->assertEquals( array( ),
528 $this->title
->getUserPermissionsErrors( 'edit', $this->user
) );
532 function testActionPermissions() {
534 $wgUser = $this->user
;
536 $this->setUserPerm( array( "createpage" ) );
537 $this->setTitle( NS_MAIN
, "test page" );
538 $this->title
->mTitleProtection
['pt_create_perm'] = '';
539 $this->title
->mTitleProtection
['pt_user'] = $this->user
->getID();
540 $this->title
->mTitleProtection
['pt_expiry'] = Block
::infinity();
541 $this->title
->mTitleProtection
['pt_reason'] = 'test';
542 $this->title
->mCascadeRestriction
= false;
544 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
545 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
546 $this->assertEquals( false,
547 $this->title
->userCan( 'create' ) );
549 $this->title
->mTitleProtection
['pt_create_perm'] = 'sysop';
550 $this->setUserPerm( array( 'createpage', 'protect' ) );
551 $this->assertEquals( array( ),
552 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
553 $this->assertEquals( true,
554 $this->title
->userCan( 'create' ) );
557 $this->setUserPerm( array( 'createpage' ) );
558 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
559 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
560 $this->assertEquals( false,
561 $this->title
->userCan( 'create' ) );
563 $this->setTitle( NS_MEDIA
, "test page" );
564 $this->setUserPerm( array( "move" ) );
565 $this->assertEquals( false,
566 $this->title
->userCan( 'move' ) );
567 $this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ),
568 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
570 $this->setTitle( NS_MAIN
, "test page" );
571 $this->assertEquals( array( ),
572 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
573 $this->assertEquals( true,
574 $this->title
->userCan( 'move' ) );
576 $this->title
->mInterwiki
= "no";
577 $this->assertEquals( array( array( 'immobile-page' ) ),
578 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
579 $this->assertEquals( false,
580 $this->title
->userCan( 'move' ) );
582 $this->setTitle( NS_MEDIA
, "test page" );
583 $this->assertEquals( false,
584 $this->title
->userCan( 'move-target' ) );
585 $this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ),
586 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
588 $this->setTitle( NS_MAIN
, "test page" );
589 $this->assertEquals( array( ),
590 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
591 $this->assertEquals( true,
592 $this->title
->userCan( 'move-target' ) );
594 $this->title
->mInterwiki
= "no";
595 $this->assertEquals( array( array( 'immobile-target-page' ) ),
596 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
597 $this->assertEquals( false,
598 $this->title
->userCan( 'move-target' ) );
602 function testUserBlock() {
603 global $wgUser, $wgEmailConfirmToEdit, $wgEmailAuthentication;
604 $wgEmailConfirmToEdit = true;
605 $wgEmailAuthentication = true;
606 $wgUser = $this->user
;
608 $this->setUserPerm( array( "createpage", "move" ) );
609 $this->setTitle( NS_MAIN
, "test page" );
612 $this->assertEquals( array( array( 'confirmedittext' ) ),
613 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
614 $wgEmailConfirmToEdit = false;
615 $this->assertEquals( true, $this->title
->userCan( 'move-target' ) );
617 # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
618 $this->assertEquals( array( ),
619 $this->title
->getUserPermissionsErrors( 'move-target',
625 $this->user
->mBlockedby
= $this->user
->getId();
626 $this->user
->mBlock
= new Block( '127.0.8.1', $this->user
->getId(), $this->user
->getId(),
627 'no reason given', $prev +
3600, 1, 0 );
628 $this->user
->mBlock
->mTimestamp
= 0;
629 $this->assertEquals( array( array( 'autoblockedtext',
630 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
631 'Useruser', null, 'infinite', '127.0.8.1',
632 $wgLang->timeanddate( wfTimestamp( TS_MW
, $prev ), true ) ) ),
633 $this->title
->getUserPermissionsErrors( 'move-target',
636 $this->assertEquals( false, $this->title
->userCan( 'move-target' ) );
637 // quickUserCan should ignore user blocks
638 $this->assertEquals( true, $this->title
->quickUserCan( 'move-target' ) );
640 global $wgLocalTZoffset;
641 $wgLocalTZoffset = -60;
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 );
644 $this->assertEquals( array( array( 'blockedtext',
645 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
646 'Useruser', null, '23:00, 31 December 1969', '127.0.8.1',
647 $wgLang->timeanddate( wfTimestamp( TS_MW
, $now ), true ) ) ),
648 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
650 # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
651 # $user->blockedFor() == ''
652 # $user->mBlock->mExpiry == 'infinity'