7 class TitlePermissionTest
extends MediaWikiLangTestCase
{
12 protected $userName, $altUserName;
22 protected $user, $anonUser, $userUser, $altUser;
24 protected function setUp() {
27 $langObj = Language
::factory( 'en' );
29 $localOffset = date( 'Z' ) / 60;
31 $this->setMwGlobals( array(
32 'wgMemc' => new EmptyBagOStuff
,
33 'wgContLang' => $langObj,
34 'wgLanguageCode' => 'en',
36 'wgLocaltimezone' => $localZone,
37 'wgLocalTZoffset' => $localOffset,
38 'wgNamespaceProtection' => array(
39 NS_MEDIAWIKI
=> 'editinterface',
43 $this->userName
= 'Useruser';
44 $this->altUserName
= 'Altuseruser';
45 date_default_timezone_set( $localZone );
47 $this->title
= Title
::makeTitle( NS_MAIN
, "Main Page" );
48 if ( !isset( $this->userUser
) ||
!( $this->userUser
instanceOf User
) ) {
49 $this->userUser
= User
::newFromName( $this->userName
);
51 if ( !$this->userUser
->getID() ) {
52 $this->userUser
= User
::createNew( $this->userName
, array(
53 "email" => "test@example.com",
54 "real_name" => "Test User" ) );
55 $this->userUser
->load();
58 $this->altUser
= User
::newFromName( $this->altUserName
);
59 if ( !$this->altUser
->getID() ) {
60 $this->altUser
= User
::createNew( $this->altUserName
, array(
61 "email" => "alttest@example.com",
62 "real_name" => "Test User Alt" ) );
63 $this->altUser
->load();
66 $this->anonUser
= User
::newFromId( 0 );
68 $this->user
= $this->userUser
;
72 protected 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 protected function setTitle( $ns, $title = "Main_Page" ) {
83 $this->title
= Title
::makeTitle( $ns, $title );
86 protected function setUser( $userName = null ) {
87 if ( $userName === 'anon' ) {
88 $this->user
= $this->anonUser
;
89 } elseif ( $userName === null ||
$userName === $this->userName
) {
90 $this->user
= $this->userUser
;
92 $this->user
= $this->altUser
;
97 * @todo This test method should be split up into separate test methods and
100 public 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 if ( $this->isWikitextNS( NS_MAIN
) ) {
240 //NOTE: some content models don't allow moving
241 // @todo find a Wikitext namespace for testing
243 $this->setTitle( NS_MAIN
);
244 $this->setUser( 'anon' );
245 $this->setUserPerm( "move" );
246 $this->runGroupPermissions( 'move', array() );
248 $this->setUserPerm( "" );
249 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ),
250 array( array( 'movenologintext' ) ) );
252 $this->setUser( $this->userName
);
253 $this->setUserPerm( "" );
254 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ) );
256 $this->setUserPerm( "move" );
257 $this->runGroupPermissions( 'move', array() );
259 $this->setUser( 'anon' );
260 $this->setUserPerm( 'move' );
261 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
262 $this->assertEquals( array(), $res );
264 $this->setUserPerm( '' );
265 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
266 $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
269 $this->setTitle( NS_USER
);
270 $this->setUser( $this->userName
);
271 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
272 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
273 $this->assertEquals( array(), $res );
275 $this->setUserPerm( "move" );
276 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
277 $this->assertEquals( array( array( 'cant-move-to-user-page' ) ), $res );
279 $this->setUser( 'anon' );
280 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
281 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
282 $this->assertEquals( array(), $res );
284 $this->setTitle( NS_USER
, "User/subpage" );
285 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
286 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
287 $this->assertEquals( array(), $res );
289 $this->setUserPerm( "move" );
290 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
291 $this->assertEquals( array(), $res );
293 $this->setUser( 'anon' );
294 $check = array( 'edit' => array( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ) ),
295 array( array( 'badaccess-group0' ) ),
297 'protect' => array( array( array( 'badaccess-groups', "[[$prefix:Administrators|Administrators]]", 1 ), array( 'protect-cantedit' ) ),
298 array( array( 'badaccess-group0' ), array( 'protect-cantedit' ) ),
299 array( array( 'protect-cantedit' ) ), false ),
300 '' => array( array(), array(), array(), true ) );
302 foreach ( array( "edit", "protect", "" ) as $action ) {
303 $this->setUserPerm( null );
304 $this->assertEquals( $check[$action][0],
305 $this->title
->getUserPermissionsErrors( $action, $this->user
, true ) );
307 global $wgGroupPermissions;
308 $old = $wgGroupPermissions;
309 $wgGroupPermissions = array();
311 $this->assertEquals( $check[$action][1],
312 $this->title
->getUserPermissionsErrors( $action, $this->user
, true ) );
313 $wgGroupPermissions = $old;
315 $this->setUserPerm( $action );
316 $this->assertEquals( $check[$action][2],
317 $this->title
->getUserPermissionsErrors( $action, $this->user
, true ) );
319 $this->setUserPerm( $action );
320 $this->assertEquals( $check[$action][3],
321 $this->title
->userCan( $action, $this->user
, true ) );
322 $this->assertEquals( $check[$action][3],
323 $this->title
->quickUserCan( $action, $this->user
) );
324 # count( User::getGroupsWithPermissions( $action ) ) < 1
328 protected function runGroupPermissions( $action, $result, $result2 = null ) {
329 global $wgGroupPermissions;
331 if ( $result2 === null ) {
335 $wgGroupPermissions['autoconfirmed']['move'] = false;
336 $wgGroupPermissions['user']['move'] = false;
337 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
338 $this->assertEquals( $result, $res );
340 $wgGroupPermissions['autoconfirmed']['move'] = true;
341 $wgGroupPermissions['user']['move'] = false;
342 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
343 $this->assertEquals( $result2, $res );
345 $wgGroupPermissions['autoconfirmed']['move'] = true;
346 $wgGroupPermissions['user']['move'] = true;
347 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
348 $this->assertEquals( $result2, $res );
350 $wgGroupPermissions['autoconfirmed']['move'] = false;
351 $wgGroupPermissions['user']['move'] = true;
352 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
353 $this->assertEquals( $result2, $res );
357 * @todo This test method should be split up into separate test methods and
360 public function testSpecialsAndNSPermissions() {
361 global $wgNamespaceProtection;
362 $this->setUser( $this->userName
);
364 $this->setTitle( NS_SPECIAL
);
366 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'ns-specialprotected' ) ),
367 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
369 $this->setTitle( NS_MAIN
);
370 $this->setUserPerm( 'bogus' );
371 $this->assertEquals( array(),
372 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
374 $this->setTitle( NS_MAIN
);
375 $this->setUserPerm( '' );
376 $this->assertEquals( array( array( 'badaccess-group0' ) ),
377 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
379 $wgNamespaceProtection[NS_USER
] = array( 'bogus' );
381 $this->setTitle( NS_USER
);
382 $this->setUserPerm( '' );
383 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'namespaceprotected', 'User' ) ),
384 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
386 $this->setTitle( NS_MEDIAWIKI
);
387 $this->setUserPerm( 'bogus' );
388 $this->assertEquals( array( array( 'protectedinterface' ) ),
389 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
391 $this->setTitle( NS_MEDIAWIKI
);
392 $this->setUserPerm( 'bogus' );
393 $this->assertEquals( array( array( 'protectedinterface' ) ),
394 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
396 $wgNamespaceProtection = null;
398 $this->setUserPerm( 'bogus' );
399 $this->assertEquals( array(),
400 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
401 $this->assertEquals( true,
402 $this->title
->userCan( 'bogus', $this->user
) );
404 $this->setUserPerm( '' );
405 $this->assertEquals( array( array( 'badaccess-group0' ) ),
406 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
407 $this->assertEquals( false,
408 $this->title
->userCan( 'bogus', $this->user
) );
412 * @todo This test method should be split up into separate test methods and
415 public function testCssAndJavascriptPermissions() {
416 $this->setUser( $this->userName
);
418 $this->setTitle( NS_USER
, $this->userName
. '/test.js' );
419 $this->runCSSandJSPermissions(
420 array( array( 'badaccess-group0' ), array( 'mycustomjsprotected' ) ),
421 array( array( 'badaccess-group0' ), array( 'mycustomjsprotected' ) ),
422 array( array( 'badaccess-group0' ) ),
423 array( array( 'badaccess-group0' ), array( 'mycustomjsprotected' ) ),
424 array( array( 'badaccess-group0' ) )
427 $this->setTitle( NS_USER
, $this->userName
. '/test.css' );
428 $this->runCSSandJSPermissions(
429 array( array( 'badaccess-group0' ), array( 'mycustomcssprotected' ) ),
430 array( array( 'badaccess-group0' ) ),
431 array( array( 'badaccess-group0' ), array( 'mycustomcssprotected' ) ),
432 array( array( 'badaccess-group0' ) ),
433 array( array( 'badaccess-group0' ), array( 'mycustomcssprotected' ) )
436 $this->setTitle( NS_USER
, $this->altUserName
. '/test.js' );
437 $this->runCSSandJSPermissions(
438 array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
439 array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
440 array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
441 array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
442 array( array( 'badaccess-group0' ) )
445 $this->setTitle( NS_USER
, $this->altUserName
. '/test.css' );
446 $this->runCSSandJSPermissions(
447 array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ),
448 array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ),
449 array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ),
450 array( array( 'badaccess-group0' ) ),
451 array( array( 'badaccess-group0' ), array( 'customcssprotected' ) )
454 $this->setTitle( NS_USER
, $this->altUserName
. '/tempo' );
455 $this->runCSSandJSPermissions(
456 array( array( 'badaccess-group0' ) ),
457 array( array( 'badaccess-group0' ) ),
458 array( array( 'badaccess-group0' ) ),
459 array( array( 'badaccess-group0' ) ),
460 array( array( 'badaccess-group0' ) )
464 protected function runCSSandJSPermissions( $result0, $result1, $result2, $result3, $result4 ) {
465 $this->setUserPerm( '' );
466 $this->assertEquals( $result0,
467 $this->title
->getUserPermissionsErrors( 'bogus',
470 $this->setUserPerm( 'editmyusercss' );
471 $this->assertEquals( $result1,
472 $this->title
->getUserPermissionsErrors( 'bogus',
475 $this->setUserPerm( 'editmyuserjs' );
476 $this->assertEquals( $result2,
477 $this->title
->getUserPermissionsErrors( 'bogus',
480 $this->setUserPerm( 'editusercss' );
481 $this->assertEquals( $result3,
482 $this->title
->getUserPermissionsErrors( 'bogus',
485 $this->setUserPerm( 'edituserjs' );
486 $this->assertEquals( $result4,
487 $this->title
->getUserPermissionsErrors( 'bogus',
490 $this->setUserPerm( 'editusercssjs' );
491 $this->assertEquals( array( array( 'badaccess-group0' ) ),
492 $this->title
->getUserPermissionsErrors( 'bogus',
495 $this->setUserPerm( array( 'edituserjs', 'editusercss' ) );
496 $this->assertEquals( array( array( 'badaccess-group0' ) ),
497 $this->title
->getUserPermissionsErrors( 'bogus',
502 * @todo This test method should be split up into separate test methods and
505 public function testPageRestrictions() {
508 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT
);
510 $this->setTitle( NS_MAIN
);
511 $this->title
->mRestrictionsLoaded
= true;
512 $this->setUserPerm( "edit" );
513 $this->title
->mRestrictions
= array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
515 $this->assertEquals( array(),
516 $this->title
->getUserPermissionsErrors( 'edit',
519 $this->assertEquals( true,
520 $this->title
->quickUserCan( 'edit', $this->user
) );
521 $this->title
->mRestrictions
= array( "edit" => array( 'bogus', "sysop", "protect", "" ),
522 "bogus" => array( 'bogus', "sysop", "protect", "" ) );
524 $this->assertEquals( array( array( 'badaccess-group0' ),
525 array( 'protectedpagetext', 'bogus' ),
526 array( 'protectedpagetext', 'editprotected' ),
527 array( 'protectedpagetext', 'protect' ) ),
528 $this->title
->getUserPermissionsErrors( 'bogus',
530 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
531 array( 'protectedpagetext', 'editprotected' ),
532 array( 'protectedpagetext', 'protect' ) ),
533 $this->title
->getUserPermissionsErrors( 'edit',
535 $this->setUserPerm( "" );
536 $this->assertEquals( array( array( 'badaccess-group0' ),
537 array( 'protectedpagetext', 'bogus' ),
538 array( 'protectedpagetext', 'editprotected' ),
539 array( 'protectedpagetext', 'protect' ) ),
540 $this->title
->getUserPermissionsErrors( 'bogus',
542 $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ),
543 array( 'protectedpagetext', 'bogus' ),
544 array( 'protectedpagetext', 'editprotected' ),
545 array( 'protectedpagetext', 'protect' ) ),
546 $this->title
->getUserPermissionsErrors( 'edit',
548 $this->setUserPerm( array( "edit", "editprotected" ) );
549 $this->assertEquals( array( array( 'badaccess-group0' ),
550 array( 'protectedpagetext', 'bogus' ),
551 array( 'protectedpagetext', 'protect' ) ),
552 $this->title
->getUserPermissionsErrors( 'bogus',
554 $this->assertEquals( array(
555 array( 'protectedpagetext', 'bogus' ),
556 array( 'protectedpagetext', 'protect' ) ),
557 $this->title
->getUserPermissionsErrors( 'edit',
560 $this->title
->mCascadeRestriction
= true;
561 $this->setUserPerm( "edit" );
562 $this->assertEquals( false,
563 $this->title
->quickUserCan( 'bogus', $this->user
) );
564 $this->assertEquals( false,
565 $this->title
->quickUserCan( 'edit', $this->user
) );
566 $this->assertEquals( array( array( 'badaccess-group0' ),
567 array( 'protectedpagetext', 'bogus' ),
568 array( 'protectedpagetext', 'editprotected' ),
569 array( 'protectedpagetext', 'protect' ) ),
570 $this->title
->getUserPermissionsErrors( 'bogus',
572 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
573 array( 'protectedpagetext', 'editprotected' ),
574 array( 'protectedpagetext', 'protect' ) ),
575 $this->title
->getUserPermissionsErrors( 'edit',
578 $this->setUserPerm( array( "edit", "editprotected" ) );
579 $this->assertEquals( false,
580 $this->title
->quickUserCan( 'bogus', $this->user
) );
581 $this->assertEquals( false,
582 $this->title
->quickUserCan( 'edit', $this->user
) );
583 $this->assertEquals( array( array( 'badaccess-group0' ),
584 array( 'protectedpagetext', 'bogus' ),
585 array( 'protectedpagetext', 'protect' ),
586 array( 'protectedpagetext', 'protect' ) ),
587 $this->title
->getUserPermissionsErrors( 'bogus',
589 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
590 array( 'protectedpagetext', 'protect' ),
591 array( 'protectedpagetext', 'protect' ) ),
592 $this->title
->getUserPermissionsErrors( 'edit',
596 public function testCascadingSourcesRestrictions() {
597 $this->setTitle( NS_MAIN
, "test page" );
598 $this->setUserPerm( array( "edit", "bogus" ) );
600 $this->title
->mCascadeSources
= array( Title
::makeTitle( NS_MAIN
, "Bogus" ), Title
::makeTitle( NS_MAIN
, "UnBogus" ) );
601 $this->title
->mCascadingRestrictions
= array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
603 $this->assertEquals( false,
604 $this->title
->userCan( 'bogus', $this->user
) );
605 $this->assertEquals( array( array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ),
606 array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ),
607 array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ) ),
608 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
610 $this->assertEquals( true,
611 $this->title
->userCan( 'edit', $this->user
) );
612 $this->assertEquals( array(),
613 $this->title
->getUserPermissionsErrors( 'edit', $this->user
) );
617 * @todo This test method should be split up into separate test methods and
620 public function testActionPermissions() {
621 $this->setUserPerm( array( "createpage" ) );
622 $this->setTitle( NS_MAIN
, "test page" );
623 $this->title
->mTitleProtection
['pt_create_perm'] = '';
624 $this->title
->mTitleProtection
['pt_user'] = $this->user
->getID();
625 $this->title
->mTitleProtection
['pt_expiry'] = wfGetDB( DB_SLAVE
)->getInfinity();
626 $this->title
->mTitleProtection
['pt_reason'] = 'test';
627 $this->title
->mCascadeRestriction
= false;
629 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
630 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
631 $this->assertEquals( false,
632 $this->title
->userCan( 'create', $this->user
) );
634 $this->title
->mTitleProtection
['pt_create_perm'] = 'sysop';
635 $this->setUserPerm( array( 'createpage', 'protect' ) );
636 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
637 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
638 $this->assertEquals( false,
639 $this->title
->userCan( 'create', $this->user
) );
641 $this->setUserPerm( array( 'createpage', 'editprotected' ) );
642 $this->assertEquals( array(),
643 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
644 $this->assertEquals( true,
645 $this->title
->userCan( 'create', $this->user
) );
647 $this->setUserPerm( array( 'createpage' ) );
648 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
649 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
650 $this->assertEquals( false,
651 $this->title
->userCan( 'create', $this->user
) );
653 $this->setTitle( NS_MEDIA
, "test page" );
654 $this->setUserPerm( array( "move" ) );
655 $this->assertEquals( false,
656 $this->title
->userCan( 'move', $this->user
) );
657 $this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ),
658 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
660 $this->setTitle( NS_HELP
, "test page" );
661 $this->assertEquals( array(),
662 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
663 $this->assertEquals( true,
664 $this->title
->userCan( 'move', $this->user
) );
666 $this->title
->mInterwiki
= "no";
667 $this->assertEquals( array( array( 'immobile-source-page' ) ),
668 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
669 $this->assertEquals( false,
670 $this->title
->userCan( 'move', $this->user
) );
672 $this->setTitle( NS_MEDIA
, "test page" );
673 $this->assertEquals( false,
674 $this->title
->userCan( 'move-target', $this->user
) );
675 $this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ),
676 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
678 $this->setTitle( NS_HELP
, "test page" );
679 $this->assertEquals( array(),
680 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
681 $this->assertEquals( true,
682 $this->title
->userCan( 'move-target', $this->user
) );
684 $this->title
->mInterwiki
= "no";
685 $this->assertEquals( array( array( 'immobile-target-page' ) ),
686 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
687 $this->assertEquals( false,
688 $this->title
->userCan( 'move-target', $this->user
) );
691 public function testUserBlock() {
692 global $wgEmailConfirmToEdit, $wgEmailAuthentication;
693 $wgEmailConfirmToEdit = true;
694 $wgEmailAuthentication = true;
696 $this->setUserPerm( array( "createpage", "move" ) );
697 $this->setTitle( NS_HELP
, "test page" );
700 $this->assertEquals( array( array( 'confirmedittext' ) ),
701 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
702 $wgEmailConfirmToEdit = false;
703 $this->assertEquals( true, $this->title
->userCan( 'move-target', $this->user
) );
705 # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
706 $this->assertEquals( array(),
707 $this->title
->getUserPermissionsErrors( 'move-target',
713 $this->user
->mBlockedby
= $this->user
->getId();
714 $this->user
->mBlock
= new Block( '127.0.8.1', 0, $this->user
->getId(),
715 'no reason given', $prev +
3600, 1, 0 );
716 $this->user
->mBlock
->mTimestamp
= 0;
717 $this->assertEquals( array( array( 'autoblockedtext',
718 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
719 'Useruser', null, 'infinite', '127.0.8.1',
720 $wgLang->timeanddate( wfTimestamp( TS_MW
, $prev ), true ) ) ),
721 $this->title
->getUserPermissionsErrors( 'move-target',
724 $this->assertEquals( false, $this->title
->userCan( 'move-target', $this->user
) );
725 // quickUserCan should ignore user blocks
726 $this->assertEquals( true, $this->title
->quickUserCan( 'move-target', $this->user
) );
728 global $wgLocalTZoffset;
729 $wgLocalTZoffset = -60;
730 $this->user
->mBlockedby
= $this->user
->getName();
731 $this->user
->mBlock
= new Block( '127.0.8.1', 0, $this->user
->getId(),
732 'no reason given', $now, 0, 10 );
733 $this->assertEquals( array( array( 'blockedtext',
734 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
735 'Useruser', null, '23:00, 31 December 1969', '127.0.8.1',
736 $wgLang->timeanddate( wfTimestamp( TS_MW
, $now ), true ) ) ),
737 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
738 # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
739 # $user->blockedFor() == ''
740 # $user->mBlock->mExpiry == 'infinity'