6 * @covers Title::getUserPermissionsErrors
7 * @covers Title::getUserPermissionsErrorsInternal
9 class TitlePermissionTest
extends MediaWikiLangTestCase
{
14 protected $userName, $altUserName;
24 protected $user, $anonUser, $userUser, $altUser;
26 protected function setUp() {
29 $langObj = Language
::factory( 'en' );
31 $localOffset = date( 'Z' ) / 60;
33 $this->setMwGlobals( array(
34 'wgMemc' => new EmptyBagOStuff
,
35 'wgContLang' => $langObj,
36 'wgLanguageCode' => 'en',
38 'wgLocaltimezone' => $localZone,
39 'wgLocalTZoffset' => $localOffset,
40 'wgNamespaceProtection' => array(
41 NS_MEDIAWIKI
=> 'editinterface',
44 // Without this testUserBlock will use a non-English context on non-English MediaWiki
45 // installations (because of how Title::checkUserBlock is implemented) and fail.
46 RequestContext
::resetMain();
48 $this->userName
= 'Useruser';
49 $this->altUserName
= 'Altuseruser';
50 date_default_timezone_set( $localZone );
52 $this->title
= Title
::makeTitle( NS_MAIN
, "Main Page" );
53 if ( !isset( $this->userUser
) ||
!( $this->userUser
instanceof User
) ) {
54 $this->userUser
= User
::newFromName( $this->userName
);
56 if ( !$this->userUser
->getID() ) {
57 $this->userUser
= User
::createNew( $this->userName
, array(
58 "email" => "test@example.com",
59 "real_name" => "Test User" ) );
60 $this->userUser
->load();
63 $this->altUser
= User
::newFromName( $this->altUserName
);
64 if ( !$this->altUser
->getID() ) {
65 $this->altUser
= User
::createNew( $this->altUserName
, array(
66 "email" => "alttest@example.com",
67 "real_name" => "Test User Alt" ) );
68 $this->altUser
->load();
71 $this->anonUser
= User
::newFromId( 0 );
73 $this->user
= $this->userUser
;
77 protected function setUserPerm( $perm ) {
78 // Setting member variables is evil!!!
80 if ( is_array( $perm ) ) {
81 $this->user
->mRights
= $perm;
83 $this->user
->mRights
= array( $perm );
87 protected function setTitle( $ns, $title = "Main_Page" ) {
88 $this->title
= Title
::makeTitle( $ns, $title );
91 protected function setUser( $userName = null ) {
92 if ( $userName === 'anon' ) {
93 $this->user
= $this->anonUser
;
94 } elseif ( $userName === null ||
$userName === $this->userName
) {
95 $this->user
= $this->userUser
;
97 $this->user
= $this->altUser
;
102 * @todo This test method should be split up into separate test methods and
105 public function testQuickPermissions() {
107 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT
);
109 $this->setUser( 'anon' );
110 $this->setTitle( NS_TALK
);
111 $this->setUserPerm( "createtalk" );
112 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
113 $this->assertEquals( array(), $res );
115 $this->setTitle( NS_TALK
);
116 $this->setUserPerm( "createpage" );
117 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
118 $this->assertEquals( array( array( "nocreatetext" ) ), $res );
120 $this->setTitle( NS_TALK
);
121 $this->setUserPerm( "" );
122 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
123 $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
125 $this->setTitle( NS_MAIN
);
126 $this->setUserPerm( "createpage" );
127 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
128 $this->assertEquals( array(), $res );
130 $this->setTitle( NS_MAIN
);
131 $this->setUserPerm( "createtalk" );
132 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
133 $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
135 $this->setUser( $this->userName
);
136 $this->setTitle( NS_TALK
);
137 $this->setUserPerm( "createtalk" );
138 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
139 $this->assertEquals( array(), $res );
141 $this->setTitle( NS_TALK
);
142 $this->setUserPerm( "createpage" );
143 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
144 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
146 $this->setTitle( NS_TALK
);
147 $this->setUserPerm( "" );
148 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
149 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
151 $this->setTitle( NS_MAIN
);
152 $this->setUserPerm( "createpage" );
153 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
154 $this->assertEquals( array(), $res );
156 $this->setTitle( NS_MAIN
);
157 $this->setUserPerm( "createtalk" );
158 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
159 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
161 $this->setTitle( NS_MAIN
);
162 $this->setUserPerm( "" );
163 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
164 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
166 $this->setUser( 'anon' );
167 $this->setTitle( NS_USER
, $this->userName
. '' );
168 $this->setUserPerm( "" );
169 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
170 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
172 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
173 $this->setUserPerm( "" );
174 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
175 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
177 $this->setTitle( NS_USER
, $this->userName
. '' );
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
. '/subpage' );
183 $this->setUserPerm( "move-rootuserpages" );
184 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
185 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
187 $this->setTitle( NS_USER
, $this->userName
. '' );
188 $this->setUserPerm( "" );
189 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
190 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
192 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
193 $this->setUserPerm( "" );
194 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
195 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
197 $this->setTitle( NS_USER
, $this->userName
. '' );
198 $this->setUserPerm( "move-rootuserpages" );
199 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
200 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
202 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
203 $this->setUserPerm( "move-rootuserpages" );
204 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
205 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
207 $this->setUser( $this->userName
);
208 $this->setTitle( NS_FILE
, "img.png" );
209 $this->setUserPerm( "" );
210 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
211 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ), $res );
213 $this->setTitle( NS_FILE
, "img.png" );
214 $this->setUserPerm( "movefile" );
215 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
216 $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
218 $this->setUser( 'anon' );
219 $this->setTitle( NS_FILE
, "img.png" );
220 $this->setUserPerm( "" );
221 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
222 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ), $res );
224 $this->setTitle( NS_FILE
, "img.png" );
225 $this->setUserPerm( "movefile" );
226 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
227 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
229 $this->setUser( $this->userName
);
230 $this->setUserPerm( "move" );
231 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
233 $this->setUserPerm( "" );
234 $this->runGroupPermissions(
236 array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) )
239 $this->setUser( 'anon' );
240 $this->setUserPerm( "move" );
241 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
243 $this->setUserPerm( "" );
244 $this->runGroupPermissions(
246 array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ),
247 array( array( 'movenotallowedfile' ), array( 'movenologintext' ) )
250 if ( $this->isWikitextNS( NS_MAIN
) ) {
251 //NOTE: some content models don't allow moving
252 // @todo find a Wikitext namespace for testing
254 $this->setTitle( NS_MAIN
);
255 $this->setUser( 'anon' );
256 $this->setUserPerm( "move" );
257 $this->runGroupPermissions( 'move', array() );
259 $this->setUserPerm( "" );
260 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ),
261 array( array( 'movenologintext' ) ) );
263 $this->setUser( $this->userName
);
264 $this->setUserPerm( "" );
265 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ) );
267 $this->setUserPerm( "move" );
268 $this->runGroupPermissions( 'move', array() );
270 $this->setUser( 'anon' );
271 $this->setUserPerm( 'move' );
272 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
273 $this->assertEquals( array(), $res );
275 $this->setUserPerm( '' );
276 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
277 $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
280 $this->setTitle( NS_USER
);
281 $this->setUser( $this->userName
);
282 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
283 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
284 $this->assertEquals( array(), $res );
286 $this->setUserPerm( "move" );
287 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
288 $this->assertEquals( array( array( 'cant-move-to-user-page' ) ), $res );
290 $this->setUser( 'anon' );
291 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
292 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
293 $this->assertEquals( array(), $res );
295 $this->setTitle( NS_USER
, "User/subpage" );
296 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
297 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
298 $this->assertEquals( array(), $res );
300 $this->setUserPerm( "move" );
301 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
302 $this->assertEquals( array(), $res );
304 $this->setUser( 'anon' );
307 array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ) ),
308 array( array( 'badaccess-group0' ) ),
315 "[[$prefix:Administrators|Administrators]]", 1 ),
316 array( 'protect-cantedit'
318 array( array( 'badaccess-group0' ), array( 'protect-cantedit' ) ),
319 array( array( 'protect-cantedit' ) ),
322 '' => array( array(), array(), array(), true )
325 foreach ( array( "edit", "protect", "" ) as $action ) {
326 $this->setUserPerm( null );
327 $this->assertEquals( $check[$action][0],
328 $this->title
->getUserPermissionsErrors( $action, $this->user
, true ) );
330 global $wgGroupPermissions;
331 $old = $wgGroupPermissions;
332 $wgGroupPermissions = array();
334 $this->assertEquals( $check[$action][1],
335 $this->title
->getUserPermissionsErrors( $action, $this->user
, true ) );
336 $wgGroupPermissions = $old;
338 $this->setUserPerm( $action );
339 $this->assertEquals( $check[$action][2],
340 $this->title
->getUserPermissionsErrors( $action, $this->user
, true ) );
342 $this->setUserPerm( $action );
343 $this->assertEquals( $check[$action][3],
344 $this->title
->userCan( $action, $this->user
, true ) );
345 $this->assertEquals( $check[$action][3],
346 $this->title
->quickUserCan( $action, $this->user
) );
347 # count( User::getGroupsWithPermissions( $action ) ) < 1
351 protected function runGroupPermissions( $action, $result, $result2 = null ) {
352 global $wgGroupPermissions;
354 if ( $result2 === null ) {
358 $wgGroupPermissions['autoconfirmed']['move'] = false;
359 $wgGroupPermissions['user']['move'] = false;
360 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
361 $this->assertEquals( $result, $res );
363 $wgGroupPermissions['autoconfirmed']['move'] = true;
364 $wgGroupPermissions['user']['move'] = false;
365 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
366 $this->assertEquals( $result2, $res );
368 $wgGroupPermissions['autoconfirmed']['move'] = true;
369 $wgGroupPermissions['user']['move'] = true;
370 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
371 $this->assertEquals( $result2, $res );
373 $wgGroupPermissions['autoconfirmed']['move'] = false;
374 $wgGroupPermissions['user']['move'] = true;
375 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
376 $this->assertEquals( $result2, $res );
380 * @todo This test method should be split up into separate test methods and
383 public function testSpecialsAndNSPermissions() {
384 global $wgNamespaceProtection;
385 $this->setUser( $this->userName
);
387 $this->setTitle( NS_SPECIAL
);
389 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'ns-specialprotected' ) ),
390 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
392 $this->setTitle( NS_MAIN
);
393 $this->setUserPerm( 'bogus' );
394 $this->assertEquals( array(),
395 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
397 $this->setTitle( NS_MAIN
);
398 $this->setUserPerm( '' );
399 $this->assertEquals( array( array( 'badaccess-group0' ) ),
400 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
402 $wgNamespaceProtection[NS_USER
] = array( 'bogus' );
404 $this->setTitle( NS_USER
);
405 $this->setUserPerm( '' );
406 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'namespaceprotected', 'User', 'bogus' ) ),
407 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
409 $this->setTitle( NS_MEDIAWIKI
);
410 $this->setUserPerm( 'bogus' );
411 $this->assertEquals( array( array( 'protectedinterface', 'bogus' ) ),
412 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
414 $this->setTitle( NS_MEDIAWIKI
);
415 $this->setUserPerm( 'bogus' );
416 $this->assertEquals( array( array( 'protectedinterface', 'bogus' ) ),
417 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
419 $wgNamespaceProtection = null;
421 $this->setUserPerm( 'bogus' );
422 $this->assertEquals( array(),
423 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
424 $this->assertEquals( true,
425 $this->title
->userCan( 'bogus', $this->user
) );
427 $this->setUserPerm( '' );
428 $this->assertEquals( array( array( 'badaccess-group0' ) ),
429 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
430 $this->assertEquals( false,
431 $this->title
->userCan( 'bogus', $this->user
) );
435 * @todo This test method should be split up into separate test methods and
438 public function testCssAndJavascriptPermissions() {
439 $this->setUser( $this->userName
);
441 $this->setTitle( NS_USER
, $this->userName
. '/test.js' );
442 $this->runCSSandJSPermissions(
443 array( array( 'badaccess-group0' ), array( 'mycustomjsprotected', 'bogus' ) ),
444 array( array( 'badaccess-group0' ), array( 'mycustomjsprotected', 'bogus' ) ),
445 array( array( 'badaccess-group0' ) ),
446 array( array( 'badaccess-group0' ), array( 'mycustomjsprotected', 'bogus' ) ),
447 array( array( 'badaccess-group0' ) )
450 $this->setTitle( NS_USER
, $this->userName
. '/test.css' );
451 $this->runCSSandJSPermissions(
452 array( array( 'badaccess-group0' ), array( 'mycustomcssprotected', 'bogus' ) ),
453 array( array( 'badaccess-group0' ) ),
454 array( array( 'badaccess-group0' ), array( 'mycustomcssprotected', 'bogus' ) ),
455 array( array( 'badaccess-group0' ) ),
456 array( array( 'badaccess-group0' ), array( 'mycustomcssprotected', 'bogus' ) )
459 $this->setTitle( NS_USER
, $this->altUserName
. '/test.js' );
460 $this->runCSSandJSPermissions(
461 array( array( 'badaccess-group0' ), array( 'customjsprotected', 'bogus' ) ),
462 array( array( 'badaccess-group0' ), array( 'customjsprotected', 'bogus' ) ),
463 array( array( 'badaccess-group0' ), array( 'customjsprotected', 'bogus' ) ),
464 array( array( 'badaccess-group0' ), array( 'customjsprotected', 'bogus' ) ),
465 array( array( 'badaccess-group0' ) )
468 $this->setTitle( NS_USER
, $this->altUserName
. '/test.css' );
469 $this->runCSSandJSPermissions(
470 array( array( 'badaccess-group0' ), array( 'customcssprotected', 'bogus' ) ),
471 array( array( 'badaccess-group0' ), array( 'customcssprotected', 'bogus' ) ),
472 array( array( 'badaccess-group0' ), array( 'customcssprotected', 'bogus' ) ),
473 array( array( 'badaccess-group0' ) ),
474 array( array( 'badaccess-group0' ), array( 'customcssprotected', 'bogus' ) )
477 $this->setTitle( NS_USER
, $this->altUserName
. '/tempo' );
478 $this->runCSSandJSPermissions(
479 array( array( 'badaccess-group0' ) ),
480 array( array( 'badaccess-group0' ) ),
481 array( array( 'badaccess-group0' ) ),
482 array( array( 'badaccess-group0' ) ),
483 array( array( 'badaccess-group0' ) )
487 protected function runCSSandJSPermissions( $result0, $result1, $result2, $result3, $result4 ) {
488 $this->setUserPerm( '' );
489 $this->assertEquals( $result0,
490 $this->title
->getUserPermissionsErrors( 'bogus',
493 $this->setUserPerm( 'editmyusercss' );
494 $this->assertEquals( $result1,
495 $this->title
->getUserPermissionsErrors( 'bogus',
498 $this->setUserPerm( 'editmyuserjs' );
499 $this->assertEquals( $result2,
500 $this->title
->getUserPermissionsErrors( 'bogus',
503 $this->setUserPerm( 'editusercss' );
504 $this->assertEquals( $result3,
505 $this->title
->getUserPermissionsErrors( 'bogus',
508 $this->setUserPerm( 'edituserjs' );
509 $this->assertEquals( $result4,
510 $this->title
->getUserPermissionsErrors( 'bogus',
513 $this->setUserPerm( 'editusercssjs' );
514 $this->assertEquals( array( array( 'badaccess-group0' ) ),
515 $this->title
->getUserPermissionsErrors( 'bogus',
518 $this->setUserPerm( array( 'edituserjs', 'editusercss' ) );
519 $this->assertEquals( array( array( 'badaccess-group0' ) ),
520 $this->title
->getUserPermissionsErrors( 'bogus',
525 * @todo This test method should be split up into separate test methods and
528 public function testPageRestrictions() {
531 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT
);
533 $this->setTitle( NS_MAIN
);
534 $this->title
->mRestrictionsLoaded
= true;
535 $this->setUserPerm( "edit" );
536 $this->title
->mRestrictions
= array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
538 $this->assertEquals( array(),
539 $this->title
->getUserPermissionsErrors( 'edit',
542 $this->assertEquals( true,
543 $this->title
->quickUserCan( 'edit', $this->user
) );
544 $this->title
->mRestrictions
= array( "edit" => array( 'bogus', "sysop", "protect", "" ),
545 "bogus" => array( 'bogus', "sysop", "protect", "" ) );
547 $this->assertEquals( array( array( 'badaccess-group0' ),
548 array( 'protectedpagetext', 'bogus', 'bogus' ),
549 array( 'protectedpagetext', 'editprotected', 'bogus' ),
550 array( 'protectedpagetext', 'protect', 'bogus' ) ),
551 $this->title
->getUserPermissionsErrors( 'bogus',
553 $this->assertEquals( array( array( 'protectedpagetext', 'bogus', 'edit' ),
554 array( 'protectedpagetext', 'editprotected', 'edit' ),
555 array( 'protectedpagetext', 'protect', 'edit' ) ),
556 $this->title
->getUserPermissionsErrors( 'edit',
558 $this->setUserPerm( "" );
559 $this->assertEquals( array( array( 'badaccess-group0' ),
560 array( 'protectedpagetext', 'bogus', 'bogus' ),
561 array( 'protectedpagetext', 'editprotected', 'bogus' ),
562 array( 'protectedpagetext', 'protect', 'bogus' ) ),
563 $this->title
->getUserPermissionsErrors( 'bogus',
565 $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ),
566 array( 'protectedpagetext', 'bogus', 'edit' ),
567 array( 'protectedpagetext', 'editprotected', 'edit' ),
568 array( 'protectedpagetext', 'protect', 'edit' ) ),
569 $this->title
->getUserPermissionsErrors( 'edit',
571 $this->setUserPerm( array( "edit", "editprotected" ) );
572 $this->assertEquals( array( array( 'badaccess-group0' ),
573 array( 'protectedpagetext', 'bogus', 'bogus' ),
574 array( 'protectedpagetext', 'protect', 'bogus' ) ),
575 $this->title
->getUserPermissionsErrors( 'bogus',
577 $this->assertEquals( array(
578 array( 'protectedpagetext', 'bogus', 'edit' ),
579 array( 'protectedpagetext', 'protect', 'edit' ) ),
580 $this->title
->getUserPermissionsErrors( 'edit',
583 $this->title
->mCascadeRestriction
= true;
584 $this->setUserPerm( "edit" );
585 $this->assertEquals( false,
586 $this->title
->quickUserCan( 'bogus', $this->user
) );
587 $this->assertEquals( false,
588 $this->title
->quickUserCan( 'edit', $this->user
) );
589 $this->assertEquals( array( array( 'badaccess-group0' ),
590 array( 'protectedpagetext', 'bogus', 'bogus' ),
591 array( 'protectedpagetext', 'editprotected', 'bogus' ),
592 array( 'protectedpagetext', 'protect', 'bogus' ) ),
593 $this->title
->getUserPermissionsErrors( 'bogus',
595 $this->assertEquals( array( array( 'protectedpagetext', 'bogus', 'edit' ),
596 array( 'protectedpagetext', 'editprotected', 'edit' ),
597 array( 'protectedpagetext', 'protect', 'edit' ) ),
598 $this->title
->getUserPermissionsErrors( 'edit',
601 $this->setUserPerm( array( "edit", "editprotected" ) );
602 $this->assertEquals( false,
603 $this->title
->quickUserCan( 'bogus', $this->user
) );
604 $this->assertEquals( false,
605 $this->title
->quickUserCan( 'edit', $this->user
) );
606 $this->assertEquals( array( array( 'badaccess-group0' ),
607 array( 'protectedpagetext', 'bogus', 'bogus' ),
608 array( 'protectedpagetext', 'protect', 'bogus' ),
609 array( 'protectedpagetext', 'protect', 'bogus' ) ),
610 $this->title
->getUserPermissionsErrors( 'bogus',
612 $this->assertEquals( array( array( 'protectedpagetext', 'bogus', 'edit' ),
613 array( 'protectedpagetext', 'protect', 'edit' ),
614 array( 'protectedpagetext', 'protect', 'edit' ) ),
615 $this->title
->getUserPermissionsErrors( 'edit',
619 public function testCascadingSourcesRestrictions() {
620 $this->setTitle( NS_MAIN
, "test page" );
621 $this->setUserPerm( array( "edit", "bogus" ) );
623 $this->title
->mCascadeSources
= array(
624 Title
::makeTitle( NS_MAIN
, "Bogus" ),
625 Title
::makeTitle( NS_MAIN
, "UnBogus" )
627 $this->title
->mCascadingRestrictions
= array(
628 "bogus" => array( 'bogus', "sysop", "protect", "" )
631 $this->assertEquals( false,
632 $this->title
->userCan( 'bogus', $this->user
) );
633 $this->assertEquals( array( array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n", 'bogus' ),
634 array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n", 'bogus' ),
635 array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n", 'bogus' ) ),
636 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
638 $this->assertEquals( true,
639 $this->title
->userCan( 'edit', $this->user
) );
640 $this->assertEquals( array(),
641 $this->title
->getUserPermissionsErrors( 'edit', $this->user
) );
645 * @todo This test method should be split up into separate test methods and
648 public function testActionPermissions() {
649 $this->setUserPerm( array( "createpage" ) );
650 $this->setTitle( NS_MAIN
, "test page" );
651 $this->title
->mTitleProtection
['pt_create_perm'] = '';
652 $this->title
->mTitleProtection
['pt_user'] = $this->user
->getID();
653 $this->title
->mTitleProtection
['pt_expiry'] = wfGetDB( DB_SLAVE
)->getInfinity();
654 $this->title
->mTitleProtection
['pt_reason'] = 'test';
655 $this->title
->mCascadeRestriction
= false;
657 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
658 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
659 $this->assertEquals( false,
660 $this->title
->userCan( 'create', $this->user
) );
662 $this->title
->mTitleProtection
['pt_create_perm'] = 'sysop';
663 $this->setUserPerm( array( 'createpage', 'protect' ) );
664 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
665 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
666 $this->assertEquals( false,
667 $this->title
->userCan( 'create', $this->user
) );
669 $this->setUserPerm( array( 'createpage', 'editprotected' ) );
670 $this->assertEquals( array(),
671 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
672 $this->assertEquals( true,
673 $this->title
->userCan( 'create', $this->user
) );
675 $this->setUserPerm( array( 'createpage' ) );
676 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
677 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
678 $this->assertEquals( false,
679 $this->title
->userCan( 'create', $this->user
) );
681 $this->setTitle( NS_MEDIA
, "test page" );
682 $this->setUserPerm( array( "move" ) );
683 $this->assertEquals( false,
684 $this->title
->userCan( 'move', $this->user
) );
685 $this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ),
686 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
688 $this->setTitle( NS_HELP
, "test page" );
689 $this->assertEquals( array(),
690 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
691 $this->assertEquals( true,
692 $this->title
->userCan( 'move', $this->user
) );
694 $this->title
->mInterwiki
= "no";
695 $this->assertEquals( array( array( 'immobile-source-page' ) ),
696 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
697 $this->assertEquals( false,
698 $this->title
->userCan( 'move', $this->user
) );
700 $this->setTitle( NS_MEDIA
, "test page" );
701 $this->assertEquals( false,
702 $this->title
->userCan( 'move-target', $this->user
) );
703 $this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ),
704 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
706 $this->setTitle( NS_HELP
, "test page" );
707 $this->assertEquals( array(),
708 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
709 $this->assertEquals( true,
710 $this->title
->userCan( 'move-target', $this->user
) );
712 $this->title
->mInterwiki
= "no";
713 $this->assertEquals( array( array( 'immobile-target-page' ) ),
714 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
715 $this->assertEquals( false,
716 $this->title
->userCan( 'move-target', $this->user
) );
719 public function testUserBlock() {
720 global $wgEmailConfirmToEdit, $wgEmailAuthentication;
721 $wgEmailConfirmToEdit = true;
722 $wgEmailAuthentication = true;
724 $this->setUserPerm( array( "createpage", "move" ) );
725 $this->setTitle( NS_HELP
, "test page" );
728 $this->assertEquals( array( array( 'confirmedittext' ) ),
729 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
730 $wgEmailConfirmToEdit = false;
731 $this->assertEquals( true, $this->title
->userCan( 'move-target', $this->user
) );
733 # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
734 $this->assertEquals( array(),
735 $this->title
->getUserPermissionsErrors( 'move-target',
741 $this->user
->mBlockedby
= $this->user
->getId();
742 $this->user
->mBlock
= new Block( '127.0.8.1', 0, $this->user
->getId(),
743 'no reason given', $prev +
3600, 1, 0 );
744 $this->user
->mBlock
->mTimestamp
= 0;
745 $this->assertEquals( array( array( 'autoblockedtext',
746 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
747 'Useruser', null, 'infinite', '127.0.8.1',
748 $wgLang->timeanddate( wfTimestamp( TS_MW
, $prev ), true ) ) ),
749 $this->title
->getUserPermissionsErrors( 'move-target',
752 $this->assertEquals( false, $this->title
->userCan( 'move-target', $this->user
) );
753 // quickUserCan should ignore user blocks
754 $this->assertEquals( true, $this->title
->quickUserCan( 'move-target', $this->user
) );
756 global $wgLocalTZoffset;
757 $wgLocalTZoffset = -60;
758 $this->user
->mBlockedby
= $this->user
->getName();
759 $this->user
->mBlock
= new Block( '127.0.8.1', 0, $this->user
->getId(),
760 'no reason given', $now, 0, 10 );
761 $this->assertEquals( array( array( 'blockedtext',
762 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
763 'Useruser', null, '23:00, 31 December 1969', '127.0.8.1',
764 $wgLang->timeanddate( wfTimestamp( TS_MW
, $now ), true ) ) ),
765 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
766 # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
767 # $user->blockedFor() == ''
768 # $user->mBlock->mExpiry == 'infinity'