6 class TitlePermissionTest
extends MediaWikiLangTestCase
{
12 protected $user, $anonUser, $userUser, $altUser;
17 protected $userName, $altUserName;
20 global $wgLocaltimezone, $wgLocalTZoffset, $wgMemc, $wgContLang, $wgLang;
24 $wgMemc = new EmptyBagOStuff
;
26 $wgContLang = $wgLang = Language
::factory( 'en' );
28 $this->userName
= "Useruser";
29 $this->altUserName
= "Altuseruser";
30 date_default_timezone_set( $wgLocaltimezone );
31 $wgLocalTZoffset = date( "Z" ) / 60;
33 $this->title
= Title
::makeTitle( NS_MAIN
, "Main Page" );
34 if ( !isset( $this->userUser
) ||
!( $this->userUser
instanceOf User
) ) {
35 $this->userUser
= User
::newFromName( $this->userName
);
37 if ( !$this->userUser
->getID() ) {
38 $this->userUser
= User
::createNew( $this->userName
, array(
39 "email" => "test@example.com",
40 "real_name" => "Test User" ) );
41 $this->userUser
->load();
44 $this->altUser
= User
::newFromName( $this->altUserName
);
45 if ( !$this->altUser
->getID() ) {
46 $this->altUser
= User
::createNew( $this->altUserName
, array(
47 "email" => "alttest@example.com",
48 "real_name" => "Test User Alt" ) );
49 $this->altUser
->load();
52 $this->anonUser
= User
::newFromId( 0 );
54 $this->user
= $this->userUser
;
62 function setUserPerm( $perm ) {
63 // Setting member variables is evil!!!
65 if ( !is_array( $perm ) ) {
66 $perm = array( $perm );
68 for ($i = 0; $i < 100; $i++
) {
69 $this->user
->mRights
[$i] = $perm;
72 // Hack, hack hack ...
73 $this->user
->mRights
['*'] = $perm;
76 function setTitle( $ns, $title = "Main_Page" ) {
77 $this->title
= Title
::makeTitle( $ns, $title );
80 function setUser( $userName = null ) {
81 if ( $userName === 'anon' ) {
82 $this->user
= $this->anonUser
;
83 } elseif ( $userName === null ||
$userName === $this->userName
) {
84 $this->user
= $this->userUser
;
86 $this->user
= $this->altUser
;
90 $wgUser = $this->user
;
93 function testQuickPermissions() {
95 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT
);
97 $this->setUser( 'anon' );
98 $this->setTitle( NS_TALK
);
99 $this->setUserPerm( "createtalk" );
100 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
101 $this->assertEquals( array(), $res );
103 $this->setTitle( NS_TALK
);
104 $this->setUserPerm( "createpage" );
105 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
106 $this->assertEquals( array( array( "nocreatetext" ) ), $res );
108 $this->setTitle( NS_TALK
);
109 $this->setUserPerm( "" );
110 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
111 $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
113 $this->setTitle( NS_MAIN
);
114 $this->setUserPerm( "createpage" );
115 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
116 $this->assertEquals( array( ), $res );
118 $this->setTitle( NS_MAIN
);
119 $this->setUserPerm( "createtalk" );
120 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
121 $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
123 $this->setUser( $this->userName
);
124 $this->setTitle( NS_TALK
);
125 $this->setUserPerm( "createtalk" );
126 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
127 $this->assertEquals( array( ), $res );
129 $this->setTitle( NS_TALK
);
130 $this->setUserPerm( "createpage" );
131 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
132 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
134 $this->setTitle( NS_TALK
);
135 $this->setUserPerm( "" );
136 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
137 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
139 $this->setTitle( NS_MAIN
);
140 $this->setUserPerm( "createpage" );
141 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
142 $this->assertEquals( array( ), $res );
144 $this->setTitle( NS_MAIN
);
145 $this->setUserPerm( "createtalk" );
146 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
147 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
149 $this->setTitle( NS_MAIN
);
150 $this->setUserPerm( "" );
151 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
152 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
154 $this->setUser( 'anon' );
155 $this->setTitle( NS_USER
, $this->userName
. '' );
156 $this->setUserPerm( "" );
157 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
158 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
160 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
161 $this->setUserPerm( "" );
162 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
163 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
165 $this->setTitle( NS_USER
, $this->userName
. '' );
166 $this->setUserPerm( "move-rootuserpages" );
167 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
168 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
170 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
171 $this->setUserPerm( "move-rootuserpages" );
172 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
173 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
175 $this->setTitle( NS_USER
, $this->userName
. '' );
176 $this->setUserPerm( "" );
177 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
178 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
180 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
181 $this->setUserPerm( "" );
182 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
183 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
185 $this->setTitle( NS_USER
, $this->userName
. '' );
186 $this->setUserPerm( "move-rootuserpages" );
187 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
188 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
190 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
191 $this->setUserPerm( "move-rootuserpages" );
192 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
193 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
195 $this->setUser( $this->userName
);
196 $this->setTitle( NS_FILE
, "img.png" );
197 $this->setUserPerm( "" );
198 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
199 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ), $res );
201 $this->setTitle( NS_FILE
, "img.png" );
202 $this->setUserPerm( "movefile" );
203 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
204 $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
206 $this->setUser( 'anon' );
207 $this->setTitle( NS_FILE
, "img.png" );
208 $this->setUserPerm( "" );
209 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
210 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ), $res );
212 $this->setTitle( NS_FILE
, "img.png" );
213 $this->setUserPerm( "movefile" );
214 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
215 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
217 $this->setUser( $this->userName
);
218 $this->setUserPerm( "move" );
219 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
221 $this->setUserPerm( "" );
222 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ) );
224 $this->setUser( 'anon' );
225 $this->setUserPerm( "move" );
226 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
228 $this->setUserPerm( "" );
229 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ),
230 array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ) );
232 $this->setTitle( NS_MAIN
);
233 $this->setUser( 'anon' );
234 $this->setUserPerm( "move" );
235 $this->runGroupPermissions( 'move', array( ) );
237 $this->setUserPerm( "" );
238 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ),
239 array( array( 'movenologintext' ) ) );
241 $this->setUser( $this->userName
);
242 $this->setUserPerm( "" );
243 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ) );
245 $this->setUserPerm( "move" );
246 $this->runGroupPermissions( 'move', array( ) );
248 $this->setUser( 'anon' );
249 $this->setUserPerm( 'move' );
250 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
251 $this->assertEquals( array( ), $res );
253 $this->setUserPerm( '' );
254 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
255 $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
257 $this->setTitle( NS_USER
);
258 $this->setUser( $this->userName
);
259 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
260 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
261 $this->assertEquals( array( ), $res );
263 $this->setUserPerm( "move" );
264 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
265 $this->assertEquals( array( array( 'cant-move-to-user-page' ) ), $res );
267 $this->setUser( 'anon' );
268 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
269 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
270 $this->assertEquals( array( ), $res );
272 $this->setTitle( NS_USER
, "User/subpage" );
273 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
274 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
275 $this->assertEquals( array( ), $res );
277 $this->setUserPerm( "move" );
278 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
279 $this->assertEquals( array( ), $res );
281 $this->setUser( 'anon' );
282 $check = array( 'edit' => array( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ) ),
283 array( array( 'badaccess-group0' ) ),
285 'protect' => array( array( array( 'badaccess-groups', "[[$prefix:Administrators|Administrators]]", 1 ), array( 'protect-cantedit' ) ),
286 array( array( 'badaccess-group0' ), array( 'protect-cantedit' ) ),
287 array( array( 'protect-cantedit' ) ), false ),
288 '' => array( array( ), array( ), array( ), true ) );
290 $wgUser = $this->user
;
291 foreach ( array( "edit", "protect", "" ) as $action ) {
292 $this->setUserPerm( null );
293 $this->assertEquals( $check[$action][0],
294 $this->title
->getUserPermissionsErrors( $action, $this->user
, true ) );
296 global $wgGroupPermissions;
297 $old = $wgGroupPermissions;
298 $wgGroupPermissions = array();
300 $this->assertEquals( $check[$action][1],
301 $this->title
->getUserPermissionsErrors( $action, $this->user
, true ) );
302 $wgGroupPermissions = $old;
304 $this->setUserPerm( $action );
305 $this->assertEquals( $check[$action][2],
306 $this->title
->getUserPermissionsErrors( $action, $this->user
, true ) );
308 $this->setUserPerm( $action );
309 $this->assertEquals( $check[$action][3],
310 $this->title
->userCan( $action, true ) );
311 $this->assertEquals( $check[$action][3],
312 $this->title
->quickUserCan( $action, false ) );
314 # count( User::getGroupsWithPermissions( $action ) ) < 1
318 function runGroupPermissions( $action, $result, $result2 = null ) {
319 global $wgGroupPermissions;
321 if ( $result2 === null ) $result2 = $result;
323 $wgGroupPermissions['autoconfirmed']['move'] = false;
324 $wgGroupPermissions['user']['move'] = false;
325 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
326 $this->assertEquals( $result, $res );
328 $wgGroupPermissions['autoconfirmed']['move'] = true;
329 $wgGroupPermissions['user']['move'] = false;
330 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
331 $this->assertEquals( $result2, $res );
333 $wgGroupPermissions['autoconfirmed']['move'] = true;
334 $wgGroupPermissions['user']['move'] = true;
335 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
336 $this->assertEquals( $result2, $res );
338 $wgGroupPermissions['autoconfirmed']['move'] = false;
339 $wgGroupPermissions['user']['move'] = true;
340 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
341 $this->assertEquals( $result2, $res );
344 function testSpecialsAndNSPermissions() {
345 $this->setUser( $this->userName
);
347 $wgUser = $this->user
;
349 $this->setTitle( NS_SPECIAL
);
351 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'ns-specialprotected' ) ),
352 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
353 $this->assertEquals( array( array( 'badaccess-group0' ) ),
354 $this->title
->getUserPermissionsErrors( 'execute', $this->user
) );
356 $this->setTitle( NS_MAIN
);
357 $this->setUserPerm( 'bogus' );
358 $this->assertEquals( array( ),
359 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
361 $this->setTitle( NS_MAIN
);
362 $this->setUserPerm( '' );
363 $this->assertEquals( array( array( 'badaccess-group0' ) ),
364 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
366 global $wgNamespaceProtection;
367 $wgNamespaceProtection[NS_USER
] = array ( 'bogus' );
368 $this->setTitle( NS_USER
);
369 $this->setUserPerm( '' );
370 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'namespaceprotected', 'User' ) ),
371 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
373 $this->setTitle( NS_MEDIAWIKI
);
374 $this->setUserPerm( 'bogus' );
375 $this->assertEquals( array( array( 'protectedinterface' ) ),
376 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
378 $this->setTitle( NS_MEDIAWIKI
);
379 $this->setUserPerm( 'bogus' );
380 $this->assertEquals( array( array( 'protectedinterface' ) ),
381 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
383 $wgNamespaceProtection = null;
384 $this->setUserPerm( 'bogus' );
385 $this->assertEquals( array( ),
386 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
387 $this->assertEquals( true,
388 $this->title
->userCan( 'bogus' ) );
390 $this->setUserPerm( '' );
391 $this->assertEquals( array( array( 'badaccess-group0' ) ),
392 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
393 $this->assertEquals( false,
394 $this->title
->userCan( 'bogus' ) );
397 function testCssAndJavascriptPermissions() {
398 $this->setUser( $this->userName
);
400 $wgUser = $this->user
;
402 $this->setTitle( NS_USER
, $this->altUserName
. '/test.js' );
403 $this->runCSSandJSPermissions(
404 array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
405 array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
406 array( array( 'badaccess-group0' ) ) );
408 $this->setTitle( NS_USER
, $this->altUserName
. '/test.css' );
409 $this->runCSSandJSPermissions(
410 array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ),
411 array( array( 'badaccess-group0' ) ),
412 array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ) );
414 $this->setTitle( NS_USER
, $this->altUserName
. '/tempo' );
415 $this->runCSSandJSPermissions(
416 array( array( 'badaccess-group0' ) ),
417 array( array( 'badaccess-group0' ) ),
418 array( array( 'badaccess-group0' ) ) );
421 function runCSSandJSPermissions( $result0, $result1, $result2 ) {
422 $this->setUserPerm( '' );
423 $this->assertEquals( $result0,
424 $this->title
->getUserPermissionsErrors( 'bogus',
427 $this->setUserPerm( 'editusercss' );
428 $this->assertEquals( $result1,
429 $this->title
->getUserPermissionsErrors( 'bogus',
432 $this->setUserPerm( 'edituserjs' );
433 $this->assertEquals( $result2,
434 $this->title
->getUserPermissionsErrors( 'bogus',
437 $this->setUserPerm( 'editusercssjs' );
438 $this->assertEquals( array( array( 'badaccess-group0' ) ),
439 $this->title
->getUserPermissionsErrors( 'bogus',
442 $this->setUserPerm( array( 'edituserjs', 'editusercss' ) );
443 $this->assertEquals( array( array( 'badaccess-group0' ) ),
444 $this->title
->getUserPermissionsErrors( 'bogus',
448 function testPageRestrictions() {
449 global $wgUser, $wgContLang;
451 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT
);
453 $wgUser = $this->user
;
454 $this->setTitle( NS_MAIN
);
455 $this->title
->mRestrictionsLoaded
= true;
456 $this->setUserPerm( "edit" );
457 $this->title
->mRestrictions
= array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
459 $this->assertEquals( array( ),
460 $this->title
->getUserPermissionsErrors( 'edit',
463 $this->assertEquals( true,
464 $this->title
->quickUserCan( 'edit', false ) );
465 $this->title
->mRestrictions
= array( "edit" => array( 'bogus', "sysop", "protect", "" ),
466 "bogus" => array( 'bogus', "sysop", "protect", "" ) );
468 $this->assertEquals( array( array( 'badaccess-group0' ),
469 array( 'protectedpagetext', 'bogus' ),
470 array( 'protectedpagetext', 'protect' ),
471 array( 'protectedpagetext', 'protect' ) ),
472 $this->title
->getUserPermissionsErrors( 'bogus',
474 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
475 array( 'protectedpagetext', 'protect' ),
476 array( 'protectedpagetext', 'protect' ) ),
477 $this->title
->getUserPermissionsErrors( 'edit',
479 $this->setUserPerm( "" );
480 $this->assertEquals( array( array( 'badaccess-group0' ),
481 array( 'protectedpagetext', 'bogus' ),
482 array( 'protectedpagetext', 'protect' ),
483 array( 'protectedpagetext', 'protect' ) ),
484 $this->title
->getUserPermissionsErrors( 'bogus',
486 $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ),
487 array( 'protectedpagetext', 'bogus' ),
488 array( 'protectedpagetext', 'protect' ),
489 array( 'protectedpagetext', 'protect' ) ),
490 $this->title
->getUserPermissionsErrors( 'edit',
492 $this->setUserPerm( array( "edit", "editprotected" ) );
493 $this->assertEquals( array( array( 'badaccess-group0' ),
494 array( 'protectedpagetext', 'bogus' ),
495 array( 'protectedpagetext', 'protect' ),
496 array( 'protectedpagetext', 'protect' ) ),
497 $this->title
->getUserPermissionsErrors( 'bogus',
499 $this->assertEquals( array( ),
500 $this->title
->getUserPermissionsErrors( 'edit',
502 $this->title
->mCascadeRestriction
= true;
503 $this->assertEquals( false,
504 $this->title
->quickUserCan( 'bogus', false ) );
505 $this->assertEquals( false,
506 $this->title
->quickUserCan( 'edit', false ) );
507 $this->assertEquals( array( array( 'badaccess-group0' ),
508 array( 'protectedpagetext', 'bogus' ),
509 array( 'protectedpagetext', 'protect' ),
510 array( 'protectedpagetext', 'protect' ) ),
511 $this->title
->getUserPermissionsErrors( 'bogus',
513 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
514 array( 'protectedpagetext', 'protect' ),
515 array( 'protectedpagetext', 'protect' ) ),
516 $this->title
->getUserPermissionsErrors( 'edit',
520 function testCascadingSourcesRestrictions() {
522 $wgUser = $this->user
;
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' ) );
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' ) );
537 $this->assertEquals( array( ),
538 $this->title
->getUserPermissionsErrors( 'edit', $this->user
) );
542 function testActionPermissions() {
544 $wgUser = $this->user
;
546 $this->setUserPerm( array( "createpage" ) );
547 $this->setTitle( NS_MAIN
, "test page" );
548 $this->title
->mTitleProtection
['pt_create_perm'] = '';
549 $this->title
->mTitleProtection
['pt_user'] = $this->user
->getID();
550 $this->title
->mTitleProtection
['pt_expiry'] = wfGetDB( DB_SLAVE
)->getInfinity();
551 $this->title
->mTitleProtection
['pt_reason'] = 'test';
552 $this->title
->mCascadeRestriction
= false;
554 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
555 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
556 $this->assertEquals( false,
557 $this->title
->userCan( 'create' ) );
559 $this->title
->mTitleProtection
['pt_create_perm'] = 'sysop';
560 $this->setUserPerm( array( 'createpage', 'protect' ) );
561 $this->assertEquals( array( ),
562 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
563 $this->assertEquals( true,
564 $this->title
->userCan( 'create' ) );
567 $this->setUserPerm( array( 'createpage' ) );
568 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
569 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
570 $this->assertEquals( false,
571 $this->title
->userCan( 'create' ) );
573 $this->setTitle( NS_MEDIA
, "test page" );
574 $this->setUserPerm( array( "move" ) );
575 $this->assertEquals( false,
576 $this->title
->userCan( 'move' ) );
577 $this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ),
578 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
580 $this->setTitle( NS_MAIN
, "test page" );
581 $this->assertEquals( array( ),
582 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
583 $this->assertEquals( true,
584 $this->title
->userCan( 'move' ) );
586 $this->title
->mInterwiki
= "no";
587 $this->assertEquals( array( array( 'immobile-source-page' ) ),
588 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
589 $this->assertEquals( false,
590 $this->title
->userCan( 'move' ) );
592 $this->setTitle( NS_MEDIA
, "test page" );
593 $this->assertEquals( false,
594 $this->title
->userCan( 'move-target' ) );
595 $this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ),
596 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
598 $this->setTitle( NS_MAIN
, "test page" );
599 $this->assertEquals( array( ),
600 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
601 $this->assertEquals( true,
602 $this->title
->userCan( 'move-target' ) );
604 $this->title
->mInterwiki
= "no";
605 $this->assertEquals( array( array( 'immobile-target-page' ) ),
606 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
607 $this->assertEquals( false,
608 $this->title
->userCan( 'move-target' ) );
612 function testUserBlock() {
613 global $wgUser, $wgEmailConfirmToEdit, $wgEmailAuthentication;
614 $wgEmailConfirmToEdit = true;
615 $wgEmailAuthentication = true;
616 $wgUser = $this->user
;
618 $this->setUserPerm( array( "createpage", "move" ) );
619 $this->setTitle( NS_MAIN
, "test page" );
622 $this->assertEquals( array( array( 'confirmedittext' ) ),
623 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
624 $wgEmailConfirmToEdit = false;
625 $this->assertEquals( true, $this->title
->userCan( 'move-target' ) );
627 # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
628 $this->assertEquals( array( ),
629 $this->title
->getUserPermissionsErrors( 'move-target',
635 $this->user
->mBlockedby
= $this->user
->getId();
636 $this->user
->mBlock
= new Block( '127.0.8.1', $this->user
->getId(), $this->user
->getId(),
637 'no reason given', $prev +
3600, 1, 0 );
638 $this->user
->mBlock
->mTimestamp
= 0;
639 $this->assertEquals( array( array( 'autoblockedtext',
640 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
641 'Useruser', null, 'infinite', '127.0.8.1',
642 $wgLang->timeanddate( wfTimestamp( TS_MW
, $prev ), true ) ) ),
643 $this->title
->getUserPermissionsErrors( 'move-target',
646 $this->assertEquals( false, $this->title
->userCan( 'move-target' ) );
647 // quickUserCan should ignore user blocks
648 $this->assertEquals( true, $this->title
->quickUserCan( 'move-target' ) );
650 global $wgLocalTZoffset;
651 $wgLocalTZoffset = -60;
652 $this->user
->mBlockedby
= $this->user
->getName();
653 $this->user
->mBlock
= new Block( '127.0.8.1', 2, 1, 'no reason given', $now, 0, 10 );
654 $this->assertEquals( array( array( 'blockedtext',
655 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
656 'Useruser', null, '23:00, 31 December 1969', '127.0.8.1',
657 $wgLang->timeanddate( wfTimestamp( TS_MW
, $now ), true ) ) ),
658 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
660 # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
661 # $user->blockedFor() == ''
662 # $user->mBlock->mExpiry == 'infinity'