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',
45 $this->userName
= 'Useruser';
46 $this->altUserName
= 'Altuseruser';
47 date_default_timezone_set( $localZone );
49 $this->title
= Title
::makeTitle( NS_MAIN
, "Main Page" );
50 if ( !isset( $this->userUser
) ||
!( $this->userUser
instanceof User
) ) {
51 $this->userUser
= User
::newFromName( $this->userName
);
53 if ( !$this->userUser
->getID() ) {
54 $this->userUser
= User
::createNew( $this->userName
, array(
55 "email" => "test@example.com",
56 "real_name" => "Test User" ) );
57 $this->userUser
->load();
60 $this->altUser
= User
::newFromName( $this->altUserName
);
61 if ( !$this->altUser
->getID() ) {
62 $this->altUser
= User
::createNew( $this->altUserName
, array(
63 "email" => "alttest@example.com",
64 "real_name" => "Test User Alt" ) );
65 $this->altUser
->load();
68 $this->anonUser
= User
::newFromId( 0 );
70 $this->user
= $this->userUser
;
74 protected function setUserPerm( $perm ) {
75 // Setting member variables is evil!!!
77 if ( is_array( $perm ) ) {
78 $this->user
->mRights
= $perm;
80 $this->user
->mRights
= array( $perm );
84 protected function setTitle( $ns, $title = "Main_Page" ) {
85 $this->title
= Title
::makeTitle( $ns, $title );
88 protected function setUser( $userName = null ) {
89 if ( $userName === 'anon' ) {
90 $this->user
= $this->anonUser
;
91 } elseif ( $userName === null ||
$userName === $this->userName
) {
92 $this->user
= $this->userUser
;
94 $this->user
= $this->altUser
;
99 * @todo This test method should be split up into separate test methods and
102 public function testQuickPermissions() {
104 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT
);
106 $this->setUser( 'anon' );
107 $this->setTitle( NS_TALK
);
108 $this->setUserPerm( "createtalk" );
109 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
110 $this->assertEquals( array(), $res );
112 $this->setTitle( NS_TALK
);
113 $this->setUserPerm( "createpage" );
114 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
115 $this->assertEquals( array( array( "nocreatetext" ) ), $res );
117 $this->setTitle( NS_TALK
);
118 $this->setUserPerm( "" );
119 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
120 $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
122 $this->setTitle( NS_MAIN
);
123 $this->setUserPerm( "createpage" );
124 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
125 $this->assertEquals( array(), $res );
127 $this->setTitle( NS_MAIN
);
128 $this->setUserPerm( "createtalk" );
129 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
130 $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
132 $this->setUser( $this->userName
);
133 $this->setTitle( NS_TALK
);
134 $this->setUserPerm( "createtalk" );
135 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
136 $this->assertEquals( array(), $res );
138 $this->setTitle( NS_TALK
);
139 $this->setUserPerm( "createpage" );
140 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
141 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
143 $this->setTitle( NS_TALK
);
144 $this->setUserPerm( "" );
145 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
146 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
148 $this->setTitle( NS_MAIN
);
149 $this->setUserPerm( "createpage" );
150 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
151 $this->assertEquals( array(), $res );
153 $this->setTitle( NS_MAIN
);
154 $this->setUserPerm( "createtalk" );
155 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
156 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
158 $this->setTitle( NS_MAIN
);
159 $this->setUserPerm( "" );
160 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
161 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
163 $this->setUser( 'anon' );
164 $this->setTitle( NS_USER
, $this->userName
. '' );
165 $this->setUserPerm( "" );
166 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
167 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
169 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
170 $this->setUserPerm( "" );
171 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
172 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
174 $this->setTitle( NS_USER
, $this->userName
. '' );
175 $this->setUserPerm( "move-rootuserpages" );
176 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
177 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
179 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
180 $this->setUserPerm( "move-rootuserpages" );
181 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
182 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
184 $this->setTitle( NS_USER
, $this->userName
. '' );
185 $this->setUserPerm( "" );
186 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
187 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
189 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
190 $this->setUserPerm( "" );
191 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
192 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
194 $this->setTitle( NS_USER
, $this->userName
. '' );
195 $this->setUserPerm( "move-rootuserpages" );
196 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
197 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
199 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
200 $this->setUserPerm( "move-rootuserpages" );
201 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
202 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
204 $this->setUser( $this->userName
);
205 $this->setTitle( NS_FILE
, "img.png" );
206 $this->setUserPerm( "" );
207 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
208 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ), $res );
210 $this->setTitle( NS_FILE
, "img.png" );
211 $this->setUserPerm( "movefile" );
212 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
213 $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
215 $this->setUser( 'anon' );
216 $this->setTitle( NS_FILE
, "img.png" );
217 $this->setUserPerm( "" );
218 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
219 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ), $res );
221 $this->setTitle( NS_FILE
, "img.png" );
222 $this->setUserPerm( "movefile" );
223 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
224 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
226 $this->setUser( $this->userName
);
227 $this->setUserPerm( "move" );
228 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
230 $this->setUserPerm( "" );
231 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ) );
233 $this->setUser( 'anon' );
234 $this->setUserPerm( "move" );
235 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
237 $this->setUserPerm( "" );
238 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ),
239 array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ) );
241 if ( $this->isWikitextNS( NS_MAIN
) ) {
242 //NOTE: some content models don't allow moving
243 // @todo find a Wikitext namespace for testing
245 $this->setTitle( NS_MAIN
);
246 $this->setUser( 'anon' );
247 $this->setUserPerm( "move" );
248 $this->runGroupPermissions( 'move', array() );
250 $this->setUserPerm( "" );
251 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ),
252 array( array( 'movenologintext' ) ) );
254 $this->setUser( $this->userName
);
255 $this->setUserPerm( "" );
256 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ) );
258 $this->setUserPerm( "move" );
259 $this->runGroupPermissions( 'move', array() );
261 $this->setUser( 'anon' );
262 $this->setUserPerm( 'move' );
263 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
264 $this->assertEquals( array(), $res );
266 $this->setUserPerm( '' );
267 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
268 $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
271 $this->setTitle( NS_USER
);
272 $this->setUser( $this->userName
);
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( array( 'cant-move-to-user-page' ) ), $res );
281 $this->setUser( 'anon' );
282 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
283 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
284 $this->assertEquals( array(), $res );
286 $this->setTitle( NS_USER
, "User/subpage" );
287 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
288 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
289 $this->assertEquals( array(), $res );
291 $this->setUserPerm( "move" );
292 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
293 $this->assertEquals( array(), $res );
295 $this->setUser( 'anon' );
296 $check = array( 'edit' => array( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ) ),
297 array( array( 'badaccess-group0' ) ),
299 'protect' => array( array( array( 'badaccess-groups', "[[$prefix:Administrators|Administrators]]", 1 ), array( 'protect-cantedit' ) ),
300 array( array( 'badaccess-group0' ), array( 'protect-cantedit' ) ),
301 array( array( 'protect-cantedit' ) ), false ),
302 '' => array( array(), array(), array(), true ) );
304 foreach ( array( "edit", "protect", "" ) as $action ) {
305 $this->setUserPerm( null );
306 $this->assertEquals( $check[$action][0],
307 $this->title
->getUserPermissionsErrors( $action, $this->user
, true ) );
309 global $wgGroupPermissions;
310 $old = $wgGroupPermissions;
311 $wgGroupPermissions = array();
313 $this->assertEquals( $check[$action][1],
314 $this->title
->getUserPermissionsErrors( $action, $this->user
, true ) );
315 $wgGroupPermissions = $old;
317 $this->setUserPerm( $action );
318 $this->assertEquals( $check[$action][2],
319 $this->title
->getUserPermissionsErrors( $action, $this->user
, true ) );
321 $this->setUserPerm( $action );
322 $this->assertEquals( $check[$action][3],
323 $this->title
->userCan( $action, $this->user
, true ) );
324 $this->assertEquals( $check[$action][3],
325 $this->title
->quickUserCan( $action, $this->user
) );
326 # count( User::getGroupsWithPermissions( $action ) ) < 1
330 protected function runGroupPermissions( $action, $result, $result2 = null ) {
331 global $wgGroupPermissions;
333 if ( $result2 === null ) {
337 $wgGroupPermissions['autoconfirmed']['move'] = false;
338 $wgGroupPermissions['user']['move'] = false;
339 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
340 $this->assertEquals( $result, $res );
342 $wgGroupPermissions['autoconfirmed']['move'] = true;
343 $wgGroupPermissions['user']['move'] = false;
344 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
345 $this->assertEquals( $result2, $res );
347 $wgGroupPermissions['autoconfirmed']['move'] = true;
348 $wgGroupPermissions['user']['move'] = true;
349 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
350 $this->assertEquals( $result2, $res );
352 $wgGroupPermissions['autoconfirmed']['move'] = false;
353 $wgGroupPermissions['user']['move'] = true;
354 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
355 $this->assertEquals( $result2, $res );
359 * @todo This test method should be split up into separate test methods and
362 public function testSpecialsAndNSPermissions() {
363 global $wgNamespaceProtection;
364 $this->setUser( $this->userName
);
366 $this->setTitle( NS_SPECIAL
);
368 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'ns-specialprotected' ) ),
369 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
371 $this->setTitle( NS_MAIN
);
372 $this->setUserPerm( 'bogus' );
373 $this->assertEquals( array(),
374 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
376 $this->setTitle( NS_MAIN
);
377 $this->setUserPerm( '' );
378 $this->assertEquals( array( array( 'badaccess-group0' ) ),
379 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
381 $wgNamespaceProtection[NS_USER
] = array( 'bogus' );
383 $this->setTitle( NS_USER
);
384 $this->setUserPerm( '' );
385 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'namespaceprotected', 'User' ) ),
386 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
388 $this->setTitle( NS_MEDIAWIKI
);
389 $this->setUserPerm( 'bogus' );
390 $this->assertEquals( array( array( 'protectedinterface' ) ),
391 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
393 $this->setTitle( NS_MEDIAWIKI
);
394 $this->setUserPerm( 'bogus' );
395 $this->assertEquals( array( array( 'protectedinterface' ) ),
396 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
398 $wgNamespaceProtection = null;
400 $this->setUserPerm( 'bogus' );
401 $this->assertEquals( array(),
402 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
403 $this->assertEquals( true,
404 $this->title
->userCan( 'bogus', $this->user
) );
406 $this->setUserPerm( '' );
407 $this->assertEquals( array( array( 'badaccess-group0' ) ),
408 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
409 $this->assertEquals( false,
410 $this->title
->userCan( 'bogus', $this->user
) );
414 * @todo This test method should be split up into separate test methods and
417 public function testCssAndJavascriptPermissions() {
418 $this->setUser( $this->userName
);
420 $this->setTitle( NS_USER
, $this->userName
. '/test.js' );
421 $this->runCSSandJSPermissions(
422 array( array( 'badaccess-group0' ), array( 'mycustomjsprotected' ) ),
423 array( array( 'badaccess-group0' ), array( 'mycustomjsprotected' ) ),
424 array( array( 'badaccess-group0' ) ),
425 array( array( 'badaccess-group0' ), array( 'mycustomjsprotected' ) ),
426 array( array( 'badaccess-group0' ) )
429 $this->setTitle( NS_USER
, $this->userName
. '/test.css' );
430 $this->runCSSandJSPermissions(
431 array( array( 'badaccess-group0' ), array( 'mycustomcssprotected' ) ),
432 array( array( 'badaccess-group0' ) ),
433 array( array( 'badaccess-group0' ), array( 'mycustomcssprotected' ) ),
434 array( array( 'badaccess-group0' ) ),
435 array( array( 'badaccess-group0' ), array( 'mycustomcssprotected' ) )
438 $this->setTitle( NS_USER
, $this->altUserName
. '/test.js' );
439 $this->runCSSandJSPermissions(
440 array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
441 array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
442 array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
443 array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
444 array( array( 'badaccess-group0' ) )
447 $this->setTitle( NS_USER
, $this->altUserName
. '/test.css' );
448 $this->runCSSandJSPermissions(
449 array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ),
450 array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ),
451 array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ),
452 array( array( 'badaccess-group0' ) ),
453 array( array( 'badaccess-group0' ), array( 'customcssprotected' ) )
456 $this->setTitle( NS_USER
, $this->altUserName
. '/tempo' );
457 $this->runCSSandJSPermissions(
458 array( array( 'badaccess-group0' ) ),
459 array( array( 'badaccess-group0' ) ),
460 array( array( 'badaccess-group0' ) ),
461 array( array( 'badaccess-group0' ) ),
462 array( array( 'badaccess-group0' ) )
466 protected function runCSSandJSPermissions( $result0, $result1, $result2, $result3, $result4 ) {
467 $this->setUserPerm( '' );
468 $this->assertEquals( $result0,
469 $this->title
->getUserPermissionsErrors( 'bogus',
472 $this->setUserPerm( 'editmyusercss' );
473 $this->assertEquals( $result1,
474 $this->title
->getUserPermissionsErrors( 'bogus',
477 $this->setUserPerm( 'editmyuserjs' );
478 $this->assertEquals( $result2,
479 $this->title
->getUserPermissionsErrors( 'bogus',
482 $this->setUserPerm( 'editusercss' );
483 $this->assertEquals( $result3,
484 $this->title
->getUserPermissionsErrors( 'bogus',
487 $this->setUserPerm( 'edituserjs' );
488 $this->assertEquals( $result4,
489 $this->title
->getUserPermissionsErrors( 'bogus',
492 $this->setUserPerm( 'editusercssjs' );
493 $this->assertEquals( array( array( 'badaccess-group0' ) ),
494 $this->title
->getUserPermissionsErrors( 'bogus',
497 $this->setUserPerm( array( 'edituserjs', 'editusercss' ) );
498 $this->assertEquals( array( array( 'badaccess-group0' ) ),
499 $this->title
->getUserPermissionsErrors( 'bogus',
504 * @todo This test method should be split up into separate test methods and
507 public function testPageRestrictions() {
510 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT
);
512 $this->setTitle( NS_MAIN
);
513 $this->title
->mRestrictionsLoaded
= true;
514 $this->setUserPerm( "edit" );
515 $this->title
->mRestrictions
= array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
517 $this->assertEquals( array(),
518 $this->title
->getUserPermissionsErrors( 'edit',
521 $this->assertEquals( true,
522 $this->title
->quickUserCan( 'edit', $this->user
) );
523 $this->title
->mRestrictions
= array( "edit" => array( 'bogus', "sysop", "protect", "" ),
524 "bogus" => array( 'bogus', "sysop", "protect", "" ) );
526 $this->assertEquals( array( array( 'badaccess-group0' ),
527 array( 'protectedpagetext', 'bogus' ),
528 array( 'protectedpagetext', 'editprotected' ),
529 array( 'protectedpagetext', 'protect' ) ),
530 $this->title
->getUserPermissionsErrors( 'bogus',
532 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
533 array( 'protectedpagetext', 'editprotected' ),
534 array( 'protectedpagetext', 'protect' ) ),
535 $this->title
->getUserPermissionsErrors( 'edit',
537 $this->setUserPerm( "" );
538 $this->assertEquals( array( array( 'badaccess-group0' ),
539 array( 'protectedpagetext', 'bogus' ),
540 array( 'protectedpagetext', 'editprotected' ),
541 array( 'protectedpagetext', 'protect' ) ),
542 $this->title
->getUserPermissionsErrors( 'bogus',
544 $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ),
545 array( 'protectedpagetext', 'bogus' ),
546 array( 'protectedpagetext', 'editprotected' ),
547 array( 'protectedpagetext', 'protect' ) ),
548 $this->title
->getUserPermissionsErrors( 'edit',
550 $this->setUserPerm( array( "edit", "editprotected" ) );
551 $this->assertEquals( array( array( 'badaccess-group0' ),
552 array( 'protectedpagetext', 'bogus' ),
553 array( 'protectedpagetext', 'protect' ) ),
554 $this->title
->getUserPermissionsErrors( 'bogus',
556 $this->assertEquals( array(
557 array( 'protectedpagetext', 'bogus' ),
558 array( 'protectedpagetext', 'protect' ) ),
559 $this->title
->getUserPermissionsErrors( 'edit',
562 $this->title
->mCascadeRestriction
= true;
563 $this->setUserPerm( "edit" );
564 $this->assertEquals( false,
565 $this->title
->quickUserCan( 'bogus', $this->user
) );
566 $this->assertEquals( false,
567 $this->title
->quickUserCan( 'edit', $this->user
) );
568 $this->assertEquals( array( array( 'badaccess-group0' ),
569 array( 'protectedpagetext', 'bogus' ),
570 array( 'protectedpagetext', 'editprotected' ),
571 array( 'protectedpagetext', 'protect' ) ),
572 $this->title
->getUserPermissionsErrors( 'bogus',
574 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
575 array( 'protectedpagetext', 'editprotected' ),
576 array( 'protectedpagetext', 'protect' ) ),
577 $this->title
->getUserPermissionsErrors( 'edit',
580 $this->setUserPerm( array( "edit", "editprotected" ) );
581 $this->assertEquals( false,
582 $this->title
->quickUserCan( 'bogus', $this->user
) );
583 $this->assertEquals( false,
584 $this->title
->quickUserCan( 'edit', $this->user
) );
585 $this->assertEquals( array( array( 'badaccess-group0' ),
586 array( 'protectedpagetext', 'bogus' ),
587 array( 'protectedpagetext', 'protect' ),
588 array( 'protectedpagetext', 'protect' ) ),
589 $this->title
->getUserPermissionsErrors( 'bogus',
591 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
592 array( 'protectedpagetext', 'protect' ),
593 array( 'protectedpagetext', 'protect' ) ),
594 $this->title
->getUserPermissionsErrors( 'edit',
598 public function testCascadingSourcesRestrictions() {
599 $this->setTitle( NS_MAIN
, "test page" );
600 $this->setUserPerm( array( "edit", "bogus" ) );
602 $this->title
->mCascadeSources
= array( Title
::makeTitle( NS_MAIN
, "Bogus" ), Title
::makeTitle( NS_MAIN
, "UnBogus" ) );
603 $this->title
->mCascadingRestrictions
= array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
605 $this->assertEquals( false,
606 $this->title
->userCan( 'bogus', $this->user
) );
607 $this->assertEquals( array( array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ),
608 array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ),
609 array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ) ),
610 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
612 $this->assertEquals( true,
613 $this->title
->userCan( 'edit', $this->user
) );
614 $this->assertEquals( array(),
615 $this->title
->getUserPermissionsErrors( 'edit', $this->user
) );
619 * @todo This test method should be split up into separate test methods and
622 public function testActionPermissions() {
623 $this->setUserPerm( array( "createpage" ) );
624 $this->setTitle( NS_MAIN
, "test page" );
625 $this->title
->mTitleProtection
['pt_create_perm'] = '';
626 $this->title
->mTitleProtection
['pt_user'] = $this->user
->getID();
627 $this->title
->mTitleProtection
['pt_expiry'] = wfGetDB( DB_SLAVE
)->getInfinity();
628 $this->title
->mTitleProtection
['pt_reason'] = 'test';
629 $this->title
->mCascadeRestriction
= false;
631 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
632 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
633 $this->assertEquals( false,
634 $this->title
->userCan( 'create', $this->user
) );
636 $this->title
->mTitleProtection
['pt_create_perm'] = 'sysop';
637 $this->setUserPerm( array( 'createpage', 'protect' ) );
638 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
639 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
640 $this->assertEquals( false,
641 $this->title
->userCan( 'create', $this->user
) );
643 $this->setUserPerm( array( 'createpage', 'editprotected' ) );
644 $this->assertEquals( array(),
645 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
646 $this->assertEquals( true,
647 $this->title
->userCan( 'create', $this->user
) );
649 $this->setUserPerm( array( 'createpage' ) );
650 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
651 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
652 $this->assertEquals( false,
653 $this->title
->userCan( 'create', $this->user
) );
655 $this->setTitle( NS_MEDIA
, "test page" );
656 $this->setUserPerm( array( "move" ) );
657 $this->assertEquals( false,
658 $this->title
->userCan( 'move', $this->user
) );
659 $this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ),
660 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
662 $this->setTitle( NS_HELP
, "test page" );
663 $this->assertEquals( array(),
664 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
665 $this->assertEquals( true,
666 $this->title
->userCan( 'move', $this->user
) );
668 $this->title
->mInterwiki
= "no";
669 $this->assertEquals( array( array( 'immobile-source-page' ) ),
670 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
671 $this->assertEquals( false,
672 $this->title
->userCan( 'move', $this->user
) );
674 $this->setTitle( NS_MEDIA
, "test page" );
675 $this->assertEquals( false,
676 $this->title
->userCan( 'move-target', $this->user
) );
677 $this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ),
678 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
680 $this->setTitle( NS_HELP
, "test page" );
681 $this->assertEquals( array(),
682 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
683 $this->assertEquals( true,
684 $this->title
->userCan( 'move-target', $this->user
) );
686 $this->title
->mInterwiki
= "no";
687 $this->assertEquals( array( array( 'immobile-target-page' ) ),
688 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
689 $this->assertEquals( false,
690 $this->title
->userCan( 'move-target', $this->user
) );
693 public function testUserBlock() {
694 global $wgEmailConfirmToEdit, $wgEmailAuthentication;
695 $wgEmailConfirmToEdit = true;
696 $wgEmailAuthentication = true;
698 $this->setUserPerm( array( "createpage", "move" ) );
699 $this->setTitle( NS_HELP
, "test page" );
702 $this->assertEquals( array( array( 'confirmedittext' ) ),
703 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
704 $wgEmailConfirmToEdit = false;
705 $this->assertEquals( true, $this->title
->userCan( 'move-target', $this->user
) );
707 # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
708 $this->assertEquals( array(),
709 $this->title
->getUserPermissionsErrors( 'move-target',
715 $this->user
->mBlockedby
= $this->user
->getId();
716 $this->user
->mBlock
= new Block( '127.0.8.1', 0, $this->user
->getId(),
717 'no reason given', $prev +
3600, 1, 0 );
718 $this->user
->mBlock
->mTimestamp
= 0;
719 $this->assertEquals( array( array( 'autoblockedtext',
720 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
721 'Useruser', null, 'infinite', '127.0.8.1',
722 $wgLang->timeanddate( wfTimestamp( TS_MW
, $prev ), true ) ) ),
723 $this->title
->getUserPermissionsErrors( 'move-target',
726 $this->assertEquals( false, $this->title
->userCan( 'move-target', $this->user
) );
727 // quickUserCan should ignore user blocks
728 $this->assertEquals( true, $this->title
->quickUserCan( 'move-target', $this->user
) );
730 global $wgLocalTZoffset;
731 $wgLocalTZoffset = -60;
732 $this->user
->mBlockedby
= $this->user
->getName();
733 $this->user
->mBlock
= new Block( '127.0.8.1', 0, $this->user
->getId(),
734 'no reason given', $now, 0, 10 );
735 $this->assertEquals( array( array( 'blockedtext',
736 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
737 'Useruser', null, '23:00, 31 December 1969', '127.0.8.1',
738 $wgLang->timeanddate( wfTimestamp( TS_MW
, $now ), true ) ) ),
739 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
740 # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
741 # $user->blockedFor() == ''
742 # $user->mBlock->mExpiry == 'infinity'