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() {
69 $this->setUser( 'anon' );
70 $this->setTitle( NS_TALK
);
71 $this->setUserPerm( "createtalk" );
72 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
73 $this->assertEquals( array(), $res );
75 $this->setTitle( NS_TALK
);
76 $this->setUserPerm( "createpage" );
77 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
78 $this->assertEquals( array( array( "nocreatetext" ) ), $res );
80 $this->setTitle( NS_TALK
);
81 $this->setUserPerm( "" );
82 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
83 $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
85 $this->setTitle( NS_MAIN
);
86 $this->setUserPerm( "createpage" );
87 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
88 $this->assertEquals( array( ), $res );
90 $this->setTitle( NS_MAIN
);
91 $this->setUserPerm( "createtalk" );
92 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
93 $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
95 $this->setUser( self
::$userName );
96 $this->setTitle( NS_TALK
);
97 $this->setUserPerm( "createtalk" );
98 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
99 $this->assertEquals( array( ), $res );
101 $this->setTitle( NS_TALK
);
102 $this->setUserPerm( "createpage" );
103 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
104 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
106 $this->setTitle( NS_TALK
);
107 $this->setUserPerm( "" );
108 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
109 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
111 $this->setTitle( NS_MAIN
);
112 $this->setUserPerm( "createpage" );
113 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
114 $this->assertEquals( array( ), $res );
116 $this->setTitle( NS_MAIN
);
117 $this->setUserPerm( "createtalk" );
118 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
119 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
121 $this->setTitle( NS_MAIN
);
122 $this->setUserPerm( "" );
123 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
124 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
126 $this->setUser( 'anon' );
127 $this->setTitle( NS_USER
, self
::$userName . '' );
128 $this->setUserPerm( "" );
129 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
130 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
132 $this->setTitle( NS_USER
, self
::$userName . '/subpage' );
133 $this->setUserPerm( "" );
134 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
135 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
137 $this->setTitle( NS_USER
, self
::$userName . '' );
138 $this->setUserPerm( "move-rootuserpages" );
139 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
140 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
142 $this->setTitle( NS_USER
, self
::$userName . '/subpage' );
143 $this->setUserPerm( "move-rootuserpages" );
144 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
145 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
147 $this->setTitle( NS_USER
, self
::$userName . '' );
148 $this->setUserPerm( "" );
149 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
150 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
152 $this->setTitle( NS_USER
, self
::$userName . '/subpage' );
153 $this->setUserPerm( "" );
154 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
155 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
157 $this->setTitle( NS_USER
, self
::$userName . '' );
158 $this->setUserPerm( "move-rootuserpages" );
159 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
160 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
162 $this->setTitle( NS_USER
, self
::$userName . '/subpage' );
163 $this->setUserPerm( "move-rootuserpages" );
164 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
165 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
167 $this->setUser( self
::$userName );
168 $this->setTitle( NS_FILE
, "img.png" );
169 $this->setUserPerm( "" );
170 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
171 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ), $res );
173 $this->setTitle( NS_FILE
, "img.png" );
174 $this->setUserPerm( "movefile" );
175 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
176 $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
178 $this->setUser( 'anon' );
179 $this->setTitle( NS_FILE
, "img.png" );
180 $this->setUserPerm( "" );
181 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
182 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ), $res );
184 $this->setTitle( NS_FILE
, "img.png" );
185 $this->setUserPerm( "movefile" );
186 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
187 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
189 $this->setUser( self
::$userName );
190 $this->setUserPerm( "move" );
191 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
193 $this->setUserPerm( "" );
194 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ) );
196 $this->setUser( 'anon' );
197 $this->setUserPerm( "move" );
198 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
200 $this->setUserPerm( "" );
201 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ),
202 array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ) );
204 $this->setTitle( NS_MAIN
);
205 $this->setUser( 'anon' );
206 $this->setUserPerm( "move" );
207 $this->runGroupPermissions( 'move', array( ) );
209 $this->setUserPerm( "" );
210 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ),
211 array( array( 'movenologintext' ) ) );
213 $this->setUser( self
::$userName );
214 $this->setUserPerm( "" );
215 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ) );
217 $this->setUserPerm( "move" );
218 $this->runGroupPermissions( 'move', array( ) );
220 $this->setUser( 'anon' );
221 $this->setUserPerm( 'move' );
222 $res = self
::$title->getUserPermissionsErrors( 'move-target', self
::$user );
223 $this->assertEquals( array( ), $res );
225 $this->setUserPerm( '' );
226 $res = self
::$title->getUserPermissionsErrors( 'move-target', self
::$user );
227 $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
229 $this->setTitle( NS_USER
);
230 $this->setUser( self
::$userName );
231 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
232 $res = self
::$title->getUserPermissionsErrors( 'move-target', self
::$user );
233 $this->assertEquals( array( ), $res );
235 $this->setUserPerm( "move" );
236 $res = self
::$title->getUserPermissionsErrors( 'move-target', self
::$user );
237 $this->assertEquals( array( array( 'cant-move-to-user-page' ) ), $res );
239 $this->setUser( 'anon' );
240 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
241 $res = self
::$title->getUserPermissionsErrors( 'move-target', self
::$user );
242 $this->assertEquals( array( ), $res );
244 $this->setTitle( NS_USER
, "User/subpage" );
245 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
246 $res = self
::$title->getUserPermissionsErrors( 'move-target', self
::$user );
247 $this->assertEquals( array( ), $res );
249 $this->setUserPerm( "move" );
250 $res = self
::$title->getUserPermissionsErrors( 'move-target', self
::$user );
251 $this->assertEquals( array( ), $res );
253 $this->setUser( 'anon' );
254 $check = array( 'edit' => array( array( array( 'badaccess-groups', "*, [[Mw:Users|Users]]", 2 ) ),
255 array( array( 'badaccess-group0' ) ),
257 'protect' => array( array( array( 'badaccess-groups', "[[Mw:Administrators|Administrators]]", 1 ), array( 'protect-cantedit' ) ),
258 array( array( 'badaccess-group0' ), array( 'protect-cantedit' ) ),
259 array( array( 'protect-cantedit' ) ), false ),
260 '' => array( array( ), array( ), array( ), true ) );
262 $wgUser = self
::$user;
263 foreach ( array( "edit", "protect", "" ) as $action ) {
264 $this->setUserPerm( null );
265 $this->assertEquals( $check[$action][0],
266 self
::$title->getUserPermissionsErrors( $action, self
::$user, true ) );
268 global $wgGroupPermissions;
269 $old = $wgGroupPermissions;
270 $wgGroupPermissions = array();
272 $this->assertEquals( $check[$action][1],
273 self
::$title->getUserPermissionsErrors( $action, self
::$user, true ) );
274 $wgGroupPermissions = $old;
276 $this->setUserPerm( $action );
277 $this->assertEquals( $check[$action][2],
278 self
::$title->getUserPermissionsErrors( $action, self
::$user, true ) );
280 $this->setUserPerm( $action );
281 $this->assertEquals( $check[$action][3],
282 self
::$title->userCan( $action, true ) );
283 $this->assertEquals( $check[$action][3],
284 self
::$title->quickUserCan( $action, false ) );
286 # count( User::getGroupsWithPermissions( $action ) ) < 1
290 function runGroupPermissions( $action, $result, $result2 = null ) {
291 global $wgGroupPermissions;
293 if ( $result2 === null ) $result2 = $result;
295 $wgGroupPermissions['autoconfirmed']['move'] = false;
296 $wgGroupPermissions['user']['move'] = false;
297 $res = self
::$title->getUserPermissionsErrors( $action, self
::$user );
298 $this->assertEquals( $result, $res );
300 $wgGroupPermissions['autoconfirmed']['move'] = true;
301 $wgGroupPermissions['user']['move'] = false;
302 $res = self
::$title->getUserPermissionsErrors( $action, self
::$user );
303 $this->assertEquals( $result2, $res );
305 $wgGroupPermissions['autoconfirmed']['move'] = true;
306 $wgGroupPermissions['user']['move'] = true;
307 $res = self
::$title->getUserPermissionsErrors( $action, self
::$user );
308 $this->assertEquals( $result2, $res );
310 $wgGroupPermissions['autoconfirmed']['move'] = false;
311 $wgGroupPermissions['user']['move'] = true;
312 $res = self
::$title->getUserPermissionsErrors( $action, self
::$user );
313 $this->assertEquals( $result2, $res );
316 function testPermissionHooks() { }
317 function testSpecialsAndNSPermissions() {
318 $this->setUser( self
::$userName );
320 $wgUser = self
::$user;
322 $this->setTitle( NS_SPECIAL
);
324 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'ns-specialprotected' ) ),
325 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
326 $this->assertEquals( array( array( 'badaccess-groups', '*, [[Mw:Administrators|Administrators]]', 2 ) ),
327 self
::$title->getUserPermissionsErrors( 'createaccount', self
::$user ) );
328 $this->assertEquals( array( array( 'badaccess-group0' ) ),
329 self
::$title->getUserPermissionsErrors( 'execute', self
::$user ) );
331 $this->setTitle( NS_MAIN
);
332 $this->setUserPerm( 'bogus' );
333 $this->assertEquals( array( ),
334 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
336 $this->setTitle( NS_MAIN
);
337 $this->setUserPerm( '' );
338 $this->assertEquals( array( array( 'badaccess-group0' ) ),
339 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
341 global $wgNamespaceProtection;
342 $wgNamespaceProtection[NS_USER
] = array ( 'bogus' );
343 $this->setTitle( NS_USER
);
344 $this->setUserPerm( '' );
345 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'namespaceprotected', 'User' ) ),
346 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
348 $this->setTitle( NS_MEDIAWIKI
);
349 $this->setUserPerm( 'bogus' );
350 $this->assertEquals( array( array( 'protectedinterface' ) ),
351 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
353 $this->setTitle( NS_MEDIAWIKI
);
354 $this->setUserPerm( 'bogus' );
355 $this->assertEquals( array( array( 'protectedinterface' ) ),
356 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
358 $wgNamespaceProtection = null;
359 $this->setUserPerm( 'bogus' );
360 $this->assertEquals( array( ),
361 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
362 $this->assertEquals( true,
363 self
::$title->userCan( 'bogus' ) );
365 $this->setUserPerm( '' );
366 $this->assertEquals( array( array( 'badaccess-group0' ) ),
367 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
368 $this->assertEquals( false,
369 self
::$title->userCan( 'bogus' ) );
372 function testCSSandJSPermissions() {
373 $this->setUser( self
::$userName );
375 $wgUser = self
::$user;
377 $this->setTitle( NS_USER
, self
::$altUserName . '/test.js' );
378 $this->runCSSandJSPermissions(
379 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
380 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
381 array( array( 'badaccess-group0' ) ) );
383 $this->setTitle( NS_USER
, self
::$altUserName . '/test.css' );
384 $this->runCSSandJSPermissions(
385 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
386 array( array( 'badaccess-group0' ) ),
387 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ) );
389 $this->setTitle( NS_USER
, self
::$altUserName . '/tempo' );
390 $this->runCSSandJSPermissions(
391 array( array( 'badaccess-group0' ) ),
392 array( array( 'badaccess-group0' ) ),
393 array( array( 'badaccess-group0' ) ) );
396 function runCSSandJSPermissions( $result0, $result1, $result2 ) {
397 $this->setUserPerm( '' );
398 $this->assertEquals( $result0,
399 self
::$title->getUserPermissionsErrors( 'bogus',
402 $this->setUserPerm( 'editusercss' );
403 $this->assertEquals( $result1,
404 self
::$title->getUserPermissionsErrors( 'bogus',
407 $this->setUserPerm( 'edituserjs' );
408 $this->assertEquals( $result2,
409 self
::$title->getUserPermissionsErrors( 'bogus',
412 $this->setUserPerm( 'editusercssjs' );
413 $this->assertEquals( array( array( 'badaccess-group0' ) ),
414 self
::$title->getUserPermissionsErrors( 'bogus',
417 $this->setUserPerm( array( 'edituserjs', 'editusercss' ) );
418 $this->assertEquals( array( array( 'badaccess-group0' ) ),
419 self
::$title->getUserPermissionsErrors( 'bogus',
423 function testPageRestrictions() {
425 $wgUser = self
::$user;
426 $this->setTitle( NS_MAIN
);
427 self
::$title->mRestrictionsLoaded
= true;
428 $this->setUserPerm( "edit" );
429 self
::$title->mRestrictions
= array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
431 $this->assertEquals( array( ),
432 self
::$title->getUserPermissionsErrors( 'edit',
435 $this->assertEquals( true,
436 self
::$title->quickUserCan( 'edit', false ) );
437 self
::$title->mRestrictions
= array( "edit" => array( 'bogus', "sysop", "protect", "" ),
438 "bogus" => array( 'bogus', "sysop", "protect", "" ) );
440 $this->assertEquals( array( array( 'badaccess-group0' ),
441 array( 'protectedpagetext', 'bogus' ),
442 array( 'protectedpagetext', 'protect' ),
443 array( 'protectedpagetext', 'protect' ) ),
444 self
::$title->getUserPermissionsErrors( 'bogus',
446 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
447 array( 'protectedpagetext', 'protect' ),
448 array( 'protectedpagetext', 'protect' ) ),
449 self
::$title->getUserPermissionsErrors( 'edit',
451 $this->setUserPerm( "" );
452 $this->assertEquals( array( array( 'badaccess-group0' ),
453 array( 'protectedpagetext', 'bogus' ),
454 array( 'protectedpagetext', 'protect' ),
455 array( 'protectedpagetext', 'protect' ) ),
456 self
::$title->getUserPermissionsErrors( 'bogus',
458 $this->assertEquals( array( array( 'badaccess-groups', '*, [[Mw:Users|Users]]', 2 ),
459 array( 'protectedpagetext', 'bogus' ),
460 array( 'protectedpagetext', 'protect' ),
461 array( 'protectedpagetext', 'protect' ) ),
462 self
::$title->getUserPermissionsErrors( 'edit',
464 $this->setUserPerm( array( "edit", "editprotected" ) );
465 $this->assertEquals( array( array( 'badaccess-group0' ),
466 array( 'protectedpagetext', 'bogus' ),
467 array( 'protectedpagetext', 'protect' ),
468 array( 'protectedpagetext', 'protect' ) ),
469 self
::$title->getUserPermissionsErrors( 'bogus',
471 $this->assertEquals( array( ),
472 self
::$title->getUserPermissionsErrors( 'edit',
474 self
::$title->mCascadeRestriction
= true;
475 $this->assertEquals( false,
476 self
::$title->quickUserCan( 'bogus', false ) );
477 $this->assertEquals( false,
478 self
::$title->quickUserCan( 'edit', false ) );
479 $this->assertEquals( array( array( 'badaccess-group0' ),
480 array( 'protectedpagetext', 'bogus' ),
481 array( 'protectedpagetext', 'protect' ),
482 array( 'protectedpagetext', 'protect' ) ),
483 self
::$title->getUserPermissionsErrors( 'bogus',
485 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
486 array( 'protectedpagetext', 'protect' ),
487 array( 'protectedpagetext', 'protect' ) ),
488 self
::$title->getUserPermissionsErrors( 'edit',
492 function testCascadingSourcesRestrictions() {
494 $wgUser = self
::$user;
495 $this->setTitle( NS_MAIN
, "test page" );
496 $this->setUserPerm( array( "edit", "bogus" ) );
498 self
::$title->mCascadeSources
= array( Title
::makeTitle( NS_MAIN
, "Bogus" ), Title
::makeTitle( NS_MAIN
, "UnBogus" ) );
499 self
::$title->mCascadingRestrictions
= array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
501 $this->assertEquals( false,
502 self
::$title->userCan( 'bogus' ) );
503 $this->assertEquals( array( array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ),
504 array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ) ),
505 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
507 $this->assertEquals( true,
508 self
::$title->userCan( 'edit' ) );
509 $this->assertEquals( array( ),
510 self
::$title->getUserPermissionsErrors( 'edit', self
::$user ) );
514 function testActionPermissions() {
516 $wgUser = self
::$user;
518 $this->setUserPerm( array( "createpage" ) );
519 $this->setTitle( NS_MAIN
, "test page" );
520 self
::$title->mTitleProtection
['pt_create_perm'] = '';
521 self
::$title->mTitleProtection
['pt_user'] = self
::$user->getID();
522 self
::$title->mTitleProtection
['pt_expiry'] = Block
::infinity();
523 self
::$title->mTitleProtection
['pt_reason'] = 'test';
524 self
::$title->mCascadeRestriction
= false;
526 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
527 self
::$title->getUserPermissionsErrors( 'create', self
::$user ) );
528 $this->assertEquals( false,
529 self
::$title->userCan( 'create' ) );
531 self
::$title->mTitleProtection
['pt_create_perm'] = 'sysop';
532 $this->setUserPerm( array( 'createpage', 'protect' ) );
533 $this->assertEquals( array( ),
534 self
::$title->getUserPermissionsErrors( 'create', self
::$user ) );
535 $this->assertEquals( true,
536 self
::$title->userCan( 'create' ) );
539 $this->setUserPerm( array( 'createpage' ) );
540 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
541 self
::$title->getUserPermissionsErrors( 'create', self
::$user ) );
542 $this->assertEquals( false,
543 self
::$title->userCan( 'create' ) );
545 $this->setTitle( NS_MEDIA
, "test page" );
546 $this->setUserPerm( array( "move" ) );
547 $this->assertEquals( false,
548 self
::$title->userCan( 'move' ) );
549 $this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ),
550 self
::$title->getUserPermissionsErrors( 'move', self
::$user ) );
552 $this->setTitle( NS_MAIN
, "test page" );
553 $this->assertEquals( array( ),
554 self
::$title->getUserPermissionsErrors( 'move', self
::$user ) );
555 $this->assertEquals( true,
556 self
::$title->userCan( 'move' ) );
558 self
::$title->mInterwiki
= "no";
559 $this->assertEquals( array( array( 'immobile-page' ) ),
560 self
::$title->getUserPermissionsErrors( 'move', self
::$user ) );
561 $this->assertEquals( false,
562 self
::$title->userCan( 'move' ) );
564 $this->setTitle( NS_MEDIA
, "test page" );
565 $this->assertEquals( false,
566 self
::$title->userCan( 'move-target' ) );
567 $this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ),
568 self
::$title->getUserPermissionsErrors( 'move-target', self
::$user ) );
570 $this->setTitle( NS_MAIN
, "test page" );
571 $this->assertEquals( array( ),
572 self
::$title->getUserPermissionsErrors( 'move-target', self
::$user ) );
573 $this->assertEquals( true,
574 self
::$title->userCan( 'move-target' ) );
576 self
::$title->mInterwiki
= "no";
577 $this->assertEquals( array( array( 'immobile-target-page' ) ),
578 self
::$title->getUserPermissionsErrors( 'move-target', self
::$user ) );
579 $this->assertEquals( false,
580 self
::$title->userCan( 'move-target' ) );
584 function testUserBlock() {
585 global $wgUser, $wgEmailConfirmToEdit, $wgEmailAuthentication;
586 $wgEmailConfirmToEdit = true;
587 $wgEmailAuthentication = true;
588 $wgUser = self
::$user;
590 $this->setUserPerm( array( "createpage", "move" ) );
591 $this->setTitle( NS_MAIN
, "test page" );
594 $this->assertEquals( array( array( 'confirmedittext' ) ),
595 self
::$title->getUserPermissionsErrors( 'move-target', self
::$user ) );
596 $this->assertEquals( true, self
::$title->userCan( 'move-target' ) );
598 $wgEmailConfirmToEdit = false;
599 # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
600 $this->assertEquals( array( ),
601 self
::$title->getUserPermissionsErrors( 'move-target',
607 self
::$user->mBlockedby
= self
::$user->getId();
608 self
::$user->mBlock
= new Block( '127.0.8.1', self
::$user->getId(), self
::$user->getId(),
609 'no reason given', $prev +
3600, 1, 0 );
610 self
::$user->mBlock
->mTimestamp
= 0;
611 $this->assertEquals( array( array( 'autoblockedtext',
612 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
613 'Useruser', 0, 'infinite', '127.0.8.1',
614 $wgLang->timeanddate( wfTimestamp( TS_MW
, $prev ), true ) ) ),
615 self
::$title->getUserPermissionsErrors( 'move-target',
618 $this->assertEquals( true,
619 self
::$title->userCan( 'move-target', self
::$user ) );
621 global $wgLocalTZoffset;
622 $wgLocalTZoffset = -60;
623 self
::$user->mBlockedby
= self
::$user->getName();
624 self
::$user->mBlock
= new Block( '127.0.8.1', 2, 1, 'no reason given', $now, 0, 10 );
625 $this->assertEquals( array( array( 'blockedtext',
626 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
627 'Useruser', 0, '23:00, 31 December 1969', '127.0.8.1',
628 $wgLang->timeanddate( wfTimestamp( TS_MW
, $now ), true ) ) ),
629 self
::$title->getUserPermissionsErrors( 'move-target', self
::$user ) );
631 # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
632 # $user->blockedFor() == ''
633 # $user->mBlock->mExpiry == 'infinity'