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 $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 );
264 $this->setTitle( NS_USER
);
265 $this->setUser( $this->userName
);
266 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
267 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
268 $this->assertEquals( array( ), $res );
270 $this->setUserPerm( "move" );
271 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
272 $this->assertEquals( array( array( 'cant-move-to-user-page' ) ), $res );
274 $this->setUser( 'anon' );
275 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
276 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
277 $this->assertEquals( array( ), $res );
279 $this->setTitle( NS_USER
, "User/subpage" );
280 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
281 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
282 $this->assertEquals( array( ), $res );
284 $this->setUserPerm( "move" );
285 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
286 $this->assertEquals( array( ), $res );
288 $this->setUser( 'anon' );
289 $check = array( 'edit' => array( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ) ),
290 array( array( 'badaccess-group0' ) ),
292 'protect' => array( array( array( 'badaccess-groups', "[[$prefix:Administrators|Administrators]]", 1 ), array( 'protect-cantedit' ) ),
293 array( array( 'badaccess-group0' ), array( 'protect-cantedit' ) ),
294 array( array( 'protect-cantedit' ) ), false ),
295 '' => array( array( ), array( ), array( ), true ) );
297 $wgUser = $this->user
;
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, true ) );
318 $this->assertEquals( $check[$action][3],
319 $this->title
->quickUserCan( $action ) );
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
) );
359 $this->assertEquals( array( array( 'badaccess-group0' ) ),
360 $this->title
->getUserPermissionsErrors( 'execute', $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' ) );
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' ) );
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() {
454 global $wgUser, $wgContLang;
456 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT
);
458 $wgUser = $this->user
;
459 $this->setTitle( NS_MAIN
);
460 $this->title
->mRestrictionsLoaded
= true;
461 $this->setUserPerm( "edit" );
462 $this->title
->mRestrictions
= array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
464 $this->assertEquals( array( ),
465 $this->title
->getUserPermissionsErrors( 'edit',
468 $this->assertEquals( true,
469 $this->title
->quickUserCan( 'edit' ) );
470 $this->title
->mRestrictions
= array( "edit" => array( 'bogus', "sysop", "protect", "" ),
471 "bogus" => array( 'bogus', "sysop", "protect", "" ) );
473 $this->assertEquals( array( array( 'badaccess-group0' ),
474 array( 'protectedpagetext', 'bogus' ),
475 array( 'protectedpagetext', 'protect' ),
476 array( 'protectedpagetext', 'protect' ) ),
477 $this->title
->getUserPermissionsErrors( 'bogus',
479 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
480 array( 'protectedpagetext', 'protect' ),
481 array( 'protectedpagetext', 'protect' ) ),
482 $this->title
->getUserPermissionsErrors( 'edit',
484 $this->setUserPerm( "" );
485 $this->assertEquals( array( array( 'badaccess-group0' ),
486 array( 'protectedpagetext', 'bogus' ),
487 array( 'protectedpagetext', 'protect' ),
488 array( 'protectedpagetext', 'protect' ) ),
489 $this->title
->getUserPermissionsErrors( 'bogus',
491 $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ),
492 array( 'protectedpagetext', 'bogus' ),
493 array( 'protectedpagetext', 'protect' ),
494 array( 'protectedpagetext', 'protect' ) ),
495 $this->title
->getUserPermissionsErrors( 'edit',
497 $this->setUserPerm( array( "edit", "editprotected" ) );
498 $this->assertEquals( array( array( 'badaccess-group0' ),
499 array( 'protectedpagetext', 'bogus' ),
500 array( 'protectedpagetext', 'protect' ),
501 array( 'protectedpagetext', 'protect' ) ),
502 $this->title
->getUserPermissionsErrors( 'bogus',
504 $this->assertEquals( array( ),
505 $this->title
->getUserPermissionsErrors( 'edit',
507 $this->title
->mCascadeRestriction
= true;
508 $this->assertEquals( false,
509 $this->title
->quickUserCan( 'bogus' ) );
510 $this->assertEquals( false,
511 $this->title
->quickUserCan( 'edit' ) );
512 $this->assertEquals( array( array( 'badaccess-group0' ),
513 array( 'protectedpagetext', 'bogus' ),
514 array( 'protectedpagetext', 'protect' ),
515 array( 'protectedpagetext', 'protect' ) ),
516 $this->title
->getUserPermissionsErrors( 'bogus',
518 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
519 array( 'protectedpagetext', 'protect' ),
520 array( 'protectedpagetext', 'protect' ) ),
521 $this->title
->getUserPermissionsErrors( 'edit',
525 function testCascadingSourcesRestrictions() {
527 $wgUser = $this->user
;
528 $this->setTitle( NS_MAIN
, "test page" );
529 $this->setUserPerm( array( "edit", "bogus" ) );
531 $this->title
->mCascadeSources
= array( Title
::makeTitle( NS_MAIN
, "Bogus" ), Title
::makeTitle( NS_MAIN
, "UnBogus" ) );
532 $this->title
->mCascadingRestrictions
= array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
534 $this->assertEquals( false,
535 $this->title
->userCan( 'bogus' ) );
536 $this->assertEquals( array( array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ),
537 array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ) ),
538 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
540 $this->assertEquals( true,
541 $this->title
->userCan( 'edit' ) );
542 $this->assertEquals( array( ),
543 $this->title
->getUserPermissionsErrors( 'edit', $this->user
) );
547 function testActionPermissions() {
549 $wgUser = $this->user
;
551 $this->setUserPerm( array( "createpage" ) );
552 $this->setTitle( NS_MAIN
, "test page" );
553 $this->title
->mTitleProtection
['pt_create_perm'] = '';
554 $this->title
->mTitleProtection
['pt_user'] = $this->user
->getID();
555 $this->title
->mTitleProtection
['pt_expiry'] = wfGetDB( DB_SLAVE
)->getInfinity();
556 $this->title
->mTitleProtection
['pt_reason'] = 'test';
557 $this->title
->mCascadeRestriction
= false;
559 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
560 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
561 $this->assertEquals( false,
562 $this->title
->userCan( 'create' ) );
564 $this->title
->mTitleProtection
['pt_create_perm'] = 'sysop';
565 $this->setUserPerm( array( 'createpage', 'protect' ) );
566 $this->assertEquals( array( ),
567 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
568 $this->assertEquals( true,
569 $this->title
->userCan( 'create' ) );
572 $this->setUserPerm( array( 'createpage' ) );
573 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
574 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
575 $this->assertEquals( false,
576 $this->title
->userCan( 'create' ) );
578 $this->setTitle( NS_MEDIA
, "test page" );
579 $this->setUserPerm( array( "move" ) );
580 $this->assertEquals( false,
581 $this->title
->userCan( 'move' ) );
582 $this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ),
583 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
585 $this->setTitle( NS_MAIN
, "test page" );
586 $this->assertEquals( array( ),
587 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
588 $this->assertEquals( true,
589 $this->title
->userCan( 'move' ) );
591 $this->title
->mInterwiki
= "no";
592 $this->assertEquals( array( array( 'immobile-source-page' ) ),
593 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
594 $this->assertEquals( false,
595 $this->title
->userCan( 'move' ) );
597 $this->setTitle( NS_MEDIA
, "test page" );
598 $this->assertEquals( false,
599 $this->title
->userCan( 'move-target' ) );
600 $this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ),
601 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
603 $this->setTitle( NS_MAIN
, "test page" );
604 $this->assertEquals( array( ),
605 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
606 $this->assertEquals( true,
607 $this->title
->userCan( 'move-target' ) );
609 $this->title
->mInterwiki
= "no";
610 $this->assertEquals( array( array( 'immobile-target-page' ) ),
611 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
612 $this->assertEquals( false,
613 $this->title
->userCan( 'move-target' ) );
617 function testUserBlock() {
618 global $wgUser, $wgEmailConfirmToEdit, $wgEmailAuthentication;
619 $wgEmailConfirmToEdit = true;
620 $wgEmailAuthentication = true;
621 $wgUser = $this->user
;
623 $this->setUserPerm( array( "createpage", "move" ) );
624 $this->setTitle( NS_MAIN
, "test page" );
627 $this->assertEquals( array( array( 'confirmedittext' ) ),
628 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
629 $wgEmailConfirmToEdit = false;
630 $this->assertEquals( true, $this->title
->userCan( 'move-target' ) );
632 # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
633 $this->assertEquals( array( ),
634 $this->title
->getUserPermissionsErrors( 'move-target',
640 $this->user
->mBlockedby
= $this->user
->getId();
641 $this->user
->mBlock
= new Block( '127.0.8.1', 0, $this->user
->getId(),
642 'no reason given', $prev +
3600, 1, 0 );
643 $this->user
->mBlock
->mTimestamp
= 0;
644 $this->assertEquals( array( array( 'autoblockedtext',
645 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
646 'Useruser', null, 'infinite', '127.0.8.1',
647 $wgLang->timeanddate( wfTimestamp( TS_MW
, $prev ), true ) ) ),
648 $this->title
->getUserPermissionsErrors( 'move-target',
651 $this->assertEquals( false, $this->title
->userCan( 'move-target' ) );
652 // quickUserCan should ignore user blocks
653 $this->assertEquals( true, $this->title
->quickUserCan( 'move-target' ) );
655 global $wgLocalTZoffset;
656 $wgLocalTZoffset = -60;
657 $this->user
->mBlockedby
= $this->user
->getName();
658 $this->user
->mBlock
= new Block( '127.0.8.1', 0, 1, 'no reason given', $now, 0, 10 );
659 $this->assertEquals( array( array( 'blockedtext',
660 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
661 'Useruser', null, '23:00, 31 December 1969', '127.0.8.1',
662 $wgLang->timeanddate( wfTimestamp( TS_MW
, $now ), true ) ) ),
663 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
665 # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
666 # $user->blockedFor() == ''
667 # $user->mBlock->mExpiry == 'infinity'