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 ) );
329 $this->assertEquals( $check[$action][0],
330 $this->title
->getUserPermissionsErrors( $action, $this->user
, 'full' ) );
331 $this->assertEquals( $check[$action][0],
332 $this->title
->getUserPermissionsErrors( $action, $this->user
, 'secure' ) );
334 global $wgGroupPermissions;
335 $old = $wgGroupPermissions;
336 $wgGroupPermissions = array();
338 $this->assertEquals( $check[$action][1],
339 $this->title
->getUserPermissionsErrors( $action, $this->user
, true ) );
340 $this->assertEquals( $check[$action][1],
341 $this->title
->getUserPermissionsErrors( $action, $this->user
, 'full' ) );
342 $this->assertEquals( $check[$action][1],
343 $this->title
->getUserPermissionsErrors( $action, $this->user
, 'secure' ) );
344 $wgGroupPermissions = $old;
346 $this->setUserPerm( $action );
347 $this->assertEquals( $check[$action][2],
348 $this->title
->getUserPermissionsErrors( $action, $this->user
, true ) );
349 $this->assertEquals( $check[$action][2],
350 $this->title
->getUserPermissionsErrors( $action, $this->user
, 'full' ) );
351 $this->assertEquals( $check[$action][2],
352 $this->title
->getUserPermissionsErrors( $action, $this->user
, 'secure' ) );
354 $this->setUserPerm( $action );
355 $this->assertEquals( $check[$action][3],
356 $this->title
->userCan( $action, $this->user
, true ) );
357 $this->assertEquals( $check[$action][3],
358 $this->title
->quickUserCan( $action, $this->user
) );
359 # count( User::getGroupsWithPermissions( $action ) ) < 1
363 protected function runGroupPermissions( $action, $result, $result2 = null ) {
364 global $wgGroupPermissions;
366 if ( $result2 === null ) {
370 $wgGroupPermissions['autoconfirmed']['move'] = false;
371 $wgGroupPermissions['user']['move'] = false;
372 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
373 $this->assertEquals( $result, $res );
375 $wgGroupPermissions['autoconfirmed']['move'] = true;
376 $wgGroupPermissions['user']['move'] = false;
377 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
378 $this->assertEquals( $result2, $res );
380 $wgGroupPermissions['autoconfirmed']['move'] = true;
381 $wgGroupPermissions['user']['move'] = true;
382 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
383 $this->assertEquals( $result2, $res );
385 $wgGroupPermissions['autoconfirmed']['move'] = false;
386 $wgGroupPermissions['user']['move'] = true;
387 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
388 $this->assertEquals( $result2, $res );
392 * @todo This test method should be split up into separate test methods and
395 public function testSpecialsAndNSPermissions() {
396 global $wgNamespaceProtection;
397 $this->setUser( $this->userName
);
399 $this->setTitle( NS_SPECIAL
);
401 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'ns-specialprotected' ) ),
402 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
404 $this->setTitle( NS_MAIN
);
405 $this->setUserPerm( 'bogus' );
406 $this->assertEquals( array(),
407 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
409 $this->setTitle( NS_MAIN
);
410 $this->setUserPerm( '' );
411 $this->assertEquals( array( array( 'badaccess-group0' ) ),
412 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
414 $wgNamespaceProtection[NS_USER
] = array( 'bogus' );
416 $this->setTitle( NS_USER
);
417 $this->setUserPerm( '' );
418 $this->assertEquals( array( array( 'badaccess-group0' ),
419 array( 'namespaceprotected', 'User', 'bogus' ) ),
420 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
422 $this->setTitle( NS_MEDIAWIKI
);
423 $this->setUserPerm( 'bogus' );
424 $this->assertEquals( array( array( 'protectedinterface', 'bogus' ) ),
425 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
427 $this->setTitle( NS_MEDIAWIKI
);
428 $this->setUserPerm( 'bogus' );
429 $this->assertEquals( array( array( 'protectedinterface', 'bogus' ) ),
430 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
432 $wgNamespaceProtection = null;
434 $this->setUserPerm( 'bogus' );
435 $this->assertEquals( array(),
436 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
437 $this->assertEquals( true,
438 $this->title
->userCan( 'bogus', $this->user
) );
440 $this->setUserPerm( '' );
441 $this->assertEquals( array( array( 'badaccess-group0' ) ),
442 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
443 $this->assertEquals( false,
444 $this->title
->userCan( 'bogus', $this->user
) );
448 * @todo This test method should be split up into separate test methods and
451 public function testCssAndJavascriptPermissions() {
452 $this->setUser( $this->userName
);
454 $this->setTitle( NS_USER
, $this->userName
. '/test.js' );
455 $this->runCSSandJSPermissions(
456 array( array( 'badaccess-group0' ), array( 'mycustomjsprotected', 'bogus' ) ),
457 array( array( 'badaccess-group0' ), array( 'mycustomjsprotected', 'bogus' ) ),
458 array( array( 'badaccess-group0' ) ),
459 array( array( 'badaccess-group0' ), array( 'mycustomjsprotected', 'bogus' ) ),
460 array( array( 'badaccess-group0' ) )
463 $this->setTitle( NS_USER
, $this->userName
. '/test.css' );
464 $this->runCSSandJSPermissions(
465 array( array( 'badaccess-group0' ), array( 'mycustomcssprotected', 'bogus' ) ),
466 array( array( 'badaccess-group0' ) ),
467 array( array( 'badaccess-group0' ), array( 'mycustomcssprotected', 'bogus' ) ),
468 array( array( 'badaccess-group0' ) ),
469 array( array( 'badaccess-group0' ), array( 'mycustomcssprotected', 'bogus' ) )
472 $this->setTitle( NS_USER
, $this->altUserName
. '/test.js' );
473 $this->runCSSandJSPermissions(
474 array( array( 'badaccess-group0' ), array( 'customjsprotected', 'bogus' ) ),
475 array( array( 'badaccess-group0' ), array( 'customjsprotected', 'bogus' ) ),
476 array( array( 'badaccess-group0' ), array( 'customjsprotected', 'bogus' ) ),
477 array( array( 'badaccess-group0' ), array( 'customjsprotected', 'bogus' ) ),
478 array( array( 'badaccess-group0' ) )
481 $this->setTitle( NS_USER
, $this->altUserName
. '/test.css' );
482 $this->runCSSandJSPermissions(
483 array( array( 'badaccess-group0' ), array( 'customcssprotected', 'bogus' ) ),
484 array( array( 'badaccess-group0' ), array( 'customcssprotected', 'bogus' ) ),
485 array( array( 'badaccess-group0' ), array( 'customcssprotected', 'bogus' ) ),
486 array( array( 'badaccess-group0' ) ),
487 array( array( 'badaccess-group0' ), array( 'customcssprotected', 'bogus' ) )
490 $this->setTitle( NS_USER
, $this->altUserName
. '/tempo' );
491 $this->runCSSandJSPermissions(
492 array( array( 'badaccess-group0' ) ),
493 array( array( 'badaccess-group0' ) ),
494 array( array( 'badaccess-group0' ) ),
495 array( array( 'badaccess-group0' ) ),
496 array( array( 'badaccess-group0' ) )
500 protected function runCSSandJSPermissions( $result0, $result1, $result2, $result3, $result4 ) {
501 $this->setUserPerm( '' );
502 $this->assertEquals( $result0,
503 $this->title
->getUserPermissionsErrors( 'bogus',
506 $this->setUserPerm( 'editmyusercss' );
507 $this->assertEquals( $result1,
508 $this->title
->getUserPermissionsErrors( 'bogus',
511 $this->setUserPerm( 'editmyuserjs' );
512 $this->assertEquals( $result2,
513 $this->title
->getUserPermissionsErrors( 'bogus',
516 $this->setUserPerm( 'editusercss' );
517 $this->assertEquals( $result3,
518 $this->title
->getUserPermissionsErrors( 'bogus',
521 $this->setUserPerm( 'edituserjs' );
522 $this->assertEquals( $result4,
523 $this->title
->getUserPermissionsErrors( 'bogus',
526 $this->setUserPerm( 'editusercssjs' );
527 $this->assertEquals( array( array( 'badaccess-group0' ) ),
528 $this->title
->getUserPermissionsErrors( 'bogus',
531 $this->setUserPerm( array( 'edituserjs', 'editusercss' ) );
532 $this->assertEquals( array( array( 'badaccess-group0' ) ),
533 $this->title
->getUserPermissionsErrors( 'bogus',
538 * @todo This test method should be split up into separate test methods and
541 public function testPageRestrictions() {
544 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT
);
546 $this->setTitle( NS_MAIN
);
547 $this->title
->mRestrictionsLoaded
= true;
548 $this->setUserPerm( "edit" );
549 $this->title
->mRestrictions
= array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
551 $this->assertEquals( array(),
552 $this->title
->getUserPermissionsErrors( 'edit',
555 $this->assertEquals( true,
556 $this->title
->quickUserCan( 'edit', $this->user
) );
557 $this->title
->mRestrictions
= array( "edit" => array( 'bogus', "sysop", "protect", "" ),
558 "bogus" => array( 'bogus', "sysop", "protect", "" ) );
560 $this->assertEquals( array( array( 'badaccess-group0' ),
561 array( 'protectedpagetext', 'bogus', 'bogus' ),
562 array( 'protectedpagetext', 'editprotected', 'bogus' ),
563 array( 'protectedpagetext', 'protect', 'bogus' ) ),
564 $this->title
->getUserPermissionsErrors( 'bogus',
566 $this->assertEquals( array( array( 'protectedpagetext', 'bogus', 'edit' ),
567 array( 'protectedpagetext', 'editprotected', 'edit' ),
568 array( 'protectedpagetext', 'protect', 'edit' ) ),
569 $this->title
->getUserPermissionsErrors( 'edit',
571 $this->setUserPerm( "" );
572 $this->assertEquals( array( array( 'badaccess-group0' ),
573 array( 'protectedpagetext', 'bogus', 'bogus' ),
574 array( 'protectedpagetext', 'editprotected', 'bogus' ),
575 array( 'protectedpagetext', 'protect', 'bogus' ) ),
576 $this->title
->getUserPermissionsErrors( 'bogus',
578 $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ),
579 array( 'protectedpagetext', 'bogus', 'edit' ),
580 array( 'protectedpagetext', 'editprotected', 'edit' ),
581 array( 'protectedpagetext', 'protect', 'edit' ) ),
582 $this->title
->getUserPermissionsErrors( 'edit',
584 $this->setUserPerm( array( "edit", "editprotected" ) );
585 $this->assertEquals( array( array( 'badaccess-group0' ),
586 array( 'protectedpagetext', 'bogus', 'bogus' ),
587 array( 'protectedpagetext', 'protect', 'bogus' ) ),
588 $this->title
->getUserPermissionsErrors( 'bogus',
590 $this->assertEquals( array(
591 array( 'protectedpagetext', 'bogus', 'edit' ),
592 array( 'protectedpagetext', 'protect', 'edit' ) ),
593 $this->title
->getUserPermissionsErrors( 'edit',
596 $this->title
->mCascadeRestriction
= true;
597 $this->setUserPerm( "edit" );
598 $this->assertEquals( false,
599 $this->title
->quickUserCan( 'bogus', $this->user
) );
600 $this->assertEquals( false,
601 $this->title
->quickUserCan( 'edit', $this->user
) );
602 $this->assertEquals( array( array( 'badaccess-group0' ),
603 array( 'protectedpagetext', 'bogus', 'bogus' ),
604 array( 'protectedpagetext', 'editprotected', 'bogus' ),
605 array( 'protectedpagetext', 'protect', 'bogus' ) ),
606 $this->title
->getUserPermissionsErrors( 'bogus',
608 $this->assertEquals( array( array( 'protectedpagetext', 'bogus', 'edit' ),
609 array( 'protectedpagetext', 'editprotected', 'edit' ),
610 array( 'protectedpagetext', 'protect', 'edit' ) ),
611 $this->title
->getUserPermissionsErrors( 'edit',
614 $this->setUserPerm( array( "edit", "editprotected" ) );
615 $this->assertEquals( false,
616 $this->title
->quickUserCan( 'bogus', $this->user
) );
617 $this->assertEquals( false,
618 $this->title
->quickUserCan( 'edit', $this->user
) );
619 $this->assertEquals( array( array( 'badaccess-group0' ),
620 array( 'protectedpagetext', 'bogus', 'bogus' ),
621 array( 'protectedpagetext', 'protect', 'bogus' ),
622 array( 'protectedpagetext', 'protect', 'bogus' ) ),
623 $this->title
->getUserPermissionsErrors( 'bogus',
625 $this->assertEquals( array( array( 'protectedpagetext', 'bogus', 'edit' ),
626 array( 'protectedpagetext', 'protect', 'edit' ),
627 array( 'protectedpagetext', 'protect', 'edit' ) ),
628 $this->title
->getUserPermissionsErrors( 'edit',
632 public function testCascadingSourcesRestrictions() {
633 $this->setTitle( NS_MAIN
, "test page" );
634 $this->setUserPerm( array( "edit", "bogus" ) );
636 $this->title
->mCascadeSources
= array(
637 Title
::makeTitle( NS_MAIN
, "Bogus" ),
638 Title
::makeTitle( NS_MAIN
, "UnBogus" )
640 $this->title
->mCascadingRestrictions
= array(
641 "bogus" => array( 'bogus', "sysop", "protect", "" )
644 $this->assertEquals( false,
645 $this->title
->userCan( 'bogus', $this->user
) );
646 $this->assertEquals( array(
647 array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n", 'bogus' ),
648 array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n", 'bogus' ),
649 array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n", 'bogus' ) ),
650 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
652 $this->assertEquals( true,
653 $this->title
->userCan( 'edit', $this->user
) );
654 $this->assertEquals( array(),
655 $this->title
->getUserPermissionsErrors( 'edit', $this->user
) );
659 * @todo This test method should be split up into separate test methods and
662 public function testActionPermissions() {
663 $this->setUserPerm( array( "createpage" ) );
664 $this->setTitle( NS_MAIN
, "test page" );
665 $this->title
->mTitleProtection
['permission'] = '';
666 $this->title
->mTitleProtection
['user'] = $this->user
->getID();
667 $this->title
->mTitleProtection
['expiry'] = wfGetDB( DB_SLAVE
)->getInfinity();
668 $this->title
->mTitleProtection
['reason'] = 'test';
669 $this->title
->mCascadeRestriction
= false;
671 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
672 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
673 $this->assertEquals( false,
674 $this->title
->userCan( 'create', $this->user
) );
676 $this->title
->mTitleProtection
['permission'] = 'editprotected';
677 $this->setUserPerm( array( 'createpage', 'protect' ) );
678 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
679 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
680 $this->assertEquals( false,
681 $this->title
->userCan( 'create', $this->user
) );
683 $this->setUserPerm( array( 'createpage', 'editprotected' ) );
684 $this->assertEquals( array(),
685 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
686 $this->assertEquals( true,
687 $this->title
->userCan( 'create', $this->user
) );
689 $this->setUserPerm( array( 'createpage' ) );
690 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
691 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
692 $this->assertEquals( false,
693 $this->title
->userCan( 'create', $this->user
) );
695 $this->setTitle( NS_MEDIA
, "test page" );
696 $this->setUserPerm( array( "move" ) );
697 $this->assertEquals( false,
698 $this->title
->userCan( 'move', $this->user
) );
699 $this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ),
700 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
702 $this->setTitle( NS_HELP
, "test page" );
703 $this->assertEquals( array(),
704 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
705 $this->assertEquals( true,
706 $this->title
->userCan( 'move', $this->user
) );
708 $this->title
->mInterwiki
= "no";
709 $this->assertEquals( array( array( 'immobile-source-page' ) ),
710 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
711 $this->assertEquals( false,
712 $this->title
->userCan( 'move', $this->user
) );
714 $this->setTitle( NS_MEDIA
, "test page" );
715 $this->assertEquals( false,
716 $this->title
->userCan( 'move-target', $this->user
) );
717 $this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ),
718 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
720 $this->setTitle( NS_HELP
, "test page" );
721 $this->assertEquals( array(),
722 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
723 $this->assertEquals( true,
724 $this->title
->userCan( 'move-target', $this->user
) );
726 $this->title
->mInterwiki
= "no";
727 $this->assertEquals( array( array( 'immobile-target-page' ) ),
728 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
729 $this->assertEquals( false,
730 $this->title
->userCan( 'move-target', $this->user
) );
733 public function testUserBlock() {
734 global $wgEmailConfirmToEdit, $wgEmailAuthentication;
735 $wgEmailConfirmToEdit = true;
736 $wgEmailAuthentication = true;
738 $this->setUserPerm( array( "createpage", "move" ) );
739 $this->setTitle( NS_HELP
, "test page" );
742 $this->assertEquals( array( array( 'confirmedittext' ) ),
743 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
744 $wgEmailConfirmToEdit = false;
745 $this->assertEquals( true, $this->title
->userCan( 'move-target', $this->user
) );
747 # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
748 $this->assertEquals( array(),
749 $this->title
->getUserPermissionsErrors( 'move-target',
755 $this->user
->mBlockedby
= $this->user
->getId();
756 $this->user
->mBlock
= new Block( '127.0.8.1', 0, $this->user
->getId(),
757 'no reason given', $prev +
3600, 1, 0 );
758 $this->user
->mBlock
->mTimestamp
= 0;
759 $this->assertEquals( array( array( 'autoblockedtext',
760 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
761 'Useruser', null, 'infinite', '127.0.8.1',
762 $wgLang->timeanddate( wfTimestamp( TS_MW
, $prev ), true ) ) ),
763 $this->title
->getUserPermissionsErrors( 'move-target',
766 $this->assertEquals( false, $this->title
->userCan( 'move-target', $this->user
) );
767 // quickUserCan should ignore user blocks
768 $this->assertEquals( true, $this->title
->quickUserCan( 'move-target', $this->user
) );
770 global $wgLocalTZoffset;
771 $wgLocalTZoffset = -60;
772 $this->user
->mBlockedby
= $this->user
->getName();
773 $this->user
->mBlock
= new Block( '127.0.8.1', 0, $this->user
->getId(),
774 'no reason given', $now, 0, 10 );
775 $this->assertEquals( array( array( 'blockedtext',
776 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
777 'Useruser', null, '23:00, 31 December 1969', '127.0.8.1',
778 $wgLang->timeanddate( wfTimestamp( TS_MW
, $now ), true ) ) ),
779 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
780 # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
781 # $user->blockedFor() == ''
782 # $user->mBlock->mExpiry == 'infinity'