7 class TitlePermissionTest
extends PHPUnit_Framework_TestCase
{
17 global $wgLocaltimezone, $wgLocalTZoffset, $wgMemc, $wgContLang, $wgLang, $wgMessageCache;
20 $wgMemc = new FakeMemCachedClient
;
22 $wgMessageCache = new MessageCache( $wgMemc, true, 3600 );
23 $wgContLang = $wgLang = Language
::factory( 'en' );
25 self
::$userName = "Useruser";
26 self
::$altUserName = "Altuseruser";
27 date_default_timezone_set( $wgLocaltimezone );
28 $wgLocalTZoffset = date( "Z" ) / 60;
30 self
::$title = Title
::makeTitle( NS_MAIN
, "Main Page" );
31 if ( !isset( self
::$userUser ) ||
!( self
::$userUser instanceOf User
) ) {
32 self
::$userUser = User
::newFromName( self
::$userName );
34 if ( !self
::$userUser->getID() ) {
35 self
::$userUser = User
::createNew( self
::$userName, array(
36 "email" => "test@example.com",
37 "real_name" => "Test User" ) );
40 self
::$altUser = User
::newFromName( self
::$altUserName );
41 if ( !self
::$altUser->getID() ) {
42 self
::$altUser = User
::createNew( self
::$altUserName, array(
43 "email" => "alttest@example.com",
44 "real_name" => "Test User Alt" ) );
47 self
::$anonUser = User
::newFromId( 0 );
49 self
::$user = self
::$userUser;
53 function setUserPerm( $perm ) {
54 if ( is_array( $perm ) ) {
55 self
::$user->mRights
= $perm;
57 self
::$user->mRights
= array( $perm );
61 function setTitle( $ns, $title = "Main_Page" ) {
62 self
::$title = Title
::makeTitle( $ns, $title );
65 function setUser( $userName = null ) {
66 if ( $userName === 'anon' ) {
67 self
::$user = self
::$anonUser;
68 } else if ( $userName === null ||
$userName === self
::$userName ) {
69 self
::$user = self
::$userUser;
71 self
::$user = self
::$altUser;
75 $wgUser = self
::$user;
78 function testQuickPermissions() {
80 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT
);
82 $this->setUser( 'anon' );
83 $this->setTitle( NS_TALK
);
84 $this->setUserPerm( "createtalk" );
85 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
86 $this->assertEquals( array(), $res );
88 $this->setTitle( NS_TALK
);
89 $this->setUserPerm( "createpage" );
90 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
91 $this->assertEquals( array( array( "nocreatetext" ) ), $res );
93 $this->setTitle( NS_TALK
);
94 $this->setUserPerm( "" );
95 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
96 $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
98 $this->setTitle( NS_MAIN
);
99 $this->setUserPerm( "createpage" );
100 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
101 $this->assertEquals( array( ), $res );
103 $this->setTitle( NS_MAIN
);
104 $this->setUserPerm( "createtalk" );
105 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
106 $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
108 $this->setUser( self
::$userName );
109 $this->setTitle( NS_TALK
);
110 $this->setUserPerm( "createtalk" );
111 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
112 $this->assertEquals( array( ), $res );
114 $this->setTitle( NS_TALK
);
115 $this->setUserPerm( "createpage" );
116 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
117 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
119 $this->setTitle( NS_TALK
);
120 $this->setUserPerm( "" );
121 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
122 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
124 $this->setTitle( NS_MAIN
);
125 $this->setUserPerm( "createpage" );
126 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
127 $this->assertEquals( array( ), $res );
129 $this->setTitle( NS_MAIN
);
130 $this->setUserPerm( "createtalk" );
131 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
132 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
134 $this->setTitle( NS_MAIN
);
135 $this->setUserPerm( "" );
136 $res = self
::$title->getUserPermissionsErrors( 'create', self
::$user );
137 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
139 $this->setUser( 'anon' );
140 $this->setTitle( NS_USER
, self
::$userName . '' );
141 $this->setUserPerm( "" );
142 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
143 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
145 $this->setTitle( NS_USER
, self
::$userName . '/subpage' );
146 $this->setUserPerm( "" );
147 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
148 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
150 $this->setTitle( NS_USER
, self
::$userName . '' );
151 $this->setUserPerm( "move-rootuserpages" );
152 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
153 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
155 $this->setTitle( NS_USER
, self
::$userName . '/subpage' );
156 $this->setUserPerm( "move-rootuserpages" );
157 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
158 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
160 $this->setTitle( NS_USER
, self
::$userName . '' );
161 $this->setUserPerm( "" );
162 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
163 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
165 $this->setTitle( NS_USER
, self
::$userName . '/subpage' );
166 $this->setUserPerm( "" );
167 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
168 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
170 $this->setTitle( NS_USER
, self
::$userName . '' );
171 $this->setUserPerm( "move-rootuserpages" );
172 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
173 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
175 $this->setTitle( NS_USER
, self
::$userName . '/subpage' );
176 $this->setUserPerm( "move-rootuserpages" );
177 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
178 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
180 $this->setUser( self
::$userName );
181 $this->setTitle( NS_FILE
, "img.png" );
182 $this->setUserPerm( "" );
183 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
184 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ), $res );
186 $this->setTitle( NS_FILE
, "img.png" );
187 $this->setUserPerm( "movefile" );
188 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
189 $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
191 $this->setUser( 'anon' );
192 $this->setTitle( NS_FILE
, "img.png" );
193 $this->setUserPerm( "" );
194 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
195 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ), $res );
197 $this->setTitle( NS_FILE
, "img.png" );
198 $this->setUserPerm( "movefile" );
199 $res = self
::$title->getUserPermissionsErrors( 'move', self
::$user );
200 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
202 $this->setUser( self
::$userName );
203 $this->setUserPerm( "move" );
204 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
206 $this->setUserPerm( "" );
207 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ) );
209 $this->setUser( 'anon' );
210 $this->setUserPerm( "move" );
211 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
213 $this->setUserPerm( "" );
214 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ),
215 array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ) );
217 $this->setTitle( NS_MAIN
);
218 $this->setUser( 'anon' );
219 $this->setUserPerm( "move" );
220 $this->runGroupPermissions( 'move', array( ) );
222 $this->setUserPerm( "" );
223 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ),
224 array( array( 'movenologintext' ) ) );
226 $this->setUser( self
::$userName );
227 $this->setUserPerm( "" );
228 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ) );
230 $this->setUserPerm( "move" );
231 $this->runGroupPermissions( 'move', array( ) );
233 $this->setUser( 'anon' );
234 $this->setUserPerm( 'move' );
235 $res = self
::$title->getUserPermissionsErrors( 'move-target', self
::$user );
236 $this->assertEquals( array( ), $res );
238 $this->setUserPerm( '' );
239 $res = self
::$title->getUserPermissionsErrors( 'move-target', self
::$user );
240 $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
242 $this->setTitle( NS_USER
);
243 $this->setUser( self
::$userName );
244 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
245 $res = self
::$title->getUserPermissionsErrors( 'move-target', self
::$user );
246 $this->assertEquals( array( ), $res );
248 $this->setUserPerm( "move" );
249 $res = self
::$title->getUserPermissionsErrors( 'move-target', self
::$user );
250 $this->assertEquals( array( array( 'cant-move-to-user-page' ) ), $res );
252 $this->setUser( 'anon' );
253 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
254 $res = self
::$title->getUserPermissionsErrors( 'move-target', self
::$user );
255 $this->assertEquals( array( ), $res );
257 $this->setTitle( NS_USER
, "User/subpage" );
258 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
259 $res = self
::$title->getUserPermissionsErrors( 'move-target', self
::$user );
260 $this->assertEquals( array( ), $res );
262 $this->setUserPerm( "move" );
263 $res = self
::$title->getUserPermissionsErrors( 'move-target', self
::$user );
264 $this->assertEquals( array( ), $res );
266 $this->setUser( 'anon' );
267 $check = array( 'edit' => array( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ) ),
268 array( array( 'badaccess-group0' ) ),
270 'protect' => array( array( array( 'badaccess-groups', "[[$prefix:Administrators|Administrators]]", 1 ), array( 'protect-cantedit' ) ),
271 array( array( 'badaccess-group0' ), array( 'protect-cantedit' ) ),
272 array( array( 'protect-cantedit' ) ), false ),
273 '' => array( array( ), array( ), array( ), true ) );
275 $wgUser = self
::$user;
276 foreach ( array( "edit", "protect", "" ) as $action ) {
277 $this->setUserPerm( null );
278 $this->assertEquals( $check[$action][0],
279 self
::$title->getUserPermissionsErrors( $action, self
::$user, true ) );
281 global $wgGroupPermissions;
282 $old = $wgGroupPermissions;
283 $wgGroupPermissions = array();
285 $this->assertEquals( $check[$action][1],
286 self
::$title->getUserPermissionsErrors( $action, self
::$user, true ) );
287 $wgGroupPermissions = $old;
289 $this->setUserPerm( $action );
290 $this->assertEquals( $check[$action][2],
291 self
::$title->getUserPermissionsErrors( $action, self
::$user, true ) );
293 $this->setUserPerm( $action );
294 $this->assertEquals( $check[$action][3],
295 self
::$title->userCan( $action, true ) );
296 $this->assertEquals( $check[$action][3],
297 self
::$title->quickUserCan( $action, false ) );
299 # count( User::getGroupsWithPermissions( $action ) ) < 1
303 function runGroupPermissions( $action, $result, $result2 = null ) {
304 global $wgGroupPermissions;
306 if ( $result2 === null ) $result2 = $result;
308 $wgGroupPermissions['autoconfirmed']['move'] = false;
309 $wgGroupPermissions['user']['move'] = false;
310 $res = self
::$title->getUserPermissionsErrors( $action, self
::$user );
311 $this->assertEquals( $result, $res );
313 $wgGroupPermissions['autoconfirmed']['move'] = true;
314 $wgGroupPermissions['user']['move'] = false;
315 $res = self
::$title->getUserPermissionsErrors( $action, self
::$user );
316 $this->assertEquals( $result2, $res );
318 $wgGroupPermissions['autoconfirmed']['move'] = true;
319 $wgGroupPermissions['user']['move'] = true;
320 $res = self
::$title->getUserPermissionsErrors( $action, self
::$user );
321 $this->assertEquals( $result2, $res );
323 $wgGroupPermissions['autoconfirmed']['move'] = false;
324 $wgGroupPermissions['user']['move'] = true;
325 $res = self
::$title->getUserPermissionsErrors( $action, self
::$user );
326 $this->assertEquals( $result2, $res );
329 function testPermissionHooks() { }
330 function testSpecialsAndNSPermissions() {
331 $this->setUser( self
::$userName );
332 global $wgUser, $wgContLang;
333 $wgUser = self
::$user;
334 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT
);
336 $this->setTitle( NS_SPECIAL
);
338 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'ns-specialprotected' ) ),
339 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
340 $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Administrators|Administrators]]", 2 ) ),
341 self
::$title->getUserPermissionsErrors( 'createaccount', self
::$user ) );
342 $this->assertEquals( array( array( 'badaccess-group0' ) ),
343 self
::$title->getUserPermissionsErrors( 'execute', self
::$user ) );
345 $this->setTitle( NS_MAIN
);
346 $this->setUserPerm( 'bogus' );
347 $this->assertEquals( array( ),
348 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
350 $this->setTitle( NS_MAIN
);
351 $this->setUserPerm( '' );
352 $this->assertEquals( array( array( 'badaccess-group0' ) ),
353 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
355 global $wgNamespaceProtection;
356 $wgNamespaceProtection[NS_USER
] = array ( 'bogus' );
357 $this->setTitle( NS_USER
);
358 $this->setUserPerm( '' );
359 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'namespaceprotected', 'User' ) ),
360 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
362 $this->setTitle( NS_MEDIAWIKI
);
363 $this->setUserPerm( 'bogus' );
364 $this->assertEquals( array( array( 'protectedinterface' ) ),
365 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
367 $this->setTitle( NS_MEDIAWIKI
);
368 $this->setUserPerm( 'bogus' );
369 $this->assertEquals( array( array( 'protectedinterface' ) ),
370 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
372 $wgNamespaceProtection = null;
373 $this->setUserPerm( 'bogus' );
374 $this->assertEquals( array( ),
375 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
376 $this->assertEquals( true,
377 self
::$title->userCan( 'bogus' ) );
379 $this->setUserPerm( '' );
380 $this->assertEquals( array( array( 'badaccess-group0' ) ),
381 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
382 $this->assertEquals( false,
383 self
::$title->userCan( 'bogus' ) );
386 function testCSSandJSPermissions() {
387 $this->setUser( self
::$userName );
389 $wgUser = self
::$user;
391 $this->setTitle( NS_USER
, self
::$altUserName . '/test.js' );
392 $this->runCSSandJSPermissions(
393 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
394 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
395 array( array( 'badaccess-group0' ) ) );
397 $this->setTitle( NS_USER
, self
::$altUserName . '/test.css' );
398 $this->runCSSandJSPermissions(
399 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
400 array( array( 'badaccess-group0' ) ),
401 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ) );
403 $this->setTitle( NS_USER
, self
::$altUserName . '/tempo' );
404 $this->runCSSandJSPermissions(
405 array( array( 'badaccess-group0' ) ),
406 array( array( 'badaccess-group0' ) ),
407 array( array( 'badaccess-group0' ) ) );
410 function runCSSandJSPermissions( $result0, $result1, $result2 ) {
411 $this->setUserPerm( '' );
412 $this->assertEquals( $result0,
413 self
::$title->getUserPermissionsErrors( 'bogus',
416 $this->setUserPerm( 'editusercss' );
417 $this->assertEquals( $result1,
418 self
::$title->getUserPermissionsErrors( 'bogus',
421 $this->setUserPerm( 'edituserjs' );
422 $this->assertEquals( $result2,
423 self
::$title->getUserPermissionsErrors( 'bogus',
426 $this->setUserPerm( 'editusercssjs' );
427 $this->assertEquals( array( array( 'badaccess-group0' ) ),
428 self
::$title->getUserPermissionsErrors( 'bogus',
431 $this->setUserPerm( array( 'edituserjs', 'editusercss' ) );
432 $this->assertEquals( array( array( 'badaccess-group0' ) ),
433 self
::$title->getUserPermissionsErrors( 'bogus',
437 function testPageRestrictions() {
438 global $wgUser, $wgContLang;
440 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT
);
442 $wgUser = self
::$user;
443 $this->setTitle( NS_MAIN
);
444 self
::$title->mRestrictionsLoaded
= true;
445 $this->setUserPerm( "edit" );
446 self
::$title->mRestrictions
= array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
448 $this->assertEquals( array( ),
449 self
::$title->getUserPermissionsErrors( 'edit',
452 $this->assertEquals( true,
453 self
::$title->quickUserCan( 'edit', false ) );
454 self
::$title->mRestrictions
= array( "edit" => array( 'bogus', "sysop", "protect", "" ),
455 "bogus" => array( 'bogus', "sysop", "protect", "" ) );
457 $this->assertEquals( array( array( 'badaccess-group0' ),
458 array( 'protectedpagetext', 'bogus' ),
459 array( 'protectedpagetext', 'protect' ),
460 array( 'protectedpagetext', 'protect' ) ),
461 self
::$title->getUserPermissionsErrors( 'bogus',
463 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
464 array( 'protectedpagetext', 'protect' ),
465 array( 'protectedpagetext', 'protect' ) ),
466 self
::$title->getUserPermissionsErrors( 'edit',
468 $this->setUserPerm( "" );
469 $this->assertEquals( array( array( 'badaccess-group0' ),
470 array( 'protectedpagetext', 'bogus' ),
471 array( 'protectedpagetext', 'protect' ),
472 array( 'protectedpagetext', 'protect' ) ),
473 self
::$title->getUserPermissionsErrors( 'bogus',
475 $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ),
476 array( 'protectedpagetext', 'bogus' ),
477 array( 'protectedpagetext', 'protect' ),
478 array( 'protectedpagetext', 'protect' ) ),
479 self
::$title->getUserPermissionsErrors( 'edit',
481 $this->setUserPerm( array( "edit", "editprotected" ) );
482 $this->assertEquals( array( array( 'badaccess-group0' ),
483 array( 'protectedpagetext', 'bogus' ),
484 array( 'protectedpagetext', 'protect' ),
485 array( 'protectedpagetext', 'protect' ) ),
486 self
::$title->getUserPermissionsErrors( 'bogus',
488 $this->assertEquals( array( ),
489 self
::$title->getUserPermissionsErrors( 'edit',
491 self
::$title->mCascadeRestriction
= true;
492 $this->assertEquals( false,
493 self
::$title->quickUserCan( 'bogus', false ) );
494 $this->assertEquals( false,
495 self
::$title->quickUserCan( 'edit', false ) );
496 $this->assertEquals( array( array( 'badaccess-group0' ),
497 array( 'protectedpagetext', 'bogus' ),
498 array( 'protectedpagetext', 'protect' ),
499 array( 'protectedpagetext', 'protect' ) ),
500 self
::$title->getUserPermissionsErrors( 'bogus',
502 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
503 array( 'protectedpagetext', 'protect' ),
504 array( 'protectedpagetext', 'protect' ) ),
505 self
::$title->getUserPermissionsErrors( 'edit',
509 function testCascadingSourcesRestrictions() {
511 $wgUser = self
::$user;
512 $this->setTitle( NS_MAIN
, "test page" );
513 $this->setUserPerm( array( "edit", "bogus" ) );
515 self
::$title->mCascadeSources
= array( Title
::makeTitle( NS_MAIN
, "Bogus" ), Title
::makeTitle( NS_MAIN
, "UnBogus" ) );
516 self
::$title->mCascadingRestrictions
= array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
518 $this->assertEquals( false,
519 self
::$title->userCan( 'bogus' ) );
520 $this->assertEquals( array( array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ),
521 array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ) ),
522 self
::$title->getUserPermissionsErrors( 'bogus', self
::$user ) );
524 $this->assertEquals( true,
525 self
::$title->userCan( 'edit' ) );
526 $this->assertEquals( array( ),
527 self
::$title->getUserPermissionsErrors( 'edit', self
::$user ) );
531 function testActionPermissions() {
533 $wgUser = self
::$user;
535 $this->setUserPerm( array( "createpage" ) );
536 $this->setTitle( NS_MAIN
, "test page" );
537 self
::$title->mTitleProtection
['pt_create_perm'] = '';
538 self
::$title->mTitleProtection
['pt_user'] = self
::$user->getID();
539 self
::$title->mTitleProtection
['pt_expiry'] = Block
::infinity();
540 self
::$title->mTitleProtection
['pt_reason'] = 'test';
541 self
::$title->mCascadeRestriction
= false;
543 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
544 self
::$title->getUserPermissionsErrors( 'create', self
::$user ) );
545 $this->assertEquals( false,
546 self
::$title->userCan( 'create' ) );
548 self
::$title->mTitleProtection
['pt_create_perm'] = 'sysop';
549 $this->setUserPerm( array( 'createpage', 'protect' ) );
550 $this->assertEquals( array( ),
551 self
::$title->getUserPermissionsErrors( 'create', self
::$user ) );
552 $this->assertEquals( true,
553 self
::$title->userCan( 'create' ) );
556 $this->setUserPerm( array( 'createpage' ) );
557 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
558 self
::$title->getUserPermissionsErrors( 'create', self
::$user ) );
559 $this->assertEquals( false,
560 self
::$title->userCan( 'create' ) );
562 $this->setTitle( NS_MEDIA
, "test page" );
563 $this->setUserPerm( array( "move" ) );
564 $this->assertEquals( false,
565 self
::$title->userCan( 'move' ) );
566 $this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ),
567 self
::$title->getUserPermissionsErrors( 'move', self
::$user ) );
569 $this->setTitle( NS_MAIN
, "test page" );
570 $this->assertEquals( array( ),
571 self
::$title->getUserPermissionsErrors( 'move', self
::$user ) );
572 $this->assertEquals( true,
573 self
::$title->userCan( 'move' ) );
575 self
::$title->mInterwiki
= "no";
576 $this->assertEquals( array( array( 'immobile-page' ) ),
577 self
::$title->getUserPermissionsErrors( 'move', self
::$user ) );
578 $this->assertEquals( false,
579 self
::$title->userCan( 'move' ) );
581 $this->setTitle( NS_MEDIA
, "test page" );
582 $this->assertEquals( false,
583 self
::$title->userCan( 'move-target' ) );
584 $this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ),
585 self
::$title->getUserPermissionsErrors( 'move-target', self
::$user ) );
587 $this->setTitle( NS_MAIN
, "test page" );
588 $this->assertEquals( array( ),
589 self
::$title->getUserPermissionsErrors( 'move-target', self
::$user ) );
590 $this->assertEquals( true,
591 self
::$title->userCan( 'move-target' ) );
593 self
::$title->mInterwiki
= "no";
594 $this->assertEquals( array( array( 'immobile-target-page' ) ),
595 self
::$title->getUserPermissionsErrors( 'move-target', self
::$user ) );
596 $this->assertEquals( false,
597 self
::$title->userCan( 'move-target' ) );
601 function testUserBlock() {
602 global $wgUser, $wgEmailConfirmToEdit, $wgEmailAuthentication;
603 $wgEmailConfirmToEdit = true;
604 $wgEmailAuthentication = true;
605 $wgUser = self
::$user;
607 $this->setUserPerm( array( "createpage", "move" ) );
608 $this->setTitle( NS_MAIN
, "test page" );
611 $this->assertEquals( array( array( 'confirmedittext' ) ),
612 self
::$title->getUserPermissionsErrors( 'move-target', self
::$user ) );
613 $wgEmailConfirmToEdit = false;
614 $this->assertEquals( true, self
::$title->userCan( 'move-target' ) );
616 # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
617 $this->assertEquals( array( ),
618 self
::$title->getUserPermissionsErrors( 'move-target',
624 self
::$user->mBlockedby
= self
::$user->getId();
625 self
::$user->mBlock
= new Block( '127.0.8.1', self
::$user->getId(), self
::$user->getId(),
626 'no reason given', $prev +
3600, 1, 0 );
627 self
::$user->mBlock
->mTimestamp
= 0;
628 $this->assertEquals( array( array( 'autoblockedtext',
629 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
630 'Useruser', 0, 'infinite', '127.0.8.1',
631 $wgLang->timeanddate( wfTimestamp( TS_MW
, $prev ), true ) ) ),
632 self
::$title->getUserPermissionsErrors( 'move-target',
635 $this->assertEquals( false,
636 self
::$title->userCan( 'move-target', self
::$user ) );
638 global $wgLocalTZoffset;
639 $wgLocalTZoffset = -60;
640 self
::$user->mBlockedby
= self
::$user->getName();
641 self
::$user->mBlock
= new Block( '127.0.8.1', 2, 1, 'no reason given', $now, 0, 10 );
642 $this->assertEquals( array( array( 'blockedtext',
643 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
644 'Useruser', 0, '23:00, 31 December 1969', '127.0.8.1',
645 $wgLang->timeanddate( wfTimestamp( TS_MW
, $now ), true ) ) ),
646 self
::$title->getUserPermissionsErrors( 'move-target', self
::$user ) );
648 # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
649 # $user->blockedFor() == ''
650 # $user->mBlock->mExpiry == 'infinity'