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 ) {
332 $wgGroupPermissions['autoconfirmed']['move'] = false;
333 $wgGroupPermissions['user']['move'] = false;
334 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
335 $this->assertEquals( $result, $res );
337 $wgGroupPermissions['autoconfirmed']['move'] = true;
338 $wgGroupPermissions['user']['move'] = false;
339 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
340 $this->assertEquals( $result2, $res );
342 $wgGroupPermissions['autoconfirmed']['move'] = true;
343 $wgGroupPermissions['user']['move'] = true;
344 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
345 $this->assertEquals( $result2, $res );
347 $wgGroupPermissions['autoconfirmed']['move'] = false;
348 $wgGroupPermissions['user']['move'] = true;
349 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
350 $this->assertEquals( $result2, $res );
353 function testSpecialsAndNSPermissions() {
354 global $wgNamespaceProtection;
355 $this->setUser( $this->userName
);
357 $this->setTitle( NS_SPECIAL
);
359 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'ns-specialprotected' ) ),
360 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
362 $this->setTitle( NS_MAIN
);
363 $this->setUserPerm( 'bogus' );
364 $this->assertEquals( array(),
365 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
367 $this->setTitle( NS_MAIN
);
368 $this->setUserPerm( '' );
369 $this->assertEquals( array( array( 'badaccess-group0' ) ),
370 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
372 $wgNamespaceProtection[NS_USER
] = array( 'bogus' );
374 $this->setTitle( NS_USER
);
375 $this->setUserPerm( '' );
376 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'namespaceprotected', 'User' ) ),
377 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
379 $this->setTitle( NS_MEDIAWIKI
);
380 $this->setUserPerm( 'bogus' );
381 $this->assertEquals( array( array( 'protectedinterface' ) ),
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 $wgNamespaceProtection = null;
391 $this->setUserPerm( 'bogus' );
392 $this->assertEquals( array(),
393 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
394 $this->assertEquals( true,
395 $this->title
->userCan( 'bogus', $this->user
) );
397 $this->setUserPerm( '' );
398 $this->assertEquals( array( array( 'badaccess-group0' ) ),
399 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
400 $this->assertEquals( false,
401 $this->title
->userCan( 'bogus', $this->user
) );
404 function testCssAndJavascriptPermissions() {
405 $this->setUser( $this->userName
);
407 $this->setTitle( NS_USER
, $this->altUserName
. '/test.js' );
408 $this->runCSSandJSPermissions(
409 array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
410 array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
411 array( array( 'badaccess-group0' ) ) );
413 $this->setTitle( NS_USER
, $this->altUserName
. '/test.css' );
414 $this->runCSSandJSPermissions(
415 array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ),
416 array( array( 'badaccess-group0' ) ),
417 array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ) );
419 $this->setTitle( NS_USER
, $this->altUserName
. '/tempo' );
420 $this->runCSSandJSPermissions(
421 array( array( 'badaccess-group0' ) ),
422 array( array( 'badaccess-group0' ) ),
423 array( array( 'badaccess-group0' ) ) );
426 function runCSSandJSPermissions( $result0, $result1, $result2 ) {
427 $this->setUserPerm( '' );
428 $this->assertEquals( $result0,
429 $this->title
->getUserPermissionsErrors( 'bogus',
432 $this->setUserPerm( 'editusercss' );
433 $this->assertEquals( $result1,
434 $this->title
->getUserPermissionsErrors( 'bogus',
437 $this->setUserPerm( 'edituserjs' );
438 $this->assertEquals( $result2,
439 $this->title
->getUserPermissionsErrors( 'bogus',
442 $this->setUserPerm( 'editusercssjs' );
443 $this->assertEquals( array( array( 'badaccess-group0' ) ),
444 $this->title
->getUserPermissionsErrors( 'bogus',
447 $this->setUserPerm( array( 'edituserjs', 'editusercss' ) );
448 $this->assertEquals( array( array( 'badaccess-group0' ) ),
449 $this->title
->getUserPermissionsErrors( 'bogus',
453 function testPageRestrictions() {
456 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT
);
458 $this->setTitle( NS_MAIN
);
459 $this->title
->mRestrictionsLoaded
= true;
460 $this->setUserPerm( "edit" );
461 $this->title
->mRestrictions
= array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
463 $this->assertEquals( array(),
464 $this->title
->getUserPermissionsErrors( 'edit',
467 $this->assertEquals( true,
468 $this->title
->quickUserCan( 'edit', $this->user
) );
469 $this->title
->mRestrictions
= array( "edit" => array( 'bogus', "sysop", "protect", "" ),
470 "bogus" => array( 'bogus', "sysop", "protect", "" ) );
472 $this->assertEquals( array( array( 'badaccess-group0' ),
473 array( 'protectedpagetext', 'bogus' ),
474 array( 'protectedpagetext', 'protect' ),
475 array( 'protectedpagetext', 'protect' ) ),
476 $this->title
->getUserPermissionsErrors( 'bogus',
478 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
479 array( 'protectedpagetext', 'protect' ),
480 array( 'protectedpagetext', 'protect' ) ),
481 $this->title
->getUserPermissionsErrors( 'edit',
483 $this->setUserPerm( "" );
484 $this->assertEquals( array( array( 'badaccess-group0' ),
485 array( 'protectedpagetext', 'bogus' ),
486 array( 'protectedpagetext', 'protect' ),
487 array( 'protectedpagetext', 'protect' ) ),
488 $this->title
->getUserPermissionsErrors( 'bogus',
490 $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ),
491 array( 'protectedpagetext', 'bogus' ),
492 array( 'protectedpagetext', 'protect' ),
493 array( 'protectedpagetext', 'protect' ) ),
494 $this->title
->getUserPermissionsErrors( 'edit',
496 $this->setUserPerm( array( "edit", "editprotected" ) );
497 $this->assertEquals( array( array( 'badaccess-group0' ),
498 array( 'protectedpagetext', 'bogus' ),
499 array( 'protectedpagetext', 'protect' ),
500 array( 'protectedpagetext', 'protect' ) ),
501 $this->title
->getUserPermissionsErrors( 'bogus',
503 $this->assertEquals( array(),
504 $this->title
->getUserPermissionsErrors( 'edit',
506 $this->title
->mCascadeRestriction
= true;
507 $this->assertEquals( false,
508 $this->title
->quickUserCan( 'bogus', $this->user
) );
509 $this->assertEquals( false,
510 $this->title
->quickUserCan( 'edit', $this->user
) );
511 $this->assertEquals( array( array( 'badaccess-group0' ),
512 array( 'protectedpagetext', 'bogus' ),
513 array( 'protectedpagetext', 'protect' ),
514 array( 'protectedpagetext', 'protect' ) ),
515 $this->title
->getUserPermissionsErrors( 'bogus',
517 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
518 array( 'protectedpagetext', 'protect' ),
519 array( 'protectedpagetext', 'protect' ) ),
520 $this->title
->getUserPermissionsErrors( 'edit',
524 function testCascadingSourcesRestrictions() {
525 $this->setTitle( NS_MAIN
, "test page" );
526 $this->setUserPerm( array( "edit", "bogus" ) );
528 $this->title
->mCascadeSources
= array( Title
::makeTitle( NS_MAIN
, "Bogus" ), Title
::makeTitle( NS_MAIN
, "UnBogus" ) );
529 $this->title
->mCascadingRestrictions
= array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
531 $this->assertEquals( false,
532 $this->title
->userCan( 'bogus', $this->user
) );
533 $this->assertEquals( array( array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ),
534 array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ) ),
535 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
537 $this->assertEquals( true,
538 $this->title
->userCan( 'edit', $this->user
) );
539 $this->assertEquals( array(),
540 $this->title
->getUserPermissionsErrors( 'edit', $this->user
) );
544 function testActionPermissions() {
545 $this->setUserPerm( array( "createpage" ) );
546 $this->setTitle( NS_MAIN
, "test page" );
547 $this->title
->mTitleProtection
['pt_create_perm'] = '';
548 $this->title
->mTitleProtection
['pt_user'] = $this->user
->getID();
549 $this->title
->mTitleProtection
['pt_expiry'] = wfGetDB( DB_SLAVE
)->getInfinity();
550 $this->title
->mTitleProtection
['pt_reason'] = 'test';
551 $this->title
->mCascadeRestriction
= false;
553 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
554 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
555 $this->assertEquals( false,
556 $this->title
->userCan( 'create', $this->user
) );
558 $this->title
->mTitleProtection
['pt_create_perm'] = 'sysop';
559 $this->setUserPerm( array( 'createpage', 'protect' ) );
560 $this->assertEquals( array(),
561 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
562 $this->assertEquals( true,
563 $this->title
->userCan( 'create', $this->user
) );
566 $this->setUserPerm( array( 'createpage' ) );
567 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
568 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
569 $this->assertEquals( false,
570 $this->title
->userCan( 'create', $this->user
) );
572 $this->setTitle( NS_MEDIA
, "test page" );
573 $this->setUserPerm( array( "move" ) );
574 $this->assertEquals( false,
575 $this->title
->userCan( 'move', $this->user
) );
576 $this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ),
577 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
579 $this->setTitle( NS_HELP
, "test page" );
580 $this->assertEquals( array(),
581 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
582 $this->assertEquals( true,
583 $this->title
->userCan( 'move', $this->user
) );
585 $this->title
->mInterwiki
= "no";
586 $this->assertEquals( array( array( 'immobile-source-page' ) ),
587 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
588 $this->assertEquals( false,
589 $this->title
->userCan( 'move', $this->user
) );
591 $this->setTitle( NS_MEDIA
, "test page" );
592 $this->assertEquals( false,
593 $this->title
->userCan( 'move-target', $this->user
) );
594 $this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ),
595 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
597 $this->setTitle( NS_HELP
, "test page" );
598 $this->assertEquals( array(),
599 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
600 $this->assertEquals( true,
601 $this->title
->userCan( 'move-target', $this->user
) );
603 $this->title
->mInterwiki
= "no";
604 $this->assertEquals( array( array( 'immobile-target-page' ) ),
605 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
606 $this->assertEquals( false,
607 $this->title
->userCan( 'move-target', $this->user
) );
611 function testUserBlock() {
612 global $wgEmailConfirmToEdit, $wgEmailAuthentication;
613 $wgEmailConfirmToEdit = true;
614 $wgEmailAuthentication = true;
616 $this->setUserPerm( array( "createpage", "move" ) );
617 $this->setTitle( NS_HELP
, "test page" );
620 $this->assertEquals( array( array( 'confirmedittext' ) ),
621 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
622 $wgEmailConfirmToEdit = false;
623 $this->assertEquals( true, $this->title
->userCan( 'move-target', $this->user
) );
625 # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
626 $this->assertEquals( array(),
627 $this->title
->getUserPermissionsErrors( 'move-target',
633 $this->user
->mBlockedby
= $this->user
->getId();
634 $this->user
->mBlock
= new Block( '127.0.8.1', 0, $this->user
->getId(),
635 'no reason given', $prev +
3600, 1, 0 );
636 $this->user
->mBlock
->mTimestamp
= 0;
637 $this->assertEquals( array( array( 'autoblockedtext',
638 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
639 'Useruser', null, 'infinite', '127.0.8.1',
640 $wgLang->timeanddate( wfTimestamp( TS_MW
, $prev ), true ) ) ),
641 $this->title
->getUserPermissionsErrors( 'move-target',
644 $this->assertEquals( false, $this->title
->userCan( 'move-target', $this->user
) );
645 // quickUserCan should ignore user blocks
646 $this->assertEquals( true, $this->title
->quickUserCan( 'move-target', $this->user
) );
648 global $wgLocalTZoffset;
649 $wgLocalTZoffset = -60;
650 $this->user
->mBlockedby
= $this->user
->getName();
651 $this->user
->mBlock
= new Block( '127.0.8.1', 0, 1, 'no reason given', $now, 0, 10 );
652 $this->assertEquals( array( array( 'blockedtext',
653 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
654 'Useruser', null, '23:00, 31 December 1969', '127.0.8.1',
655 $wgLang->timeanddate( wfTimestamp( TS_MW
, $now ), true ) ) ),
656 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
658 # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
659 # $user->blockedFor() == ''
660 # $user->mBlock->mExpiry == 'infinity'