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,
34 'wgLocaltimezone' => $localZone,
35 'wgLocalTZoffset' => $localOffset,
36 'wgNamespaceProtection' => array(
37 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 ) {
89 if ( $userName === 'anon' ) {
90 $this->user
= $this->anonUser
;
91 } elseif ( $userName === null ||
$userName === $this->userName
) {
92 $this->user
= $this->userUser
;
94 $this->user
= $this->altUser
;
97 $wgUser = $this->user
;
100 function testQuickPermissions() {
102 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT
);
104 $this->setUser( 'anon' );
105 $this->setTitle( NS_TALK
);
106 $this->setUserPerm( "createtalk" );
107 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
108 $this->assertEquals( array(), $res );
110 $this->setTitle( NS_TALK
);
111 $this->setUserPerm( "createpage" );
112 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
113 $this->assertEquals( array( array( "nocreatetext" ) ), $res );
115 $this->setTitle( NS_TALK
);
116 $this->setUserPerm( "" );
117 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
118 $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
120 $this->setTitle( NS_MAIN
);
121 $this->setUserPerm( "createpage" );
122 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
123 $this->assertEquals( array( ), $res );
125 $this->setTitle( NS_MAIN
);
126 $this->setUserPerm( "createtalk" );
127 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
128 $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
130 $this->setUser( $this->userName
);
131 $this->setTitle( NS_TALK
);
132 $this->setUserPerm( "createtalk" );
133 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
134 $this->assertEquals( array( ), $res );
136 $this->setTitle( NS_TALK
);
137 $this->setUserPerm( "createpage" );
138 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
139 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
141 $this->setTitle( NS_TALK
);
142 $this->setUserPerm( "" );
143 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
144 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
146 $this->setTitle( NS_MAIN
);
147 $this->setUserPerm( "createpage" );
148 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
149 $this->assertEquals( array( ), $res );
151 $this->setTitle( NS_MAIN
);
152 $this->setUserPerm( "createtalk" );
153 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
154 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
156 $this->setTitle( NS_MAIN
);
157 $this->setUserPerm( "" );
158 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
159 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
161 $this->setUser( 'anon' );
162 $this->setTitle( NS_USER
, $this->userName
. '' );
163 $this->setUserPerm( "" );
164 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
165 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
167 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
168 $this->setUserPerm( "" );
169 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
170 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
172 $this->setTitle( NS_USER
, $this->userName
. '' );
173 $this->setUserPerm( "move-rootuserpages" );
174 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
175 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
177 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
178 $this->setUserPerm( "move-rootuserpages" );
179 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
180 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
182 $this->setTitle( NS_USER
, $this->userName
. '' );
183 $this->setUserPerm( "" );
184 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
185 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
187 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
188 $this->setUserPerm( "" );
189 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
190 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
192 $this->setTitle( NS_USER
, $this->userName
. '' );
193 $this->setUserPerm( "move-rootuserpages" );
194 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
195 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
197 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
198 $this->setUserPerm( "move-rootuserpages" );
199 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
200 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
202 $this->setUser( $this->userName
);
203 $this->setTitle( NS_FILE
, "img.png" );
204 $this->setUserPerm( "" );
205 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
206 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ), $res );
208 $this->setTitle( NS_FILE
, "img.png" );
209 $this->setUserPerm( "movefile" );
210 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
211 $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
213 $this->setUser( 'anon' );
214 $this->setTitle( NS_FILE
, "img.png" );
215 $this->setUserPerm( "" );
216 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
217 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ), $res );
219 $this->setTitle( NS_FILE
, "img.png" );
220 $this->setUserPerm( "movefile" );
221 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
222 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
224 $this->setUser( $this->userName
);
225 $this->setUserPerm( "move" );
226 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
228 $this->setUserPerm( "" );
229 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ) );
231 $this->setUser( 'anon' );
232 $this->setUserPerm( "move" );
233 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
235 $this->setUserPerm( "" );
236 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ),
237 array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ) );
239 if ( $this->isWikitextNS( NS_MAIN
) ) {
240 //NOTE: some content models don't allow moving
241 //@todo: find a Wikitext namespace for testing
243 $this->setTitle( NS_MAIN
);
244 $this->setUser( 'anon' );
245 $this->setUserPerm( "move" );
246 $this->runGroupPermissions( 'move', array( ) );
248 $this->setUserPerm( "" );
249 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ),
250 array( array( 'movenologintext' ) ) );
252 $this->setUser( $this->userName
);
253 $this->setUserPerm( "" );
254 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ) );
256 $this->setUserPerm( "move" );
257 $this->runGroupPermissions( 'move', array( ) );
259 $this->setUser( 'anon' );
260 $this->setUserPerm( 'move' );
261 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
262 $this->assertEquals( array( ), $res );
264 $this->setUserPerm( '' );
265 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
266 $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
269 $this->setTitle( NS_USER
);
270 $this->setUser( $this->userName
);
271 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
272 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
273 $this->assertEquals( array( ), $res );
275 $this->setUserPerm( "move" );
276 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
277 $this->assertEquals( array( array( 'cant-move-to-user-page' ) ), $res );
279 $this->setUser( 'anon' );
280 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
281 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
282 $this->assertEquals( array( ), $res );
284 $this->setTitle( NS_USER
, "User/subpage" );
285 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
286 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
287 $this->assertEquals( array( ), $res );
289 $this->setUserPerm( "move" );
290 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
291 $this->assertEquals( array( ), $res );
293 $this->setUser( 'anon' );
294 $check = array( 'edit' => array( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ) ),
295 array( array( 'badaccess-group0' ) ),
297 'protect' => array( array( array( 'badaccess-groups', "[[$prefix:Administrators|Administrators]]", 1 ), array( 'protect-cantedit' ) ),
298 array( array( 'badaccess-group0' ), array( 'protect-cantedit' ) ),
299 array( array( 'protect-cantedit' ) ), false ),
300 '' => array( array( ), array( ), array( ), true ) );
302 $wgUser = $this->user
;
303 foreach ( array( "edit", "protect", "" ) as $action ) {
304 $this->setUserPerm( null );
305 $this->assertEquals( $check[$action][0],
306 $this->title
->getUserPermissionsErrors( $action, $this->user
, true ) );
308 global $wgGroupPermissions;
309 $old = $wgGroupPermissions;
310 $wgGroupPermissions = array();
312 $this->assertEquals( $check[$action][1],
313 $this->title
->getUserPermissionsErrors( $action, $this->user
, true ) );
314 $wgGroupPermissions = $old;
316 $this->setUserPerm( $action );
317 $this->assertEquals( $check[$action][2],
318 $this->title
->getUserPermissionsErrors( $action, $this->user
, true ) );
320 $this->setUserPerm( $action );
321 $this->assertEquals( $check[$action][3],
322 $this->title
->userCan( $action, true ) );
323 $this->assertEquals( $check[$action][3],
324 $this->title
->quickUserCan( $action ) );
326 # count( User::getGroupsWithPermissions( $action ) ) < 1
330 function runGroupPermissions( $action, $result, $result2 = null ) {
331 global $wgGroupPermissions;
333 if ( $result2 === null ) $result2 = $result;
335 $wgGroupPermissions['autoconfirmed']['move'] = false;
336 $wgGroupPermissions['user']['move'] = false;
337 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
338 $this->assertEquals( $result, $res );
340 $wgGroupPermissions['autoconfirmed']['move'] = true;
341 $wgGroupPermissions['user']['move'] = false;
342 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
343 $this->assertEquals( $result2, $res );
345 $wgGroupPermissions['autoconfirmed']['move'] = true;
346 $wgGroupPermissions['user']['move'] = true;
347 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
348 $this->assertEquals( $result2, $res );
350 $wgGroupPermissions['autoconfirmed']['move'] = false;
351 $wgGroupPermissions['user']['move'] = true;
352 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
353 $this->assertEquals( $result2, $res );
356 function testSpecialsAndNSPermissions() {
357 global $wgNamespaceProtection;
358 $this->setUser( $this->userName
);
360 $this->setTitle( NS_SPECIAL
);
362 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'ns-specialprotected' ) ),
363 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
364 $this->assertEquals( array( array( 'badaccess-group0' ) ),
365 $this->title
->getUserPermissionsErrors( 'execute', $this->user
) );
367 $this->setTitle( NS_MAIN
);
368 $this->setUserPerm( 'bogus' );
369 $this->assertEquals( array( ),
370 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
372 $this->setTitle( NS_MAIN
);
373 $this->setUserPerm( '' );
374 $this->assertEquals( array( array( 'badaccess-group0' ) ),
375 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
377 $wgNamespaceProtection[NS_USER
] = array( 'bogus' );
379 $this->setTitle( NS_USER
);
380 $this->setUserPerm( '' );
381 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'namespaceprotected', 'User' ) ),
382 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
384 $this->setTitle( NS_MEDIAWIKI
);
385 $this->setUserPerm( 'bogus' );
386 $this->assertEquals( array( array( 'protectedinterface' ) ),
387 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
389 $this->setTitle( NS_MEDIAWIKI
);
390 $this->setUserPerm( 'bogus' );
391 $this->assertEquals( array( array( 'protectedinterface' ) ),
392 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
394 $wgNamespaceProtection = null;
396 $this->setUserPerm( 'bogus' );
397 $this->assertEquals( array( ),
398 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
399 $this->assertEquals( true,
400 $this->title
->userCan( 'bogus' ) );
402 $this->setUserPerm( '' );
403 $this->assertEquals( array( array( 'badaccess-group0' ) ),
404 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
405 $this->assertEquals( false,
406 $this->title
->userCan( 'bogus' ) );
409 function testCssAndJavascriptPermissions() {
410 $this->setUser( $this->userName
);
412 $this->setTitle( NS_USER
, $this->altUserName
. '/test.js' );
413 $this->runCSSandJSPermissions(
414 array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
415 array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
416 array( array( 'badaccess-group0' ) ) );
418 $this->setTitle( NS_USER
, $this->altUserName
. '/test.css' );
419 $this->runCSSandJSPermissions(
420 array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ),
421 array( array( 'badaccess-group0' ) ),
422 array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ) );
424 $this->setTitle( NS_USER
, $this->altUserName
. '/tempo' );
425 $this->runCSSandJSPermissions(
426 array( array( 'badaccess-group0' ) ),
427 array( array( 'badaccess-group0' ) ),
428 array( array( 'badaccess-group0' ) ) );
431 function runCSSandJSPermissions( $result0, $result1, $result2 ) {
432 $this->setUserPerm( '' );
433 $this->assertEquals( $result0,
434 $this->title
->getUserPermissionsErrors( 'bogus',
437 $this->setUserPerm( 'editusercss' );
438 $this->assertEquals( $result1,
439 $this->title
->getUserPermissionsErrors( 'bogus',
442 $this->setUserPerm( 'edituserjs' );
443 $this->assertEquals( $result2,
444 $this->title
->getUserPermissionsErrors( 'bogus',
447 $this->setUserPerm( 'editusercssjs' );
448 $this->assertEquals( array( array( 'badaccess-group0' ) ),
449 $this->title
->getUserPermissionsErrors( 'bogus',
452 $this->setUserPerm( array( 'edituserjs', 'editusercss' ) );
453 $this->assertEquals( array( array( 'badaccess-group0' ) ),
454 $this->title
->getUserPermissionsErrors( 'bogus',
458 function testPageRestrictions() {
459 global $wgUser, $wgContLang;
461 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT
);
463 $wgUser = $this->user
;
464 $this->setTitle( NS_MAIN
);
465 $this->title
->mRestrictionsLoaded
= true;
466 $this->setUserPerm( "edit" );
467 $this->title
->mRestrictions
= array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
469 $this->assertEquals( array( ),
470 $this->title
->getUserPermissionsErrors( 'edit',
473 $this->assertEquals( true,
474 $this->title
->quickUserCan( 'edit' ) );
475 $this->title
->mRestrictions
= array( "edit" => array( 'bogus', "sysop", "protect", "" ),
476 "bogus" => array( 'bogus', "sysop", "protect", "" ) );
478 $this->assertEquals( array( array( 'badaccess-group0' ),
479 array( 'protectedpagetext', 'bogus' ),
480 array( 'protectedpagetext', 'protect' ),
481 array( 'protectedpagetext', 'protect' ) ),
482 $this->title
->getUserPermissionsErrors( 'bogus',
484 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
485 array( 'protectedpagetext', 'protect' ),
486 array( 'protectedpagetext', 'protect' ) ),
487 $this->title
->getUserPermissionsErrors( 'edit',
489 $this->setUserPerm( "" );
490 $this->assertEquals( array( array( 'badaccess-group0' ),
491 array( 'protectedpagetext', 'bogus' ),
492 array( 'protectedpagetext', 'protect' ),
493 array( 'protectedpagetext', 'protect' ) ),
494 $this->title
->getUserPermissionsErrors( 'bogus',
496 $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ),
497 array( 'protectedpagetext', 'bogus' ),
498 array( 'protectedpagetext', 'protect' ),
499 array( 'protectedpagetext', 'protect' ) ),
500 $this->title
->getUserPermissionsErrors( 'edit',
502 $this->setUserPerm( array( "edit", "editprotected" ) );
503 $this->assertEquals( array( array( 'badaccess-group0' ),
504 array( 'protectedpagetext', 'bogus' ),
505 array( 'protectedpagetext', 'protect' ),
506 array( 'protectedpagetext', 'protect' ) ),
507 $this->title
->getUserPermissionsErrors( 'bogus',
509 $this->assertEquals( array( ),
510 $this->title
->getUserPermissionsErrors( 'edit',
512 $this->title
->mCascadeRestriction
= true;
513 $this->assertEquals( false,
514 $this->title
->quickUserCan( 'bogus' ) );
515 $this->assertEquals( false,
516 $this->title
->quickUserCan( 'edit' ) );
517 $this->assertEquals( array( array( 'badaccess-group0' ),
518 array( 'protectedpagetext', 'bogus' ),
519 array( 'protectedpagetext', 'protect' ),
520 array( 'protectedpagetext', 'protect' ) ),
521 $this->title
->getUserPermissionsErrors( 'bogus',
523 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
524 array( 'protectedpagetext', 'protect' ),
525 array( 'protectedpagetext', 'protect' ) ),
526 $this->title
->getUserPermissionsErrors( 'edit',
530 function testCascadingSourcesRestrictions() {
532 $wgUser = $this->user
;
533 $this->setTitle( NS_MAIN
, "test page" );
534 $this->setUserPerm( array( "edit", "bogus" ) );
536 $this->title
->mCascadeSources
= array( Title
::makeTitle( NS_MAIN
, "Bogus" ), Title
::makeTitle( NS_MAIN
, "UnBogus" ) );
537 $this->title
->mCascadingRestrictions
= array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
539 $this->assertEquals( false,
540 $this->title
->userCan( 'bogus' ) );
541 $this->assertEquals( array( array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ),
542 array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ) ),
543 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
545 $this->assertEquals( true,
546 $this->title
->userCan( 'edit' ) );
547 $this->assertEquals( array( ),
548 $this->title
->getUserPermissionsErrors( 'edit', $this->user
) );
552 function testActionPermissions() {
554 $wgUser = $this->user
;
556 $this->setUserPerm( array( "createpage" ) );
557 $this->setTitle( NS_MAIN
, "test page" );
558 $this->title
->mTitleProtection
['pt_create_perm'] = '';
559 $this->title
->mTitleProtection
['pt_user'] = $this->user
->getID();
560 $this->title
->mTitleProtection
['pt_expiry'] = wfGetDB( DB_SLAVE
)->getInfinity();
561 $this->title
->mTitleProtection
['pt_reason'] = 'test';
562 $this->title
->mCascadeRestriction
= false;
564 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
565 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
566 $this->assertEquals( false,
567 $this->title
->userCan( 'create' ) );
569 $this->title
->mTitleProtection
['pt_create_perm'] = 'sysop';
570 $this->setUserPerm( array( 'createpage', 'protect' ) );
571 $this->assertEquals( array( ),
572 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
573 $this->assertEquals( true,
574 $this->title
->userCan( 'create' ) );
577 $this->setUserPerm( array( 'createpage' ) );
578 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
579 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
580 $this->assertEquals( false,
581 $this->title
->userCan( 'create' ) );
583 $this->setTitle( NS_MEDIA
, "test page" );
584 $this->setUserPerm( array( "move" ) );
585 $this->assertEquals( false,
586 $this->title
->userCan( 'move' ) );
587 $this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ),
588 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
590 $this->setTitle( NS_HELP
, "test page" );
591 $this->assertEquals( array( ),
592 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
593 $this->assertEquals( true,
594 $this->title
->userCan( 'move' ) );
596 $this->title
->mInterwiki
= "no";
597 $this->assertEquals( array( array( 'immobile-source-page' ) ),
598 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
599 $this->assertEquals( false,
600 $this->title
->userCan( 'move' ) );
602 $this->setTitle( NS_MEDIA
, "test page" );
603 $this->assertEquals( false,
604 $this->title
->userCan( 'move-target' ) );
605 $this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ),
606 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
608 $this->setTitle( NS_HELP
, "test page" );
609 $this->assertEquals( array( ),
610 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
611 $this->assertEquals( true,
612 $this->title
->userCan( 'move-target' ) );
614 $this->title
->mInterwiki
= "no";
615 $this->assertEquals( array( array( 'immobile-target-page' ) ),
616 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
617 $this->assertEquals( false,
618 $this->title
->userCan( 'move-target' ) );
622 function testUserBlock() {
623 global $wgUser, $wgEmailConfirmToEdit, $wgEmailAuthentication;
624 $wgEmailConfirmToEdit = true;
625 $wgEmailAuthentication = true;
626 $wgUser = $this->user
;
628 $this->setUserPerm( array( "createpage", "move" ) );
629 $this->setTitle( NS_HELP
, "test page" );
632 $this->assertEquals( array( array( 'confirmedittext' ) ),
633 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
634 $wgEmailConfirmToEdit = false;
635 $this->assertEquals( true, $this->title
->userCan( 'move-target' ) );
637 # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
638 $this->assertEquals( array( ),
639 $this->title
->getUserPermissionsErrors( 'move-target',
645 $this->user
->mBlockedby
= $this->user
->getId();
646 $this->user
->mBlock
= new Block( '127.0.8.1', 0, $this->user
->getId(),
647 'no reason given', $prev +
3600, 1, 0 );
648 $this->user
->mBlock
->mTimestamp
= 0;
649 $this->assertEquals( array( array( 'autoblockedtext',
650 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
651 'Useruser', null, 'infinite', '127.0.8.1',
652 $wgLang->timeanddate( wfTimestamp( TS_MW
, $prev ), true ) ) ),
653 $this->title
->getUserPermissionsErrors( 'move-target',
656 $this->assertEquals( false, $this->title
->userCan( 'move-target' ) );
657 // quickUserCan should ignore user blocks
658 $this->assertEquals( true, $this->title
->quickUserCan( 'move-target' ) );
660 global $wgLocalTZoffset;
661 $wgLocalTZoffset = -60;
662 $this->user
->mBlockedby
= $this->user
->getName();
663 $this->user
->mBlock
= new Block( '127.0.8.1', 0, 1, 'no reason given', $now, 0, 10 );
664 $this->assertEquals( array( array( 'blockedtext',
665 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
666 'Useruser', null, '23:00, 31 December 1969', '127.0.8.1',
667 $wgLang->timeanddate( wfTimestamp( TS_MW
, $now ), true ) ) ),
668 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
670 # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
671 # $user->blockedFor() == ''
672 # $user->mBlock->mExpiry == 'infinity'