3 class TitlePermissionTest
extends PhpUnit_Framework_TestCase
{
13 global $wgAutoloadLocalClasses;
14 self
::$userName = "Useruser";
15 self
::$altUserName = "Altuseruser";
17 self
::$title = Title
::makeTitle(NS_MAIN
, "Main Page");
18 self
::$userUser = User
::newFromName(self
::$userName);
19 if ( !self
::$userUser->getID() ) {
20 self
::$userUser = User
::createNew(self
::$userName, array(
21 "email" => "test@example.com",
22 "real_name" => "Test User"));
25 self
::$altUser = User
::newFromName(self
::$altUserName);
26 if ( !self
::$altUser->getID() ) {
27 self
::$altUser = User
::createNew(self
::$altUserName, array(
28 "email" => "alttest@example.com",
29 "real_name" => "Test User Alt"));
32 self
::$anonUser = User
::newFromId(0);
34 self
::$user = self
::$userUser;
38 function setUserPerm( $perm ) {
39 global $wgUseRCPatrol, $wgUseNPPatrol;
40 if( is_array( $perm ) ) {
41 self
::$user->mRights
= $perm;
43 self
::$user->mRights
= array($perm);
47 function setTitle( $ns, $title = "Main_Page" ) {
48 self
::$title = Title
::makeTitle($ns, $title);
51 function setUser( $userName = null ) {
52 if ( $userName === 'anon' ) {
53 self
::$user = self
::$anonUser;
54 } else if ( $userName === null ||
$userName === self
::$userName ) {
55 self
::$user = self
::$userUser;
57 self
::$user = self
::$altUser;
61 function testQuickPermissions() {
62 $this->setUser( 'anon' );
63 $this->setTitle( NS_TALK
);
64 $this->setUserPerm( "createtalk" );
65 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
66 $this->assertEquals( array(), $res);
68 $this->setTitle( NS_TALK
);
69 $this->setUserPerm( "createpage" );
70 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
71 $this->assertEquals( array( array( "nocreatetext") ), $res);
73 $this->setTitle( NS_TALK
);
74 $this->setUserPerm( "" );
75 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
76 $this->assertEquals( array( array( 'nocreatetext' ) ), $res);
78 $this->setTitle( NS_MAIN
);
79 $this->setUserPerm( "createpage" );
80 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
81 $this->assertEquals( array( ), $res);
83 $this->setTitle( NS_MAIN
);
84 $this->setUserPerm( "createtalk" );
85 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
86 $this->assertEquals( array( array( 'nocreatetext' ) ), $res);
88 $this->setUser( self
::$userName );
89 $this->setTitle( NS_TALK
);
90 $this->setUserPerm( "createtalk" );
91 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
92 $this->assertEquals( array( ), $res);
94 $this->setTitle( NS_TALK
);
95 $this->setUserPerm( "createpage" );
96 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
97 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res);
99 $this->setTitle( NS_TALK
);
100 $this->setUserPerm( "" );
101 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
102 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res);
104 $this->setTitle( NS_MAIN
);
105 $this->setUserPerm( "createpage" );
106 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
107 $this->assertEquals( array( ), $res);
109 $this->setTitle( NS_MAIN
);
110 $this->setUserPerm( "createtalk" );
111 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
112 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res);
114 $this->setTitle( NS_MAIN
);
115 $this->setUserPerm( "" );
116 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
117 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res);
119 $this->setUser( 'anon' );
120 $this->setTitle( NS_USER
, self
::$userName . '' );
121 $this->setUserPerm( "" );
122 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
123 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res);
125 $this->setTitle( NS_USER
, self
::$userName . '/subpage' );
126 $this->setUserPerm( "" );
127 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
128 $this->assertEquals( array( array( 'movenologintext' ) ), $res);
130 $this->setTitle( NS_USER
, self
::$userName . '' );
131 $this->setUserPerm( "move-rootuserpages" );
132 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
133 $this->assertEquals( array( array( 'movenologintext' ) ), $res);
135 $this->setTitle( NS_USER
, self
::$userName . '/subpage' );
136 $this->setUserPerm( "move-rootuserpages" );
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( "" );
142 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
143 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res);
145 $this->setTitle( NS_USER
, self
::$userName . '/subpage' );
146 $this->setUserPerm( "" );
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( "move-rootuserpages" );
152 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
153 $this->assertEquals( array( array( 'movenologintext' ) ), $res);
155 $this->setTitle( NS_USER
, self
::$userName . '/subpage' );
156 $this->setUserPerm( "move-rootuserpages" );
157 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
158 $this->assertEquals(array( array( 'movenologintext' ) ), $res);
160 $this->setUser( self
::$userName );
161 $this->setTitle( NS_FILE
, "img.png" );
162 $this->setUserPerm( "" );
163 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
164 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ), $res);
166 $this->setTitle( NS_FILE
, "img.png" );
167 $this->setUserPerm( "movefile" );
168 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
169 $this->assertEquals( array( array( 'movenotallowed' ) ), $res);
171 $this->setUser( 'anon' );
172 $this->setTitle( NS_FILE
, "img.png" );
173 $this->setUserPerm( "" );
174 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
175 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ), $res);
177 $this->setTitle( NS_FILE
, "img.png" );
178 $this->setUserPerm( "movefile" );
179 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
180 $this->assertEquals( array( array( 'movenologintext' ) ), $res);
182 $this->setUser( self
::$userName );
183 $this->setUserPerm( "move" );
184 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
186 $this->setUserPerm( "" );
187 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ) );
189 $this->setUser( 'anon' );
190 $this->setUserPerm( "move" );
191 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
193 $this->setUserPerm( "" );
194 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ),
195 array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ) );
197 $this->setTitle( NS_MAIN
);
198 $this->setUser( 'anon' );
199 $this->setUserPerm( "move" );
200 $this->runGroupPermissions( 'move', array( ) );
202 $this->setUserPerm( "" );
203 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ),
204 array( array( 'movenologintext' ) ) );
206 $this->setUser( self
::$userName );
207 $this->setUserPerm( "" );
208 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ) );
210 $this->setUserPerm( "move" );
211 $this->runGroupPermissions( 'move', array( ) );
213 $this->setUser( 'anon' );
214 $this->setUserPerm( 'move' );
215 $res = self
::$title->getUserPermissionsErrors( 'move-target', self
::$user );
216 $this->assertEquals( array( ), $res );
218 $this->setUserPerm( '' );
219 $res = self
::$title->getUserPermissionsErrors( 'move-target', self
::$user );
220 $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
222 $this->setTitle( NS_USER
);
223 $this->setUser( self
::$userName );
224 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
225 $res = self
::$title->getUserPermissionsErrors( 'move-target', self
::$user );
226 $this->assertEquals( array( ), $res );
228 $this->setUserPerm( "move" );
229 $res = self
::$title->getUserPermissionsErrors( 'move-target', self
::$user );
230 $this->assertEquals( array( array( 'cant-move-to-user-page' ) ), $res );
232 $this->setUser( 'anon' );
233 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
234 $res = self
::$title->getUserPermissionsErrors( 'move-target', self
::$user );
235 $this->assertEquals( array( ), $res );
237 $this->setTitle( NS_USER
, "User/subpage" );
238 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
239 $res = self
::$title->getUserPermissionsErrors( 'move-target', self
::$user );
240 $this->assertEquals( array( ), $res );
242 $this->setUserPerm( "move" );
243 $res = self
::$title->getUserPermissionsErrors( 'move-target', self
::$user );
244 $this->assertEquals( array( ), $res );
246 $this->setUser( 'anon' );
247 $check = array( 'edit' => array( array( array( 'badaccess-groups', "*, [[Mw:Users|Users]]", 2 ) ),
248 array( array( 'badaccess-group0' ) ),
250 'protect' => array( array( array( 'badaccess-groups', "[[Mw:Administrators|Administrators]]", 1 ), array( 'protect-cantedit' ) ),
251 array( array( 'badaccess-group0' ), array( 'protect-cantedit' ) ),
252 array( array( 'protect-cantedit' ) ), false ),
253 '' => array( array( ), array( ), array( ), true ) );
255 $wgUser = self
::$user;
256 foreach(array("edit", "protect", "") as $action) {
257 $this->setUserPerm( null );
258 $this->assertEquals( $check[$action][0],
259 self
::$title->getUserPermissionsErrors( $action, self
::$user, true ) );
261 global $wgGroupPermissions;
262 $old = $wgGroupPermissions;
263 $wgGroupPermissions = array();
265 $this->assertEquals( $check[$action][1],
266 self
::$title->getUserPermissionsErrors( $action, self
::$user, true ) );
267 $wgGroupPermissions = $old;
269 $this->setUserPerm( $action );
270 $this->assertEquals( $check[$action][2],
271 self
::$title->getUserPermissionsErrors( $action, self
::$user, true ) );
273 $this->setUserPerm( $action );
274 $this->assertEquals( $check[$action][3],
275 self
::$title->userCan( $action, true ) );
276 $this->assertEquals( $check[$action][3],
277 self
::$title->quickUserCan( $action, false ) );
279 # count( User::getGroupsWithPermissions( $action ) ) < 1
283 function runGroupPermissions( $action, $result, $result2 = null ) {
284 global $wgGroupPermissions;
286 if( $result2 === null ) $result2 = $result;
288 $wgGroupPermissions['autoconfirmed']['move'] = false;
289 $wgGroupPermissions['user']['move'] = false;
290 $res = self
::$title->getUserPermissionsErrors( $action, self
::$user );
291 $this->assertEquals( $result, $res );
293 $wgGroupPermissions['autoconfirmed']['move'] = true;
294 $wgGroupPermissions['user']['move'] = false;
295 $res = self
::$title->getUserPermissionsErrors( $action, self
::$user );
296 $this->assertEquals( $result2, $res );
298 $wgGroupPermissions['autoconfirmed']['move'] = true;
299 $wgGroupPermissions['user']['move'] = true;
300 $res = self
::$title->getUserPermissionsErrors( $action, self
::$user );
301 $this->assertEquals( $result2, $res );
303 $wgGroupPermissions['autoconfirmed']['move'] = false;
304 $wgGroupPermissions['user']['move'] = true;
305 $res = self
::$title->getUserPermissionsErrors( $action, self
::$user );
306 $this->assertEquals( $result2, $res );
309 function testPermissionHooks() {}
310 function testSpecialsAndNSPermissions() {
311 $this->setUser( self
::$userName );
313 $wgUser = self
::$user;
315 $this->setTitle( NS_SPECIAL
);
317 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'ns-specialprotected' ) ),
318 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
319 $this->assertEquals( array( ),
320 self
::$title->getUserPermissionsErrors( 'createaccount', self
::$user ) );
321 $this->assertEquals( array( array( 'badaccess-group0' ) ),
322 self
::$title->getUserPermissionsErrors( 'execute', self
::$user ) );
324 $this->setTitle( NS_MAIN
);
325 $this->setUserPerm( 'bogus' );
326 $this->assertEquals( array( ),
327 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
329 $this->setTitle( NS_MAIN
);
330 $this->setUserPerm( '' );
331 $this->assertEquals( array( array( 'badaccess-group0' ) ),
332 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
334 global $wgNamespaceProtection;
335 $wgNamespaceProtection[NS_USER
] = array ( 'bogus' );
336 $this->setTitle( NS_USER
);
337 $this->setUserPerm( '' );
338 $this->assertEquals( array( array( 'badaccess-group0'), array( 'namespaceprotected', 'User' ) ),
339 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
341 $this->setTitle( NS_MEDIAWIKI
);
342 $this->setUserPerm( 'bogus' );
343 $this->assertEquals( array( array( 'protectedinterface' ) ),
344 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
346 $this->setTitle( NS_MEDIAWIKI
);
347 $this->setUserPerm( 'bogus' );
348 $this->assertEquals( array( array( 'protectedinterface' ) ),
349 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
351 $wgNamespaceProtection = null;
352 $this->setUserPerm( 'bogus' );
353 $this->assertEquals( array( ),
354 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
355 $this->assertEquals( true,
356 self
::$title->userCan( 'bogus' ) );
358 $this->setUserPerm( '' );
359 $this->assertEquals( array( array( 'badaccess-group0' ) ),
360 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
361 $this->assertEquals( false,
362 self
::$title->userCan( 'bogus' ) );
365 function testCSSandJSPermissions() {
366 $this->setUser( self
::$userName );
368 $wgUser = self
::$user;
370 $this->setTitle( NS_USER
, self
::$altUserName .'/test.js' );
371 $this->runCSSandJSPermissions(
372 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
373 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
374 array( array( 'badaccess-group0' ) ) );
376 $this->setTitle( NS_USER
, self
::$altUserName .'/test.css' );
377 $this->runCSSandJSPermissions(
378 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
379 array( array( 'badaccess-group0' ) ),
380 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ) );
382 $this->setTitle( NS_USER
, self
::$altUserName .'/tempo' );
383 $this->runCSSandJSPermissions(
384 array( array( 'badaccess-group0' ) ),
385 array( array( 'badaccess-group0' ) ),
386 array( array( 'badaccess-group0' ) ) );
389 function runCSSandJSPermissions( $result0, $result1, $result2 ) {
390 $this->setUserPerm( '' );
391 $this->assertEquals( $result0,
392 self
::$title->getUserPermissionsErrors( 'bogus',
395 $this->setUserPerm( 'editusercss' );
396 $this->assertEquals( $result1,
397 self
::$title->getUserPermissionsErrors( 'bogus',
400 $this->setUserPerm( 'edituserjs' );
401 $this->assertEquals( $result2,
402 self
::$title->getUserPermissionsErrors( 'bogus',
405 $this->setUserPerm( 'editusercssjs' );
406 $this->assertEquals( array( array( 'badaccess-group0' ) ),
407 self
::$title->getUserPermissionsErrors( 'bogus',
410 $this->setUserPerm( array( 'edituserjs', 'editusercss' ) );
411 $this->assertEquals( array( array( 'badaccess-group0' ) ),
412 self
::$title->getUserPermissionsErrors( 'bogus',
416 function testPageRestrictions() {
418 $wgUser = self
::$user;
419 $this->setTitle( NS_MAIN
);
420 self
::$title->mRestrictionsLoaded
= true;
421 $this->setUserPerm("edit");
422 self
::$title->mRestrictions
= array("bogus" => array('bogus', "sysop", "protect", ""));
424 $this->assertEquals( array( ),
425 self
::$title->getUserPermissionsErrors( 'edit',
428 $this->assertEquals( true,
429 self
::$title->quickUserCan( 'edit', false ) );
430 self
::$title->mRestrictions
= array("edit" => array('bogus', "sysop", "protect", ""),
431 "bogus" => array('bogus', "sysop", "protect", ""));
433 $this->assertEquals( array( array( 'badaccess-group0' ),
434 array( 'protectedpagetext', 'bogus' ),
435 array( 'protectedpagetext', 'protect' ),
436 array( 'protectedpagetext', 'protect' ) ),
437 self
::$title->getUserPermissionsErrors( 'bogus',
439 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
440 array( 'protectedpagetext', 'protect' ),
441 array( 'protectedpagetext', 'protect' ) ),
442 self
::$title->getUserPermissionsErrors( 'edit',
444 $this->setUserPerm("");
445 $this->assertEquals( array( array( 'badaccess-group0' ),
446 array( 'protectedpagetext', 'bogus' ),
447 array( 'protectedpagetext', 'protect' ),
448 array( 'protectedpagetext', 'protect' ) ),
449 self
::$title->getUserPermissionsErrors( 'bogus',
451 $this->assertEquals( array( array( 'badaccess-groups', '*, [[Mw:Users|Users]]', 2 ),
452 array( 'protectedpagetext', 'bogus' ),
453 array( 'protectedpagetext', 'protect' ),
454 array( 'protectedpagetext', 'protect' ) ),
455 self
::$title->getUserPermissionsErrors( 'edit',
457 $this->setUserPerm(array("edit", "editprotected") );
458 $this->assertEquals( array( array( 'badaccess-group0' ),
459 array( 'protectedpagetext', 'bogus' ),
460 array( 'protectedpagetext', 'protect' ),
461 array( 'protectedpagetext', 'protect' ) ),
462 self
::$title->getUserPermissionsErrors( 'bogus',
464 $this->assertEquals( array( ),
465 self
::$title->getUserPermissionsErrors( 'edit',
467 self
::$title->mCascadeRestriction
= true;
468 $this->assertEquals( false,
469 self
::$title->quickUserCan( 'bogus', false ) );
470 $this->assertEquals( false,
471 self
::$title->quickUserCan( 'edit', false ) );
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( array( 'protectedpagetext', 'bogus' ),
479 array( 'protectedpagetext', 'protect' ),
480 array( 'protectedpagetext', 'protect' ) ),
481 self
::$title->getUserPermissionsErrors( 'edit',
485 function testCascadingSourcesRestrictions() {
487 $wgUser = self
::$user;
488 $this->setTitle(NS_MAIN
, "test page");
489 $this->setUserPerm(array("edit", "bogus"));
491 self
::$title->mCascadeSources
= array( Title
::makeTitle(NS_MAIN
, "Bogus"), Title
::makeTitle(NS_MAIN
, "UnBogus") );
492 self
::$title->mCascadingRestrictions
= array( "bogus" => array('bogus', "sysop", "protect", "" ) );
494 $this->assertEquals( false,
495 self
::$title->userCan( 'bogus' ) );
496 $this->assertEquals( array( array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ),
497 array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ) ),
498 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
500 $this->assertEquals( true,
501 self
::$title->userCan( 'edit' ) );
502 $this->assertEquals( array( ),
503 self
::$title->getUserPermissionsErrors( 'edit', self
::$user ) );
507 function testActionPermissions() {
509 $wgUser = self
::$user;
511 $this->setUserPerm( array( "createpage" ) );
512 $this->setTitle(NS_MAIN
, "test page");
513 self
::$title->mTitleProtection
['pt_create_perm'] = '';
514 self
::$title->mTitleProtection
['pt_user'] = 1;
515 self
::$title->mTitleProtection
['pt_expiry'] = Block
::infinity();
516 self
::$title->mTitleProtection
['pt_reason'] = 'test';
517 self
::$title->mCascadeRestriction
= false;
519 $this->assertEquals( array( array( 'titleprotected', 'WikiSysop', 'test' ) ),
520 self
::$title->getUserPermissionsErrors( 'create', self
::$user ) );
521 $this->assertEquals( false,
522 self
::$title->userCan( 'create' ) );
524 self
::$title->mTitleProtection
['pt_create_perm'] = 'sysop';
525 $this->setUserPerm( array( 'createpage', 'protect' ) );
526 $this->assertEquals( array( ),
527 self
::$title->getUserPermissionsErrors( 'create', self
::$user ) );
528 $this->assertEquals( true,
529 self
::$title->userCan( 'create' ) );
532 $this->setUserPerm( array( 'createpage' ) );
533 $this->assertEquals( array( array( 'titleprotected', 'WikiSysop', 'test' ) ),
534 self
::$title->getUserPermissionsErrors( 'create', self
::$user ) );
535 $this->assertEquals( false,
536 self
::$title->userCan( 'create' ) );
538 $this->setTitle( NS_MEDIA
, "test page" );
539 $this->setUserPerm( array( "move" ) );
540 $this->assertEquals( false,
541 self
::$title->userCan( 'move' ) );
542 $this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ),
543 self
::$title->getUserPermissionsErrors( 'move', self
::$user ) );
545 $this->setTitle( NS_MAIN
, "test page" );
546 $this->assertEquals( array( ),
547 self
::$title->getUserPermissionsErrors( 'move', self
::$user ) );
548 $this->assertEquals( true,
549 self
::$title->userCan( 'move' ) );
551 self
::$title->mInterwiki
= "no";
552 $this->assertEquals( array( array( 'immobile-page' ) ),
553 self
::$title->getUserPermissionsErrors( 'move', self
::$user ) );
554 $this->assertEquals( false,
555 self
::$title->userCan( 'move' ) );
557 $this->setTitle( NS_MEDIA
, "test page" );
558 $this->assertEquals( false,
559 self
::$title->userCan( 'move-target' ) );
560 $this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ),
561 self
::$title->getUserPermissionsErrors( 'move-target', self
::$user ) );
563 $this->setTitle( NS_MAIN
, "test page" );
564 $this->assertEquals( array( ),
565 self
::$title->getUserPermissionsErrors( 'move-target', self
::$user ) );
566 $this->assertEquals( true,
567 self
::$title->userCan( 'move-target' ) );
569 self
::$title->mInterwiki
= "no";
570 $this->assertEquals( array( array( 'immobile-target-page' ) ),
571 self
::$title->getUserPermissionsErrors( 'move-target', self
::$user ) );
572 $this->assertEquals( false,
573 self
::$title->userCan( 'move-target' ) );
577 function testUserBlock() {
578 global $wgUser, $wgEmailConfirmToEdit, $wgEmailAuthentication;
579 $wgEmailConfirmToEdit = true;
580 $wgEmailAuthentication = true;
581 $wgUser = self
::$user;
583 $this->setUserPerm( array( "createpage", "move" ) );
584 $this->setTitle(NS_MAIN
, "test page");
587 $this->assertEquals( array( array( 'confirmedittext' ) ),
588 self
::$title->getUserPermissionsErrors( 'move-target', self
::$user ) );
589 $this->assertEquals( true, self
::$title->userCan( 'move-target' ) );
591 $wgEmailConfirmToEdit = false;
592 # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
593 $this->assertEquals( array( ),
594 self
::$title->getUserPermissionsErrors( 'move-target',
597 self
::$user->mBlockedby
= 1;
598 self
::$user->mBlock
= new Block('127.0.8.1', 2, 1, 'no reason given', '888', 10);
599 $this->assertEquals( array( array( 'autoblockedtext',
600 '[[User:WikiSysop|WikiSysop]]', 'no reason given', '127.0.0.1',
601 'WikiSysop', 0, 'infinite', '127.0.8.1', '00:14, 1 January 1970' ) ),
602 self
::$title->getUserPermissionsErrors( 'move-target',
605 $this->assertEquals( true,
606 self
::$title->userCan( 'move-target', self
::$user ) );
610 self
::$user->mBlockedby
= 'WikiSysop';
611 self
::$user->mBlock
= new Block('127.0.8.1', 2, 1, 'no reason given', $now, 0, 10 );
612 $this->assertEquals( array( array( 'blockedtext',
613 '[[User:WikiSysop|WikiSysop]]', 'no reason given', '127.0.0.1',
614 'WikiSysop', 0, '00:00, 1 January 1970', '127.0.8.1',
615 $wgLang->timeanddate( wfTimestamp( TS_MW
, $now ), true ) ) ),
616 self
::$title->getUserPermissionsErrors( 'move-target', self
::$user ) );
618 # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
619 # $user->blockedFor() == ''
620 # $user->mBlock->mExpiry == 'infinity'