6 class TitlePermissionTest
extends MediaWikiLangTestCase
{
11 protected $userName, $altUserName;
21 protected $user, $anonUser, $userUser, $altUser;
23 protected function setUp() {
26 $langObj = Language
::factory( 'en' );
28 $localOffset = date( 'Z' ) / 60;
30 $this->setMwGlobals( array(
31 'wgMemc' => new EmptyBagOStuff
,
32 'wgContLang' => $langObj,
33 'wgLanguageCode' => 'en',
35 'wgLocaltimezone' => $localZone,
36 'wgLocalTZoffset' => $localOffset,
37 'wgNamespaceProtection' => array(
38 NS_MEDIAWIKI
=> 'editinterface',
42 $this->userName
= 'Useruser';
43 $this->altUserName
= 'Altuseruser';
44 date_default_timezone_set( $localZone );
46 $this->title
= Title
::makeTitle( NS_MAIN
, "Main Page" );
47 if ( !isset( $this->userUser
) ||
!( $this->userUser
instanceOf User
) ) {
48 $this->userUser
= User
::newFromName( $this->userName
);
50 if ( !$this->userUser
->getID() ) {
51 $this->userUser
= User
::createNew( $this->userName
, array(
52 "email" => "test@example.com",
53 "real_name" => "Test User" ) );
54 $this->userUser
->load();
57 $this->altUser
= User
::newFromName( $this->altUserName
);
58 if ( !$this->altUser
->getID() ) {
59 $this->altUser
= User
::createNew( $this->altUserName
, array(
60 "email" => "alttest@example.com",
61 "real_name" => "Test User Alt" ) );
62 $this->altUser
->load();
65 $this->anonUser
= User
::newFromId( 0 );
67 $this->user
= $this->userUser
;
72 function setUserPerm( $perm ) {
73 // Setting member variables is evil!!!
75 if ( is_array( $perm ) ) {
76 $this->user
->mRights
= $perm;
78 $this->user
->mRights
= array( $perm );
82 function setTitle( $ns, $title = "Main_Page" ) {
83 $this->title
= Title
::makeTitle( $ns, $title );
86 function setUser( $userName = null ) {
87 if ( $userName === 'anon' ) {
88 $this->user
= $this->anonUser
;
89 } elseif ( $userName === null ||
$userName === $this->userName
) {
90 $this->user
= $this->userUser
;
92 $this->user
= $this->altUser
;
96 function testQuickPermissions() {
98 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT
);
100 $this->setUser( 'anon' );
101 $this->setTitle( NS_TALK
);
102 $this->setUserPerm( "createtalk" );
103 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
104 $this->assertEquals( array(), $res );
106 $this->setTitle( NS_TALK
);
107 $this->setUserPerm( "createpage" );
108 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
109 $this->assertEquals( array( array( "nocreatetext" ) ), $res );
111 $this->setTitle( NS_TALK
);
112 $this->setUserPerm( "" );
113 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
114 $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
116 $this->setTitle( NS_MAIN
);
117 $this->setUserPerm( "createpage" );
118 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
119 $this->assertEquals( array( ), $res );
121 $this->setTitle( NS_MAIN
);
122 $this->setUserPerm( "createtalk" );
123 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
124 $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
126 $this->setUser( $this->userName
);
127 $this->setTitle( NS_TALK
);
128 $this->setUserPerm( "createtalk" );
129 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
130 $this->assertEquals( array( ), $res );
132 $this->setTitle( NS_TALK
);
133 $this->setUserPerm( "createpage" );
134 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
135 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
137 $this->setTitle( NS_TALK
);
138 $this->setUserPerm( "" );
139 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
140 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
142 $this->setTitle( NS_MAIN
);
143 $this->setUserPerm( "createpage" );
144 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
145 $this->assertEquals( array( ), $res );
147 $this->setTitle( NS_MAIN
);
148 $this->setUserPerm( "createtalk" );
149 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
150 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
152 $this->setTitle( NS_MAIN
);
153 $this->setUserPerm( "" );
154 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
155 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
157 $this->setUser( 'anon' );
158 $this->setTitle( NS_USER
, $this->userName
. '' );
159 $this->setUserPerm( "" );
160 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
161 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
163 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
164 $this->setUserPerm( "" );
165 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
166 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
168 $this->setTitle( NS_USER
, $this->userName
. '' );
169 $this->setUserPerm( "move-rootuserpages" );
170 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
171 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
173 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
174 $this->setUserPerm( "move-rootuserpages" );
175 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
176 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
178 $this->setTitle( NS_USER
, $this->userName
. '' );
179 $this->setUserPerm( "" );
180 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
181 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
183 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
184 $this->setUserPerm( "" );
185 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
186 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
188 $this->setTitle( NS_USER
, $this->userName
. '' );
189 $this->setUserPerm( "move-rootuserpages" );
190 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
191 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
193 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
194 $this->setUserPerm( "move-rootuserpages" );
195 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
196 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
198 $this->setUser( $this->userName
);
199 $this->setTitle( NS_FILE
, "img.png" );
200 $this->setUserPerm( "" );
201 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
202 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ), $res );
204 $this->setTitle( NS_FILE
, "img.png" );
205 $this->setUserPerm( "movefile" );
206 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
207 $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
209 $this->setUser( 'anon' );
210 $this->setTitle( NS_FILE
, "img.png" );
211 $this->setUserPerm( "" );
212 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
213 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ), $res );
215 $this->setTitle( NS_FILE
, "img.png" );
216 $this->setUserPerm( "movefile" );
217 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
218 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
220 $this->setUser( $this->userName
);
221 $this->setUserPerm( "move" );
222 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
224 $this->setUserPerm( "" );
225 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ) );
227 $this->setUser( 'anon' );
228 $this->setUserPerm( "move" );
229 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
231 $this->setUserPerm( "" );
232 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ),
233 array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ) );
235 if ( $this->isWikitextNS( NS_MAIN
) ) {
236 //NOTE: some content models don't allow moving
237 //@todo: find a Wikitext namespace for testing
239 $this->setTitle( NS_MAIN
);
240 $this->setUser( 'anon' );
241 $this->setUserPerm( "move" );
242 $this->runGroupPermissions( 'move', array( ) );
244 $this->setUserPerm( "" );
245 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ),
246 array( array( 'movenologintext' ) ) );
248 $this->setUser( $this->userName
);
249 $this->setUserPerm( "" );
250 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ) );
252 $this->setUserPerm( "move" );
253 $this->runGroupPermissions( 'move', array( ) );
255 $this->setUser( 'anon' );
256 $this->setUserPerm( 'move' );
257 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
258 $this->assertEquals( array( ), $res );
260 $this->setUserPerm( '' );
261 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
262 $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
265 $this->setTitle( NS_USER
);
266 $this->setUser( $this->userName
);
267 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
268 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
269 $this->assertEquals( array( ), $res );
271 $this->setUserPerm( "move" );
272 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
273 $this->assertEquals( array( array( 'cant-move-to-user-page' ) ), $res );
275 $this->setUser( 'anon' );
276 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
277 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
278 $this->assertEquals( array( ), $res );
280 $this->setTitle( NS_USER
, "User/subpage" );
281 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
282 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
283 $this->assertEquals( array( ), $res );
285 $this->setUserPerm( "move" );
286 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
287 $this->assertEquals( array( ), $res );
289 $this->setUser( 'anon' );
290 $check = array( 'edit' => array( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ) ),
291 array( array( 'badaccess-group0' ) ),
293 'protect' => array( array( array( 'badaccess-groups', "[[$prefix:Administrators|Administrators]]", 1 ), array( 'protect-cantedit' ) ),
294 array( array( 'badaccess-group0' ), array( 'protect-cantedit' ) ),
295 array( array( 'protect-cantedit' ) ), false ),
296 '' => array( array( ), array( ), array( ), true ) );
298 foreach ( array( "edit", "protect", "" ) as $action ) {
299 $this->setUserPerm( null );
300 $this->assertEquals( $check[$action][0],
301 $this->title
->getUserPermissionsErrors( $action, $this->user
, true ) );
303 global $wgGroupPermissions;
304 $old = $wgGroupPermissions;
305 $wgGroupPermissions = array();
307 $this->assertEquals( $check[$action][1],
308 $this->title
->getUserPermissionsErrors( $action, $this->user
, true ) );
309 $wgGroupPermissions = $old;
311 $this->setUserPerm( $action );
312 $this->assertEquals( $check[$action][2],
313 $this->title
->getUserPermissionsErrors( $action, $this->user
, true ) );
315 $this->setUserPerm( $action );
316 $this->assertEquals( $check[$action][3],
317 $this->title
->userCan( $action, $this->user
, true ) );
318 $this->assertEquals( $check[$action][3],
319 $this->title
->quickUserCan( $action, $this->user
) );
321 # count( User::getGroupsWithPermissions( $action ) ) < 1
325 function runGroupPermissions( $action, $result, $result2 = null ) {
326 global $wgGroupPermissions;
328 if ( $result2 === null ) $result2 = $result;
330 $wgGroupPermissions['autoconfirmed']['move'] = false;
331 $wgGroupPermissions['user']['move'] = false;
332 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
333 $this->assertEquals( $result, $res );
335 $wgGroupPermissions['autoconfirmed']['move'] = true;
336 $wgGroupPermissions['user']['move'] = false;
337 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
338 $this->assertEquals( $result2, $res );
340 $wgGroupPermissions['autoconfirmed']['move'] = true;
341 $wgGroupPermissions['user']['move'] = true;
342 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
343 $this->assertEquals( $result2, $res );
345 $wgGroupPermissions['autoconfirmed']['move'] = false;
346 $wgGroupPermissions['user']['move'] = true;
347 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
348 $this->assertEquals( $result2, $res );
351 function testSpecialsAndNSPermissions() {
352 global $wgNamespaceProtection;
353 $this->setUser( $this->userName
);
355 $this->setTitle( NS_SPECIAL
);
357 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'ns-specialprotected' ) ),
358 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
360 $this->setTitle( NS_MAIN
);
361 $this->setUserPerm( 'bogus' );
362 $this->assertEquals( array( ),
363 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
365 $this->setTitle( NS_MAIN
);
366 $this->setUserPerm( '' );
367 $this->assertEquals( array( array( 'badaccess-group0' ) ),
368 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
370 $wgNamespaceProtection[NS_USER
] = array( 'bogus' );
372 $this->setTitle( NS_USER
);
373 $this->setUserPerm( '' );
374 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'namespaceprotected', 'User' ) ),
375 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
377 $this->setTitle( NS_MEDIAWIKI
);
378 $this->setUserPerm( 'bogus' );
379 $this->assertEquals( array( array( 'protectedinterface' ) ),
380 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
382 $this->setTitle( NS_MEDIAWIKI
);
383 $this->setUserPerm( 'bogus' );
384 $this->assertEquals( array( array( 'protectedinterface' ) ),
385 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
387 $wgNamespaceProtection = null;
389 $this->setUserPerm( 'bogus' );
390 $this->assertEquals( array( ),
391 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
392 $this->assertEquals( true,
393 $this->title
->userCan( 'bogus', $this->user
) );
395 $this->setUserPerm( '' );
396 $this->assertEquals( array( array( 'badaccess-group0' ) ),
397 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
398 $this->assertEquals( false,
399 $this->title
->userCan( 'bogus', $this->user
) );
402 function testCssAndJavascriptPermissions() {
403 $this->setUser( $this->userName
);
405 $this->setTitle( NS_USER
, $this->altUserName
. '/test.js' );
406 $this->runCSSandJSPermissions(
407 array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
408 array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
409 array( array( 'badaccess-group0' ) ) );
411 $this->setTitle( NS_USER
, $this->altUserName
. '/test.css' );
412 $this->runCSSandJSPermissions(
413 array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ),
414 array( array( 'badaccess-group0' ) ),
415 array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ) );
417 $this->setTitle( NS_USER
, $this->altUserName
. '/tempo' );
418 $this->runCSSandJSPermissions(
419 array( array( 'badaccess-group0' ) ),
420 array( array( 'badaccess-group0' ) ),
421 array( array( 'badaccess-group0' ) ) );
424 function runCSSandJSPermissions( $result0, $result1, $result2 ) {
425 $this->setUserPerm( '' );
426 $this->assertEquals( $result0,
427 $this->title
->getUserPermissionsErrors( 'bogus',
430 $this->setUserPerm( 'editusercss' );
431 $this->assertEquals( $result1,
432 $this->title
->getUserPermissionsErrors( 'bogus',
435 $this->setUserPerm( 'edituserjs' );
436 $this->assertEquals( $result2,
437 $this->title
->getUserPermissionsErrors( 'bogus',
440 $this->setUserPerm( 'editusercssjs' );
441 $this->assertEquals( array( array( 'badaccess-group0' ) ),
442 $this->title
->getUserPermissionsErrors( 'bogus',
445 $this->setUserPerm( array( 'edituserjs', 'editusercss' ) );
446 $this->assertEquals( array( array( 'badaccess-group0' ) ),
447 $this->title
->getUserPermissionsErrors( 'bogus',
451 function testPageRestrictions() {
454 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT
);
456 $this->setTitle( NS_MAIN
);
457 $this->title
->mRestrictionsLoaded
= true;
458 $this->setUserPerm( "edit" );
459 $this->title
->mRestrictions
= array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
461 $this->assertEquals( array( ),
462 $this->title
->getUserPermissionsErrors( 'edit',
465 $this->assertEquals( true,
466 $this->title
->quickUserCan( 'edit', $this->user
) );
467 $this->title
->mRestrictions
= array( "edit" => array( 'bogus', "sysop", "protect", "" ),
468 "bogus" => array( 'bogus', "sysop", "protect", "" ) );
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( 'protectedpagetext', 'bogus' ),
477 array( 'protectedpagetext', 'protect' ),
478 array( 'protectedpagetext', 'protect' ) ),
479 $this->title
->getUserPermissionsErrors( 'edit',
481 $this->setUserPerm( "" );
482 $this->assertEquals( array( array( 'badaccess-group0' ),
483 array( 'protectedpagetext', 'bogus' ),
484 array( 'protectedpagetext', 'protect' ),
485 array( 'protectedpagetext', 'protect' ) ),
486 $this->title
->getUserPermissionsErrors( 'bogus',
488 $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ),
489 array( 'protectedpagetext', 'bogus' ),
490 array( 'protectedpagetext', 'protect' ),
491 array( 'protectedpagetext', 'protect' ) ),
492 $this->title
->getUserPermissionsErrors( 'edit',
494 $this->setUserPerm( array( "edit", "editprotected" ) );
495 $this->assertEquals( array( array( 'badaccess-group0' ),
496 array( 'protectedpagetext', 'bogus' ),
497 array( 'protectedpagetext', 'protect' ),
498 array( 'protectedpagetext', 'protect' ) ),
499 $this->title
->getUserPermissionsErrors( 'bogus',
501 $this->assertEquals( array( ),
502 $this->title
->getUserPermissionsErrors( 'edit',
504 $this->title
->mCascadeRestriction
= true;
505 $this->assertEquals( false,
506 $this->title
->quickUserCan( 'bogus', $this->user
) );
507 $this->assertEquals( false,
508 $this->title
->quickUserCan( 'edit', $this->user
) );
509 $this->assertEquals( array( array( 'badaccess-group0' ),
510 array( 'protectedpagetext', 'bogus' ),
511 array( 'protectedpagetext', 'protect' ),
512 array( 'protectedpagetext', 'protect' ) ),
513 $this->title
->getUserPermissionsErrors( 'bogus',
515 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
516 array( 'protectedpagetext', 'protect' ),
517 array( 'protectedpagetext', 'protect' ) ),
518 $this->title
->getUserPermissionsErrors( 'edit',
522 function testCascadingSourcesRestrictions() {
523 $this->setTitle( NS_MAIN
, "test page" );
524 $this->setUserPerm( array( "edit", "bogus" ) );
526 $this->title
->mCascadeSources
= array( Title
::makeTitle( NS_MAIN
, "Bogus" ), Title
::makeTitle( NS_MAIN
, "UnBogus" ) );
527 $this->title
->mCascadingRestrictions
= array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
529 $this->assertEquals( false,
530 $this->title
->userCan( 'bogus', $this->user
) );
531 $this->assertEquals( array( array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ),
532 array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ) ),
533 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
535 $this->assertEquals( true,
536 $this->title
->userCan( 'edit', $this->user
) );
537 $this->assertEquals( array( ),
538 $this->title
->getUserPermissionsErrors( 'edit', $this->user
) );
542 function testActionPermissions() {
543 $this->setUserPerm( array( "createpage" ) );
544 $this->setTitle( NS_MAIN
, "test page" );
545 $this->title
->mTitleProtection
['pt_create_perm'] = '';
546 $this->title
->mTitleProtection
['pt_user'] = $this->user
->getID();
547 $this->title
->mTitleProtection
['pt_expiry'] = wfGetDB( DB_SLAVE
)->getInfinity();
548 $this->title
->mTitleProtection
['pt_reason'] = 'test';
549 $this->title
->mCascadeRestriction
= false;
551 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
552 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
553 $this->assertEquals( false,
554 $this->title
->userCan( 'create', $this->user
) );
556 $this->title
->mTitleProtection
['pt_create_perm'] = 'sysop';
557 $this->setUserPerm( array( 'createpage', 'protect' ) );
558 $this->assertEquals( array( ),
559 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
560 $this->assertEquals( true,
561 $this->title
->userCan( 'create', $this->user
) );
564 $this->setUserPerm( array( 'createpage' ) );
565 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
566 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
567 $this->assertEquals( false,
568 $this->title
->userCan( 'create', $this->user
) );
570 $this->setTitle( NS_MEDIA
, "test page" );
571 $this->setUserPerm( array( "move" ) );
572 $this->assertEquals( false,
573 $this->title
->userCan( 'move', $this->user
) );
574 $this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ),
575 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
577 $this->setTitle( NS_HELP
, "test page" );
578 $this->assertEquals( array( ),
579 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
580 $this->assertEquals( true,
581 $this->title
->userCan( 'move', $this->user
) );
583 $this->title
->mInterwiki
= "no";
584 $this->assertEquals( array( array( 'immobile-source-page' ) ),
585 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
586 $this->assertEquals( false,
587 $this->title
->userCan( 'move', $this->user
) );
589 $this->setTitle( NS_MEDIA
, "test page" );
590 $this->assertEquals( false,
591 $this->title
->userCan( 'move-target', $this->user
) );
592 $this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ),
593 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
595 $this->setTitle( NS_HELP
, "test page" );
596 $this->assertEquals( array( ),
597 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
598 $this->assertEquals( true,
599 $this->title
->userCan( 'move-target', $this->user
) );
601 $this->title
->mInterwiki
= "no";
602 $this->assertEquals( array( array( 'immobile-target-page' ) ),
603 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
604 $this->assertEquals( false,
605 $this->title
->userCan( 'move-target', $this->user
) );
609 function testUserBlock() {
610 global $wgEmailConfirmToEdit, $wgEmailAuthentication;
611 $wgEmailConfirmToEdit = true;
612 $wgEmailAuthentication = true;
614 $this->setUserPerm( array( "createpage", "move" ) );
615 $this->setTitle( NS_HELP
, "test page" );
618 $this->assertEquals( array( array( 'confirmedittext' ) ),
619 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
620 $wgEmailConfirmToEdit = false;
621 $this->assertEquals( true, $this->title
->userCan( 'move-target', $this->user
) );
623 # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
624 $this->assertEquals( array( ),
625 $this->title
->getUserPermissionsErrors( 'move-target',
631 $this->user
->mBlockedby
= $this->user
->getId();
632 $this->user
->mBlock
= new Block( '127.0.8.1', 0, $this->user
->getId(),
633 'no reason given', $prev +
3600, 1, 0 );
634 $this->user
->mBlock
->mTimestamp
= 0;
635 $this->assertEquals( array( array( 'autoblockedtext',
636 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
637 'Useruser', null, 'infinite', '127.0.8.1',
638 $wgLang->timeanddate( wfTimestamp( TS_MW
, $prev ), true ) ) ),
639 $this->title
->getUserPermissionsErrors( 'move-target',
642 $this->assertEquals( false, $this->title
->userCan( 'move-target', $this->user
) );
643 // quickUserCan should ignore user blocks
644 $this->assertEquals( true, $this->title
->quickUserCan( 'move-target', $this->user
) );
646 global $wgLocalTZoffset;
647 $wgLocalTZoffset = -60;
648 $this->user
->mBlockedby
= $this->user
->getName();
649 $this->user
->mBlock
= new Block( '127.0.8.1', 0, 1, 'no reason given', $now, 0, 10 );
650 $this->assertEquals( array( array( 'blockedtext',
651 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
652 'Useruser', null, '23:00, 31 December 1969', '127.0.8.1',
653 $wgLang->timeanddate( wfTimestamp( TS_MW
, $now ), true ) ) ),
654 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
656 # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
657 # $user->blockedFor() == ''
658 # $user->mBlock->mExpiry == 'infinity'