315ecd26db7f092d4e3ea5d369dbbe910fc5c3ff
6 class TitlePermissionTest
extends MediaWikiTestCase
{
13 protected $altUserName;
16 global $wgLocaltimezone, $wgLocalTZoffset, $wgMemc, $wgContLang, $wgLang, $wgMessageCache;
19 $wgMemc = new FakeMemCachedClient
;
21 $wgMessageCache = new MessageCache( $wgMemc, true, 3600 );
22 $wgContLang = $wgLang = Language
::factory( 'en' );
24 $this->userName
= "Useruser";
25 $this->altUserName
= "Altuseruser";
26 date_default_timezone_set( $wgLocaltimezone );
27 $wgLocalTZoffset = date( "Z" ) / 60;
29 $this->title
= Title
::makeTitle( NS_MAIN
, "Main Page" );
30 if ( !isset( $this->userUser
) ||
!( $this->userUser
instanceOf User
) ) {
31 $this->userUser
= User
::newFromName( $this->userName
);
33 if ( !$this->userUser
->getID() ) {
34 $this->userUser
= User
::createNew( $this->userName
, array(
35 "email" => "test@example.com",
36 "real_name" => "Test User" ) );
37 $this->userUser
->load();
40 $this->altUser
= User
::newFromName( $this->altUserName
);
41 if ( !$this->altUser
->getID() ) {
42 $this->altUser
= User
::createNew( $this->altUserName
, array(
43 "email" => "alttest@example.com",
44 "real_name" => "Test User Alt" ) );
45 $this->altUser
->load();
48 $this->anonUser
= User
::newFromId( 0 );
50 $this->user
= $this->userUser
;
54 function setUserPerm( $perm ) {
55 if ( is_array( $perm ) ) {
56 $this->user
->mRights
= $perm;
58 $this->user
->mRights
= array( $perm );
62 function setTitle( $ns, $title = "Main_Page" ) {
63 $this->title
= Title
::makeTitle( $ns, $title );
66 function setUser( $userName = null ) {
67 if ( $userName === 'anon' ) {
68 $this->user
= $this->anonUser
;
69 } else if ( $userName === null ||
$userName === $this->userName
) {
70 $this->user
= $this->userUser
;
72 $this->user
= $this->altUser
;
76 $wgUser = $this->user
;
79 function testQuickPermissions() {
81 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT
);
83 $this->setUser( 'anon' );
84 $this->setTitle( NS_TALK
);
85 $this->setUserPerm( "createtalk" );
86 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
87 $this->assertEquals( array(), $res );
89 $this->setTitle( NS_TALK
);
90 $this->setUserPerm( "createpage" );
91 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
92 $this->assertEquals( array( array( "nocreatetext" ) ), $res );
94 $this->setTitle( NS_TALK
);
95 $this->setUserPerm( "" );
96 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
97 $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
99 $this->setTitle( NS_MAIN
);
100 $this->setUserPerm( "createpage" );
101 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
102 $this->assertEquals( array( ), $res );
104 $this->setTitle( NS_MAIN
);
105 $this->setUserPerm( "createtalk" );
106 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
107 $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
109 $this->setUser( $this->userName
);
110 $this->setTitle( NS_TALK
);
111 $this->setUserPerm( "createtalk" );
112 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
113 $this->assertEquals( array( ), $res );
115 $this->setTitle( NS_TALK
);
116 $this->setUserPerm( "createpage" );
117 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
118 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
120 $this->setTitle( NS_TALK
);
121 $this->setUserPerm( "" );
122 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
123 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
125 $this->setTitle( NS_MAIN
);
126 $this->setUserPerm( "createpage" );
127 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
128 $this->assertEquals( array( ), $res );
130 $this->setTitle( NS_MAIN
);
131 $this->setUserPerm( "createtalk" );
132 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
133 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
135 $this->setTitle( NS_MAIN
);
136 $this->setUserPerm( "" );
137 $res = $this->title
->getUserPermissionsErrors( 'create', $this->user
);
138 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
140 $this->setUser( 'anon' );
141 $this->setTitle( NS_USER
, $this->userName
. '' );
142 $this->setUserPerm( "" );
143 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
144 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
146 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
147 $this->setUserPerm( "" );
148 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
149 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
151 $this->setTitle( NS_USER
, $this->userName
. '' );
152 $this->setUserPerm( "move-rootuserpages" );
153 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
154 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
156 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
157 $this->setUserPerm( "move-rootuserpages" );
158 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
159 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
161 $this->setTitle( NS_USER
, $this->userName
. '' );
162 $this->setUserPerm( "" );
163 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
164 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
166 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
167 $this->setUserPerm( "" );
168 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
169 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
171 $this->setTitle( NS_USER
, $this->userName
. '' );
172 $this->setUserPerm( "move-rootuserpages" );
173 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
174 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
176 $this->setTitle( NS_USER
, $this->userName
. '/subpage' );
177 $this->setUserPerm( "move-rootuserpages" );
178 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
179 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
181 $this->setUser( $this->userName
);
182 $this->setTitle( NS_FILE
, "img.png" );
183 $this->setUserPerm( "" );
184 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
185 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ), $res );
187 $this->setTitle( NS_FILE
, "img.png" );
188 $this->setUserPerm( "movefile" );
189 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
190 $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
192 $this->setUser( 'anon' );
193 $this->setTitle( NS_FILE
, "img.png" );
194 $this->setUserPerm( "" );
195 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
196 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ), $res );
198 $this->setTitle( NS_FILE
, "img.png" );
199 $this->setUserPerm( "movefile" );
200 $res = $this->title
->getUserPermissionsErrors( 'move', $this->user
);
201 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
203 $this->setUser( $this->userName
);
204 $this->setUserPerm( "move" );
205 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
207 $this->setUserPerm( "" );
208 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ) );
210 $this->setUser( 'anon' );
211 $this->setUserPerm( "move" );
212 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
214 $this->setUserPerm( "" );
215 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ),
216 array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ) );
218 $this->setTitle( NS_MAIN
);
219 $this->setUser( 'anon' );
220 $this->setUserPerm( "move" );
221 $this->runGroupPermissions( 'move', array( ) );
223 $this->setUserPerm( "" );
224 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ),
225 array( array( 'movenologintext' ) ) );
227 $this->setUser( $this->userName
);
228 $this->setUserPerm( "" );
229 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ) );
231 $this->setUserPerm( "move" );
232 $this->runGroupPermissions( 'move', array( ) );
234 $this->setUser( 'anon' );
235 $this->setUserPerm( 'move' );
236 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
237 $this->assertEquals( array( ), $res );
239 $this->setUserPerm( '' );
240 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
241 $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
243 $this->setTitle( NS_USER
);
244 $this->setUser( $this->userName
);
245 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
246 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
247 $this->assertEquals( array( ), $res );
249 $this->setUserPerm( "move" );
250 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
251 $this->assertEquals( array( array( 'cant-move-to-user-page' ) ), $res );
253 $this->setUser( 'anon' );
254 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
255 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
256 $this->assertEquals( array( ), $res );
258 $this->setTitle( NS_USER
, "User/subpage" );
259 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
260 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
261 $this->assertEquals( array( ), $res );
263 $this->setUserPerm( "move" );
264 $res = $this->title
->getUserPermissionsErrors( 'move-target', $this->user
);
265 $this->assertEquals( array( ), $res );
267 $this->setUser( 'anon' );
268 $check = array( 'edit' => array( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ) ),
269 array( array( 'badaccess-group0' ) ),
271 'protect' => array( array( array( 'badaccess-groups', "[[$prefix:Administrators|Administrators]]", 1 ), array( 'protect-cantedit' ) ),
272 array( array( 'badaccess-group0' ), array( 'protect-cantedit' ) ),
273 array( array( 'protect-cantedit' ) ), false ),
274 '' => array( array( ), array( ), array( ), true ) );
276 $wgUser = $this->user
;
277 foreach ( array( "edit", "protect", "" ) as $action ) {
278 $this->setUserPerm( null );
279 $this->assertEquals( $check[$action][0],
280 $this->title
->getUserPermissionsErrors( $action, $this->user
, true ) );
282 global $wgGroupPermissions;
283 $old = $wgGroupPermissions;
284 $wgGroupPermissions = array();
286 $this->assertEquals( $check[$action][1],
287 $this->title
->getUserPermissionsErrors( $action, $this->user
, true ) );
288 $wgGroupPermissions = $old;
290 $this->setUserPerm( $action );
291 $this->assertEquals( $check[$action][2],
292 $this->title
->getUserPermissionsErrors( $action, $this->user
, true ) );
294 $this->setUserPerm( $action );
295 $this->assertEquals( $check[$action][3],
296 $this->title
->userCan( $action, true ) );
297 $this->assertEquals( $check[$action][3],
298 $this->title
->quickUserCan( $action, false ) );
300 # count( User::getGroupsWithPermissions( $action ) ) < 1
304 function runGroupPermissions( $action, $result, $result2 = null ) {
305 global $wgGroupPermissions;
307 if ( $result2 === null ) $result2 = $result;
309 $wgGroupPermissions['autoconfirmed']['move'] = false;
310 $wgGroupPermissions['user']['move'] = false;
311 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
312 $this->assertEquals( $result, $res );
314 $wgGroupPermissions['autoconfirmed']['move'] = true;
315 $wgGroupPermissions['user']['move'] = false;
316 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
317 $this->assertEquals( $result2, $res );
319 $wgGroupPermissions['autoconfirmed']['move'] = true;
320 $wgGroupPermissions['user']['move'] = true;
321 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
322 $this->assertEquals( $result2, $res );
324 $wgGroupPermissions['autoconfirmed']['move'] = false;
325 $wgGroupPermissions['user']['move'] = true;
326 $res = $this->title
->getUserPermissionsErrors( $action, $this->user
);
327 $this->assertEquals( $result2, $res );
330 function testPermissionHooks() { }
331 function testSpecialsAndNSPermissions() {
332 $this->setUser( $this->userName
);
333 global $wgUser, $wgContLang;
334 $wgUser = $this->user
;
335 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT
);
337 $this->setTitle( NS_SPECIAL
);
339 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'ns-specialprotected' ) ),
340 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
341 $this->assertEquals( array( array( 'badaccess-group0' ) ),
342 $this->title
->getUserPermissionsErrors( 'execute', $this->user
) );
344 $this->setTitle( NS_MAIN
);
345 $this->setUserPerm( 'bogus' );
346 $this->assertEquals( array( ),
347 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
349 $this->setTitle( NS_MAIN
);
350 $this->setUserPerm( '' );
351 $this->assertEquals( array( array( 'badaccess-group0' ) ),
352 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
354 global $wgNamespaceProtection;
355 $wgNamespaceProtection[NS_USER
] = array ( 'bogus' );
356 $this->setTitle( NS_USER
);
357 $this->setUserPerm( '' );
358 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'namespaceprotected', 'User' ) ),
359 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
361 $this->setTitle( NS_MEDIAWIKI
);
362 $this->setUserPerm( 'bogus' );
363 $this->assertEquals( array( array( 'protectedinterface' ) ),
364 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
366 $this->setTitle( NS_MEDIAWIKI
);
367 $this->setUserPerm( 'bogus' );
368 $this->assertEquals( array( array( 'protectedinterface' ) ),
369 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
371 $wgNamespaceProtection = null;
372 $this->setUserPerm( 'bogus' );
373 $this->assertEquals( array( ),
374 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
375 $this->assertEquals( true,
376 $this->title
->userCan( 'bogus' ) );
378 $this->setUserPerm( '' );
379 $this->assertEquals( array( array( 'badaccess-group0' ) ),
380 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
381 $this->assertEquals( false,
382 $this->title
->userCan( 'bogus' ) );
385 function testCSSandJSPermissions() {
386 $this->setUser( $this->userName
);
388 $wgUser = $this->user
;
390 $this->setTitle( NS_USER
, $this->altUserName
. '/test.js' );
391 $this->runCSSandJSPermissions(
392 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
393 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
394 array( array( 'badaccess-group0' ) ) );
396 $this->setTitle( NS_USER
, $this->altUserName
. '/test.css' );
397 $this->runCSSandJSPermissions(
398 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
399 array( array( 'badaccess-group0' ) ),
400 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ) );
402 $this->setTitle( NS_USER
, $this->altUserName
. '/tempo' );
403 $this->runCSSandJSPermissions(
404 array( array( 'badaccess-group0' ) ),
405 array( array( 'badaccess-group0' ) ),
406 array( array( 'badaccess-group0' ) ) );
409 function runCSSandJSPermissions( $result0, $result1, $result2 ) {
410 $this->setUserPerm( '' );
411 $this->assertEquals( $result0,
412 $this->title
->getUserPermissionsErrors( 'bogus',
415 $this->setUserPerm( 'editusercss' );
416 $this->assertEquals( $result1,
417 $this->title
->getUserPermissionsErrors( 'bogus',
420 $this->setUserPerm( 'edituserjs' );
421 $this->assertEquals( $result2,
422 $this->title
->getUserPermissionsErrors( 'bogus',
425 $this->setUserPerm( 'editusercssjs' );
426 $this->assertEquals( array( array( 'badaccess-group0' ) ),
427 $this->title
->getUserPermissionsErrors( 'bogus',
430 $this->setUserPerm( array( 'edituserjs', 'editusercss' ) );
431 $this->assertEquals( array( array( 'badaccess-group0' ) ),
432 $this->title
->getUserPermissionsErrors( 'bogus',
436 function testPageRestrictions() {
437 global $wgUser, $wgContLang;
439 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT
);
441 $wgUser = $this->user
;
442 $this->setTitle( NS_MAIN
);
443 $this->title
->mRestrictionsLoaded
= true;
444 $this->setUserPerm( "edit" );
445 $this->title
->mRestrictions
= array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
447 $this->assertEquals( array( ),
448 $this->title
->getUserPermissionsErrors( 'edit',
451 $this->assertEquals( true,
452 $this->title
->quickUserCan( 'edit', false ) );
453 $this->title
->mRestrictions
= array( "edit" => array( 'bogus', "sysop", "protect", "" ),
454 "bogus" => array( 'bogus', "sysop", "protect", "" ) );
456 $this->assertEquals( array( array( 'badaccess-group0' ),
457 array( 'protectedpagetext', 'bogus' ),
458 array( 'protectedpagetext', 'protect' ),
459 array( 'protectedpagetext', 'protect' ) ),
460 $this->title
->getUserPermissionsErrors( 'bogus',
462 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
463 array( 'protectedpagetext', 'protect' ),
464 array( 'protectedpagetext', 'protect' ) ),
465 $this->title
->getUserPermissionsErrors( 'edit',
467 $this->setUserPerm( "" );
468 $this->assertEquals( array( array( 'badaccess-group0' ),
469 array( 'protectedpagetext', 'bogus' ),
470 array( 'protectedpagetext', 'protect' ),
471 array( 'protectedpagetext', 'protect' ) ),
472 $this->title
->getUserPermissionsErrors( 'bogus',
474 $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ),
475 array( 'protectedpagetext', 'bogus' ),
476 array( 'protectedpagetext', 'protect' ),
477 array( 'protectedpagetext', 'protect' ) ),
478 $this->title
->getUserPermissionsErrors( 'edit',
480 $this->setUserPerm( array( "edit", "editprotected" ) );
481 $this->assertEquals( array( array( 'badaccess-group0' ),
482 array( 'protectedpagetext', 'bogus' ),
483 array( 'protectedpagetext', 'protect' ),
484 array( 'protectedpagetext', 'protect' ) ),
485 $this->title
->getUserPermissionsErrors( 'bogus',
487 $this->assertEquals( array( ),
488 $this->title
->getUserPermissionsErrors( 'edit',
490 $this->title
->mCascadeRestriction
= true;
491 $this->assertEquals( false,
492 $this->title
->quickUserCan( 'bogus', false ) );
493 $this->assertEquals( false,
494 $this->title
->quickUserCan( 'edit', false ) );
495 $this->assertEquals( array( array( 'badaccess-group0' ),
496 array( 'protectedpagetext', 'bogus' ),
497 array( 'protectedpagetext', 'protect' ),
498 array( 'protectedpagetext', 'protect' ) ),
499 $this->title
->getUserPermissionsErrors( 'bogus',
501 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
502 array( 'protectedpagetext', 'protect' ),
503 array( 'protectedpagetext', 'protect' ) ),
504 $this->title
->getUserPermissionsErrors( 'edit',
508 function testCascadingSourcesRestrictions() {
510 $wgUser = $this->user
;
511 $this->setTitle( NS_MAIN
, "test page" );
512 $this->setUserPerm( array( "edit", "bogus" ) );
514 $this->title
->mCascadeSources
= array( Title
::makeTitle( NS_MAIN
, "Bogus" ), Title
::makeTitle( NS_MAIN
, "UnBogus" ) );
515 $this->title
->mCascadingRestrictions
= array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
517 $this->assertEquals( false,
518 $this->title
->userCan( 'bogus' ) );
519 $this->assertEquals( array( array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ),
520 array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ) ),
521 $this->title
->getUserPermissionsErrors( 'bogus', $this->user
) );
523 $this->assertEquals( true,
524 $this->title
->userCan( 'edit' ) );
525 $this->assertEquals( array( ),
526 $this->title
->getUserPermissionsErrors( 'edit', $this->user
) );
530 function testActionPermissions() {
532 $wgUser = $this->user
;
534 $this->setUserPerm( array( "createpage" ) );
535 $this->setTitle( NS_MAIN
, "test page" );
536 $this->title
->mTitleProtection
['pt_create_perm'] = '';
537 $this->title
->mTitleProtection
['pt_user'] = $this->user
->getID();
538 $this->title
->mTitleProtection
['pt_expiry'] = Block
::infinity();
539 $this->title
->mTitleProtection
['pt_reason'] = 'test';
540 $this->title
->mCascadeRestriction
= false;
542 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
543 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
544 $this->assertEquals( false,
545 $this->title
->userCan( 'create' ) );
547 $this->title
->mTitleProtection
['pt_create_perm'] = 'sysop';
548 $this->setUserPerm( array( 'createpage', 'protect' ) );
549 $this->assertEquals( array( ),
550 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
551 $this->assertEquals( true,
552 $this->title
->userCan( 'create' ) );
555 $this->setUserPerm( array( 'createpage' ) );
556 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
557 $this->title
->getUserPermissionsErrors( 'create', $this->user
) );
558 $this->assertEquals( false,
559 $this->title
->userCan( 'create' ) );
561 $this->setTitle( NS_MEDIA
, "test page" );
562 $this->setUserPerm( array( "move" ) );
563 $this->assertEquals( false,
564 $this->title
->userCan( 'move' ) );
565 $this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ),
566 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
568 $this->setTitle( NS_MAIN
, "test page" );
569 $this->assertEquals( array( ),
570 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
571 $this->assertEquals( true,
572 $this->title
->userCan( 'move' ) );
574 $this->title
->mInterwiki
= "no";
575 $this->assertEquals( array( array( 'immobile-page' ) ),
576 $this->title
->getUserPermissionsErrors( 'move', $this->user
) );
577 $this->assertEquals( false,
578 $this->title
->userCan( 'move' ) );
580 $this->setTitle( NS_MEDIA
, "test page" );
581 $this->assertEquals( false,
582 $this->title
->userCan( 'move-target' ) );
583 $this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ),
584 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
586 $this->setTitle( NS_MAIN
, "test page" );
587 $this->assertEquals( array( ),
588 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
589 $this->assertEquals( true,
590 $this->title
->userCan( 'move-target' ) );
592 $this->title
->mInterwiki
= "no";
593 $this->assertEquals( array( array( 'immobile-target-page' ) ),
594 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
595 $this->assertEquals( false,
596 $this->title
->userCan( 'move-target' ) );
600 function testUserBlock() {
601 global $wgUser, $wgEmailConfirmToEdit, $wgEmailAuthentication;
602 $wgEmailConfirmToEdit = true;
603 $wgEmailAuthentication = true;
604 $wgUser = $this->user
;
606 $this->setUserPerm( array( "createpage", "move" ) );
607 $this->setTitle( NS_MAIN
, "test page" );
610 $this->assertEquals( array( array( 'confirmedittext' ) ),
611 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
612 $wgEmailConfirmToEdit = false;
613 $this->assertEquals( true, $this->title
->userCan( 'move-target' ) );
615 # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
616 $this->assertEquals( array( ),
617 $this->title
->getUserPermissionsErrors( 'move-target',
623 $this->user
->mBlockedby
= $this->user
->getId();
624 $this->user
->mBlock
= new Block( '127.0.8.1', $this->user
->getId(), $this->user
->getId(),
625 'no reason given', $prev +
3600, 1, 0 );
626 $this->user
->mBlock
->mTimestamp
= 0;
627 $this->assertEquals( array( array( 'autoblockedtext',
628 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
629 'Useruser', 0, 'infinite', '127.0.8.1',
630 $wgLang->timeanddate( wfTimestamp( TS_MW
, $prev ), true ) ) ),
631 $this->title
->getUserPermissionsErrors( 'move-target',
634 $this->assertEquals( false,
635 $this->title
->userCan( 'move-target', $this->user
) );
637 global $wgLocalTZoffset;
638 $wgLocalTZoffset = -60;
639 $this->user
->mBlockedby
= $this->user
->getName();
640 $this->user
->mBlock
= new Block( '127.0.8.1', 2, 1, 'no reason given', $now, 0, 10 );
641 $this->assertEquals( array( array( 'blockedtext',
642 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
643 'Useruser', 0, '23:00, 31 December 1969', '127.0.8.1',
644 $wgLang->timeanddate( wfTimestamp( TS_MW
, $now ), true ) ) ),
645 $this->title
->getUserPermissionsErrors( 'move-target', $this->user
) );
647 # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
648 # $user->blockedFor() == ''
649 # $user->mBlock->mExpiry == 'infinity'