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 'wgContLang' => $langObj,
35 'wgLanguageCode' => 'en',
37 'wgLocaltimezone' => $localZone,
38 'wgLocalTZoffset' => $localOffset,
39 'wgNamespaceProtection' => array(
40 NS_MEDIAWIKI
=> 'editinterface',
43 // Without this testUserBlock will use a non-English context on non-English MediaWiki
44 // installations (because of how Title::checkUserBlock is implemented) and fail.
45 RequestContext
::resetMain();
47 $this->userName
= 'Useruser';
48 $this->altUserName
= 'Altuseruser';
49 date_default_timezone_set( $localZone );
51 $this->title
= Title
::makeTitle( NS_MAIN
, "Main Page" );
52 if ( !isset( $this->userUser
) ||
!( $this->userUser
instanceof User
) ) {
53 $this->userUser
= User
::newFromName( $this->userName
);
55 if ( !$this->userUser
->getID() ) {
56 $this->userUser
= User
::createNew( $this->userName
, array(
57 "email" => "test@example.com",
58 "real_name" => "Test User" ) );
59 $this->userUser
->load();
62 $this->altUser
= User
::newFromName( $this->altUserName
);
63 if ( !$this->altUser
->getID() ) {
64 $this->altUser
= User
::createNew( $this->altUserName
, array(
65 "email" => "alttest@example.com",
66 "real_name" => "Test User Alt" ) );
67 $this->altUser
->load();
70 $this->anonUser
= User
::newFromId( 0 );
72 $this->user
= $this->userUser
;
76 protected function setUserPerm( $perm ) {
77 // Setting member variables is evil!!!
79 if ( is_array( $perm ) ) {
80 $this->user
->mRights
= $perm;
82 $this->user
->mRights
= array( $perm );
86 protected function setTitle( $ns, $title = "Main_Page" ) {
87 $this->title
= Title
::makeTitle( $ns, $title );
90 protected function setUser( $userName = null ) {
91 if ( $userName === 'anon' ) {
92 $this->user
= $this->anonUser
;
93 } elseif ( $userName === null ||
$userName === $this->userName
) {
94 $this->user
= $this->userUser
;
96 $this->user
= $this->altUser
;
101 * @todo This test method should be split up into separate test methods and
104 public function testQuickPermissions() {
106 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT
);
108 $this->setUser( 'anon' );
109 $this->setTitle( NS_TALK
);
110 $this->setUserPerm( "createtalk" );
111 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
112 $this->assertEquals( array(), $res );
114 $this->setTitle( NS_TALK
);
115 $this->setUserPerm( "createpage" );
116 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
117 $this->assertEquals( array( array( "nocreatetext" ) ), $res );
119 $this->setTitle( NS_TALK
);
120 $this->setUserPerm( "" );
121 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
122 $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
124 $this->setTitle( NS_MAIN
);
125 $this->setUserPerm( "createpage" );
126 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
127 $this->assertEquals( array(), $res );
129 $this->setTitle( NS_MAIN
);
130 $this->setUserPerm( "createtalk" );
131 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
132 $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
134 $this->setUser( $this->userName
);
135 $this->setTitle( NS_TALK
);
136 $this->setUserPerm( "createtalk" );
137 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
138 $this->assertEquals( array(), $res );
140 $this->setTitle( NS_TALK
);
141 $this->setUserPerm( "createpage" );
142 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
143 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
145 $this->setTitle( NS_TALK
);
146 $this->setUserPerm( "" );
147 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
148 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
150 $this->setTitle( NS_MAIN
);
151 $this->setUserPerm( "createpage" );
152 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
153 $this->assertEquals( array(), $res );
155 $this->setTitle( NS_MAIN
);
156 $this->setUserPerm( "createtalk" );
157 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
158 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
160 $this->setTitle( NS_MAIN
);
161 $this->setUserPerm( "" );
162 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
163 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
165 $this->setUser( 'anon' );
166 $this->setTitle( NS_USER
, $this->userName
. '' );
167 $this->setUserPerm( "" );
168 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
169 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
171 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
172 $this->setUserPerm( "" );
173 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
174 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
176 $this->setTitle( NS_USER
, $this->userName
. '' );
177 $this->setUserPerm( "move-rootuserpages" );
178 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
179 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
181 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
182 $this->setUserPerm( "move-rootuserpages" );
183 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
184 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
186 $this->setTitle( NS_USER
, $this->userName
. '' );
187 $this->setUserPerm( "" );
188 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
189 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
191 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
192 $this->setUserPerm( "" );
193 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
194 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
196 $this->setTitle( NS_USER
, $this->userName
. '' );
197 $this->setUserPerm( "move-rootuserpages" );
198 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
199 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
201 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
202 $this->setUserPerm( "move-rootuserpages" );
203 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
204 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
206 $this->setUser( $this->userName
);
207 $this->setTitle( NS_FILE
, "img.png" );
208 $this->setUserPerm( "" );
209 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
210 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ), $res );
212 $this->setTitle( NS_FILE
, "img.png" );
213 $this->setUserPerm( "movefile" );
214 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
215 $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
217 $this->setUser( 'anon' );
218 $this->setTitle( NS_FILE
, "img.png" );
219 $this->setUserPerm( "" );
220 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
221 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ), $res );
223 $this->setTitle( NS_FILE
, "img.png" );
224 $this->setUserPerm( "movefile" );
225 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
226 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
228 $this->setUser( $this->userName
);
229 $this->setUserPerm( "move" );
230 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
232 $this->setUserPerm( "" );
233 $this->runGroupPermissions(
235 array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) )
238 $this->setUser( 'anon' );
239 $this->setUserPerm( "move" );
240 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
242 $this->setUserPerm( "" );
243 $this->runGroupPermissions(
245 array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ),
246 array( array( 'movenotallowedfile' ), array( 'movenologintext' ) )
249 if ( $this->isWikitextNS( NS_MAIN
) ) {
250 // NOTE: some content models don't allow moving
251 // @todo find a Wikitext namespace for testing
253 $this->setTitle( NS_MAIN
);
254 $this->setUser( 'anon' );
255 $this->setUserPerm( "move" );
256 $this->runGroupPermissions( 'move', array() );
258 $this->setUserPerm( "" );
259 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ),
260 array( array( 'movenologintext' ) ) );
262 $this->setUser( $this->userName
);
263 $this->setUserPerm( "" );
264 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ) );
266 $this->setUserPerm( "move" );
267 $this->runGroupPermissions( 'move', array() );
269 $this->setUser( 'anon' );
270 $this->setUserPerm( 'move' );
271 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
272 $this->assertEquals( array(), $res );
274 $this->setUserPerm( '' );
275 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
276 $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
279 $this->setTitle( NS_USER
);
280 $this->setUser( $this->userName
);
281 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
282 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
283 $this->assertEquals( array(), $res );
285 $this->setUserPerm( "move" );
286 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
287 $this->assertEquals( array( array( 'cant-move-to-user-page' ) ), $res );
289 $this->setUser( 'anon' );
290 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
291 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
292 $this->assertEquals( array(), $res );
294 $this->setTitle( NS_USER
, "User/subpage" );
295 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
296 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
297 $this->assertEquals( array(), $res );
299 $this->setUserPerm( "move" );
300 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
301 $this->assertEquals( array(), $res );
303 $this->setUser( 'anon' );
306 array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ) ),
307 array( array( 'badaccess-group0' ) ),
314 "[[$prefix:Administrators|Administrators]]", 1 ),
315 array( 'protect-cantedit'
317 array( array( 'badaccess-group0' ), array( 'protect-cantedit' ) ),
318 array( array( 'protect-cantedit' ) ),
321 '' => array( array(), array(), array(), true )
324 foreach ( array( "edit", "protect", "" ) as $action ) {
325 $this->setUserPerm( null );
326 $this->assertEquals( $check[$action][0],
327 $this->title
->getUserPermissionsErrors( $action, $this->user
, true ) );
328 $this->assertEquals( $check[$action][0],
329 $this->title
->getUserPermissionsErrors( $action, $this->user
, 'full' ) );
330 $this->assertEquals( $check[$action][0],
331 $this->title
->getUserPermissionsErrors( $action, $this->user
, 'secure' ) );
333 global $wgGroupPermissions;
334 $old = $wgGroupPermissions;
335 $wgGroupPermissions = array();
337 $this->assertEquals( $check[$action][1],
338 $this->title
->getUserPermissionsErrors( $action, $this->user
, true ) );
339 $this->assertEquals( $check[$action][1],
340 $this->title
->getUserPermissionsErrors( $action, $this->user
, 'full' ) );
341 $this->assertEquals( $check[$action][1],
342 $this->title
->getUserPermissionsErrors( $action, $this->user
, 'secure' ) );
343 $wgGroupPermissions = $old;
345 $this->setUserPerm( $action );
346 $this->assertEquals( $check[$action][2],
347 $this->title
->getUserPermissionsErrors( $action, $this->user
, true ) );
348 $this->assertEquals( $check[$action][2],
349 $this->title
->getUserPermissionsErrors( $action, $this->user
, 'full' ) );
350 $this->assertEquals( $check[$action][2],
351 $this->title
->getUserPermissionsErrors( $action, $this->user
, 'secure' ) );
353 $this->setUserPerm( $action );
354 $this->assertEquals( $check[$action][3],
355 $this->title
->userCan( $action, $this->user
, true ) );
356 $this->assertEquals( $check[$action][3],
357 $this->title
->quickUserCan( $action, $this->user
) );
358 # count( User::getGroupsWithPermissions( $action ) ) < 1
362 protected function runGroupPermissions( $action, $result, $result2 = null ) {
363 global $wgGroupPermissions;
365 if ( $result2 === null ) {
369 $wgGroupPermissions['autoconfirmed']['move'] = false;
370 $wgGroupPermissions['user']['move'] = false;
371 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
372 $this->assertEquals( $result, $res );
374 $wgGroupPermissions['autoconfirmed']['move'] = true;
375 $wgGroupPermissions['user']['move'] = false;
376 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
377 $this->assertEquals( $result2, $res );
379 $wgGroupPermissions['autoconfirmed']['move'] = true;
380 $wgGroupPermissions['user']['move'] = true;
381 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
382 $this->assertEquals( $result2, $res );
384 $wgGroupPermissions['autoconfirmed']['move'] = false;
385 $wgGroupPermissions['user']['move'] = true;
386 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
387 $this->assertEquals( $result2, $res );
391 * @todo This test method should be split up into separate test methods and
394 public function testSpecialsAndNSPermissions() {
395 global $wgNamespaceProtection;
396 $this->setUser( $this->userName
);
398 $this->setTitle( NS_SPECIAL
);
400 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'ns-specialprotected' ) ),
401 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
403 $this->setTitle( NS_MAIN
);
404 $this->setUserPerm( 'bogus' );
405 $this->assertEquals( array(),
406 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
408 $this->setTitle( NS_MAIN
);
409 $this->setUserPerm( '' );
410 $this->assertEquals( array( array( 'badaccess-group0' ) ),
411 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
413 $wgNamespaceProtection[NS_USER
] = array( 'bogus' );
415 $this->setTitle( NS_USER
);
416 $this->setUserPerm( '' );
417 $this->assertEquals( array( array( 'badaccess-group0' ),
418 array( 'namespaceprotected', 'User', 'bogus' ) ),
419 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
421 $this->setTitle( NS_MEDIAWIKI
);
422 $this->setUserPerm( 'bogus' );
423 $this->assertEquals( array( array( 'protectedinterface', 'bogus' ) ),
424 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
426 $this->setTitle( NS_MEDIAWIKI
);
427 $this->setUserPerm( 'bogus' );
428 $this->assertEquals( array( array( 'protectedinterface', 'bogus' ) ),
429 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
431 $wgNamespaceProtection = null;
433 $this->setUserPerm( 'bogus' );
434 $this->assertEquals( array(),
435 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
436 $this->assertEquals( true,
437 $this->title
->userCan( 'bogus', $this->user
) );
439 $this->setUserPerm( '' );
440 $this->assertEquals( array( array( 'badaccess-group0' ) ),
441 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
442 $this->assertEquals( false,
443 $this->title
->userCan( 'bogus', $this->user
) );
447 * @todo This test method should be split up into separate test methods and
450 public function testCssAndJavascriptPermissions() {
451 $this->setUser( $this->userName
);
453 $this->setTitle( NS_USER
, $this->userName
. '/test.js' );
454 $this->runCSSandJSPermissions(
455 array( array( 'badaccess-group0' ), array( 'mycustomjsprotected', 'bogus' ) ),
456 array( array( 'badaccess-group0' ), array( 'mycustomjsprotected', 'bogus' ) ),
457 array( array( 'badaccess-group0' ) ),
458 array( array( 'badaccess-group0' ), array( 'mycustomjsprotected', 'bogus' ) ),
459 array( array( 'badaccess-group0' ) )
462 $this->setTitle( NS_USER
, $this->userName
. '/test.css' );
463 $this->runCSSandJSPermissions(
464 array( array( 'badaccess-group0' ), array( 'mycustomcssprotected', 'bogus' ) ),
465 array( array( 'badaccess-group0' ) ),
466 array( array( 'badaccess-group0' ), array( 'mycustomcssprotected', 'bogus' ) ),
467 array( array( 'badaccess-group0' ) ),
468 array( array( 'badaccess-group0' ), array( 'mycustomcssprotected', 'bogus' ) )
471 $this->setTitle( NS_USER
, $this->altUserName
. '/test.js' );
472 $this->runCSSandJSPermissions(
473 array( array( 'badaccess-group0' ), array( 'customjsprotected', 'bogus' ) ),
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' ) )
480 $this->setTitle( NS_USER
, $this->altUserName
. '/test.css' );
481 $this->runCSSandJSPermissions(
482 array( array( 'badaccess-group0' ), array( 'customcssprotected', 'bogus' ) ),
483 array( array( 'badaccess-group0' ), array( 'customcssprotected', 'bogus' ) ),
484 array( array( 'badaccess-group0' ), array( 'customcssprotected', 'bogus' ) ),
485 array( array( 'badaccess-group0' ) ),
486 array( array( 'badaccess-group0' ), array( 'customcssprotected', 'bogus' ) )
489 $this->setTitle( NS_USER
, $this->altUserName
. '/tempo' );
490 $this->runCSSandJSPermissions(
491 array( array( 'badaccess-group0' ) ),
492 array( array( 'badaccess-group0' ) ),
493 array( array( 'badaccess-group0' ) ),
494 array( array( 'badaccess-group0' ) ),
495 array( array( 'badaccess-group0' ) )
499 protected function runCSSandJSPermissions( $result0, $result1, $result2, $result3, $result4 ) {
500 $this->setUserPerm( '' );
501 $this->assertEquals( $result0,
502 $this->title
->getUserPermissionsErrors( 'bogus',
505 $this->setUserPerm( 'editmyusercss' );
506 $this->assertEquals( $result1,
507 $this->title
->getUserPermissionsErrors( 'bogus',
510 $this->setUserPerm( 'editmyuserjs' );
511 $this->assertEquals( $result2,
512 $this->title
->getUserPermissionsErrors( 'bogus',
515 $this->setUserPerm( 'editusercss' );
516 $this->assertEquals( $result3,
517 $this->title
->getUserPermissionsErrors( 'bogus',
520 $this->setUserPerm( 'edituserjs' );
521 $this->assertEquals( $result4,
522 $this->title
->getUserPermissionsErrors( 'bogus',
525 $this->setUserPerm( 'editusercssjs' );
526 $this->assertEquals( array( array( 'badaccess-group0' ) ),
527 $this->title
->getUserPermissionsErrors( 'bogus',
530 $this->setUserPerm( array( 'edituserjs', 'editusercss' ) );
531 $this->assertEquals( array( array( 'badaccess-group0' ) ),
532 $this->title
->getUserPermissionsErrors( 'bogus',
537 * @todo This test method should be split up into separate test methods and
540 public function testPageRestrictions() {
543 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT
);
545 $this->setTitle( NS_MAIN
);
546 $this->title
->mRestrictionsLoaded
= true;
547 $this->setUserPerm( "edit" );
548 $this->title
->mRestrictions
= array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
550 $this->assertEquals( array(),
551 $this->title
->getUserPermissionsErrors( 'edit',
554 $this->assertEquals( true,
555 $this->title
->quickUserCan( 'edit', $this->user
) );
556 $this->title
->mRestrictions
= array( "edit" => array( 'bogus', "sysop", "protect", "" ),
557 "bogus" => array( 'bogus', "sysop", "protect", "" ) );
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( 'protectedpagetext', 'bogus', 'edit' ),
566 array( 'protectedpagetext', 'editprotected', 'edit' ),
567 array( 'protectedpagetext', 'protect', 'edit' ) ),
568 $this->title
->getUserPermissionsErrors( 'edit',
570 $this->setUserPerm( "" );
571 $this->assertEquals( array( array( 'badaccess-group0' ),
572 array( 'protectedpagetext', 'bogus', 'bogus' ),
573 array( 'protectedpagetext', 'editprotected', 'bogus' ),
574 array( 'protectedpagetext', 'protect', 'bogus' ) ),
575 $this->title
->getUserPermissionsErrors( 'bogus',
577 $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ),
578 array( 'protectedpagetext', 'bogus', 'edit' ),
579 array( 'protectedpagetext', 'editprotected', 'edit' ),
580 array( 'protectedpagetext', 'protect', 'edit' ) ),
581 $this->title
->getUserPermissionsErrors( 'edit',
583 $this->setUserPerm( array( "edit", "editprotected" ) );
584 $this->assertEquals( array( array( 'badaccess-group0' ),
585 array( 'protectedpagetext', 'bogus', 'bogus' ),
586 array( 'protectedpagetext', 'protect', 'bogus' ) ),
587 $this->title
->getUserPermissionsErrors( 'bogus',
589 $this->assertEquals( array(
590 array( 'protectedpagetext', 'bogus', 'edit' ),
591 array( 'protectedpagetext', 'protect', 'edit' ) ),
592 $this->title
->getUserPermissionsErrors( 'edit',
595 $this->title
->mCascadeRestriction
= true;
596 $this->setUserPerm( "edit" );
597 $this->assertEquals( false,
598 $this->title
->quickUserCan( 'bogus', $this->user
) );
599 $this->assertEquals( false,
600 $this->title
->quickUserCan( 'edit', $this->user
) );
601 $this->assertEquals( array( array( 'badaccess-group0' ),
602 array( 'protectedpagetext', 'bogus', 'bogus' ),
603 array( 'protectedpagetext', 'editprotected', 'bogus' ),
604 array( 'protectedpagetext', 'protect', 'bogus' ) ),
605 $this->title
->getUserPermissionsErrors( 'bogus',
607 $this->assertEquals( array( array( 'protectedpagetext', 'bogus', 'edit' ),
608 array( 'protectedpagetext', 'editprotected', 'edit' ),
609 array( 'protectedpagetext', 'protect', 'edit' ) ),
610 $this->title
->getUserPermissionsErrors( 'edit',
613 $this->setUserPerm( array( "edit", "editprotected" ) );
614 $this->assertEquals( false,
615 $this->title
->quickUserCan( 'bogus', $this->user
) );
616 $this->assertEquals( false,
617 $this->title
->quickUserCan( 'edit', $this->user
) );
618 $this->assertEquals( array( array( 'badaccess-group0' ),
619 array( 'protectedpagetext', 'bogus', 'bogus' ),
620 array( 'protectedpagetext', 'protect', 'bogus' ),
621 array( 'protectedpagetext', 'protect', 'bogus' ) ),
622 $this->title
->getUserPermissionsErrors( 'bogus',
624 $this->assertEquals( array( array( 'protectedpagetext', 'bogus', 'edit' ),
625 array( 'protectedpagetext', 'protect', 'edit' ),
626 array( 'protectedpagetext', 'protect', 'edit' ) ),
627 $this->title
->getUserPermissionsErrors( 'edit',
631 public function testCascadingSourcesRestrictions() {
632 $this->setTitle( NS_MAIN
, "test page" );
633 $this->setUserPerm( array( "edit", "bogus" ) );
635 $this->title
->mCascadeSources
= array(
636 Title
::makeTitle( NS_MAIN
, "Bogus" ),
637 Title
::makeTitle( NS_MAIN
, "UnBogus" )
639 $this->title
->mCascadingRestrictions
= array(
640 "bogus" => array( 'bogus', "sysop", "protect", "" )
643 $this->assertEquals( false,
644 $this->title
->userCan( 'bogus', $this->user
) );
645 $this->assertEquals( array(
646 array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n", 'bogus' ),
647 array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n", 'bogus' ),
648 array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n", 'bogus' ) ),
649 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
651 $this->assertEquals( true,
652 $this->title
->userCan( 'edit', $this->user
) );
653 $this->assertEquals( array(),
654 $this->title
->getUserPermissionsErrors( 'edit', $this->user
) );
658 * @todo This test method should be split up into separate test methods and
661 public function testActionPermissions() {
662 $this->setUserPerm( array( "createpage" ) );
663 $this->setTitle( NS_MAIN
, "test page" );
664 $this->title
->mTitleProtection
['permission'] = '';
665 $this->title
->mTitleProtection
['user'] = $this->user
->getID();
666 $this->title
->mTitleProtection
['expiry'] = 'infinity';
667 $this->title
->mTitleProtection
['reason'] = 'test';
668 $this->title
->mCascadeRestriction
= false;
670 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
671 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
672 $this->assertEquals( false,
673 $this->title
->userCan( 'create', $this->user
) );
675 $this->title
->mTitleProtection
['permission'] = 'editprotected';
676 $this->setUserPerm( array( 'createpage', 'protect' ) );
677 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
678 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
679 $this->assertEquals( false,
680 $this->title
->userCan( 'create', $this->user
) );
682 $this->setUserPerm( array( 'createpage', 'editprotected' ) );
683 $this->assertEquals( array(),
684 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
685 $this->assertEquals( true,
686 $this->title
->userCan( 'create', $this->user
) );
688 $this->setUserPerm( array( 'createpage' ) );
689 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
690 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
691 $this->assertEquals( false,
692 $this->title
->userCan( 'create', $this->user
) );
694 $this->setTitle( NS_MEDIA
, "test page" );
695 $this->setUserPerm( array( "move" ) );
696 $this->assertEquals( false,
697 $this->title
->userCan( 'move', $this->user
) );
698 $this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ),
699 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
701 $this->setTitle( NS_HELP
, "test page" );
702 $this->assertEquals( array(),
703 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
704 $this->assertEquals( true,
705 $this->title
->userCan( 'move', $this->user
) );
707 $this->title
->mInterwiki
= "no";
708 $this->assertEquals( array( array( 'immobile-source-page' ) ),
709 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
710 $this->assertEquals( false,
711 $this->title
->userCan( 'move', $this->user
) );
713 $this->setTitle( NS_MEDIA
, "test page" );
714 $this->assertEquals( false,
715 $this->title
->userCan( 'move-target', $this->user
) );
716 $this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ),
717 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
719 $this->setTitle( NS_HELP
, "test page" );
720 $this->assertEquals( array(),
721 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
722 $this->assertEquals( true,
723 $this->title
->userCan( 'move-target', $this->user
) );
725 $this->title
->mInterwiki
= "no";
726 $this->assertEquals( array( array( 'immobile-target-page' ) ),
727 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
728 $this->assertEquals( false,
729 $this->title
->userCan( 'move-target', $this->user
) );
732 public function testUserBlock() {
733 global $wgEmailConfirmToEdit, $wgEmailAuthentication;
734 $wgEmailConfirmToEdit = true;
735 $wgEmailAuthentication = true;
737 $this->setUserPerm( array( "createpage", "move" ) );
738 $this->setTitle( NS_HELP
, "test page" );
741 $this->assertEquals( array( array( 'confirmedittext' ) ),
742 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
743 $wgEmailConfirmToEdit = false;
744 $this->assertEquals( true, $this->title
->userCan( 'move-target', $this->user
) );
746 # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
747 $this->assertEquals( array(),
748 $this->title
->getUserPermissionsErrors( 'move-target',
754 $this->user
->mBlockedby
= $this->user
->getId();
755 $this->user
->mBlock
= new Block( array(
756 'address' => '127.0.8.1',
757 'by' => $this->user
->getId(),
758 'reason' => 'no reason given',
759 'timestamp' => $prev +
3600,
763 $this->user
->mBlock
->mTimestamp
= 0;
764 $this->assertEquals( array( array( 'autoblockedtext',
765 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
766 'Useruser', null, 'infinite', '127.0.8.1',
767 $wgLang->timeanddate( wfTimestamp( TS_MW
, $prev ), true ) ) ),
768 $this->title
->getUserPermissionsErrors( 'move-target',
771 $this->assertEquals( false, $this->title
->userCan( 'move-target', $this->user
) );
772 // quickUserCan should ignore user blocks
773 $this->assertEquals( true, $this->title
->quickUserCan( 'move-target', $this->user
) );
775 global $wgLocalTZoffset;
776 $wgLocalTZoffset = -60;
777 $this->user
->mBlockedby
= $this->user
->getName();
778 $this->user
->mBlock
= new Block( array(
779 'address' => '127.0.8.1',
780 'by' => $this->user
->getId(),
781 'reason' => 'no reason given',
786 $this->assertEquals( array( array( 'blockedtext',
787 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
788 'Useruser', null, '23:00, 31 December 1969', '127.0.8.1',
789 $wgLang->timeanddate( wfTimestamp( TS_MW
, $now ), true ) ) ),
790 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
791 # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
792 # $user->blockedFor() == ''
793 # $user->mBlock->mExpiry == 'infinity'