64202662871707cd14dd28884ec33e00ccbde1ed
[lhc/web/wiklou.git] / maintenance / tests / TitlePermissionTest.php
1 <?php
2
3 class TitlePermissionTest extends PhpUnit_Framework_TestCase {
4 static $title;
5 static $user;
6 static $anonUser;
7 static $userUser;
8 static $altUser;
9 static $userName;
10 static $altUserName;
11
12 function setUp() {
13 global $wgAutoloadLocalClasses, $wgLocaltimezone, $wgLocalTZoffset;
14 self::$userName = "Useruser";
15 self::$altUserName = "Altuseruser";
16 date_default_timezone_set( $wgLocaltimezone );
17 $wgLocalTZoffset = date( "Z" ) / 60;
18
19 self::$title = Title::makeTitle( NS_MAIN, "Main Page" );
20 if ( !isset( self::$userUser ) || !( self::$userUser instanceOf User ) ) {
21 self::$userUser = User::newFromName( self::$userName );
22
23 if ( !self::$userUser->getID() ) {
24 self::$userUser = User::createNew( self::$userName, array(
25 "email" => "test@example.com",
26 "real_name" => "Test User" ) );
27 }
28
29 self::$altUser = User::newFromName( self::$altUserName );
30 if ( !self::$altUser->getID() ) {
31 self::$altUser = User::createNew( self::$altUserName, array(
32 "email" => "alttest@example.com",
33 "real_name" => "Test User Alt" ) );
34 }
35
36 self::$anonUser = User::newFromId( 0 );
37
38 self::$user = self::$userUser;
39 }
40 }
41
42 function setUserPerm( $perm ) {
43 global $wgUseRCPatrol, $wgUseNPPatrol;
44 if ( is_array( $perm ) ) {
45 self::$user->mRights = $perm;
46 } else {
47 self::$user->mRights = array( $perm );
48 }
49 }
50
51 function setTitle( $ns, $title = "Main_Page" ) {
52 self::$title = Title::makeTitle( $ns, $title );
53 }
54
55 function setUser( $userName = null ) {
56 if ( $userName === 'anon' ) {
57 self::$user = self::$anonUser;
58 } else if ( $userName === null || $userName === self::$userName ) {
59 self::$user = self::$userUser;
60 } else {
61 self::$user = self::$altUser;
62 }
63
64 global $wgUser;
65 $wgUser = self::$user;
66 }
67
68 function testQuickPermissions() {
69 global $wgContLang;
70 $prefix = $wgContLang->getNsText( NS_PROJECT );
71
72 $this->setUser( 'anon' );
73 $this->setTitle( NS_TALK );
74 $this->setUserPerm( "createtalk" );
75 $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
76 $this->assertEquals( array(), $res );
77
78 $this->setTitle( NS_TALK );
79 $this->setUserPerm( "createpage" );
80 $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
81 $this->assertEquals( array( array( "nocreatetext" ) ), $res );
82
83 $this->setTitle( NS_TALK );
84 $this->setUserPerm( "" );
85 $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
86 $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
87
88 $this->setTitle( NS_MAIN );
89 $this->setUserPerm( "createpage" );
90 $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
91 $this->assertEquals( array( ), $res );
92
93 $this->setTitle( NS_MAIN );
94 $this->setUserPerm( "createtalk" );
95 $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
96 $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
97
98 $this->setUser( self::$userName );
99 $this->setTitle( NS_TALK );
100 $this->setUserPerm( "createtalk" );
101 $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
102 $this->assertEquals( array( ), $res );
103
104 $this->setTitle( NS_TALK );
105 $this->setUserPerm( "createpage" );
106 $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
107 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
108
109 $this->setTitle( NS_TALK );
110 $this->setUserPerm( "" );
111 $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
112 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
113
114 $this->setTitle( NS_MAIN );
115 $this->setUserPerm( "createpage" );
116 $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
117 $this->assertEquals( array( ), $res );
118
119 $this->setTitle( NS_MAIN );
120 $this->setUserPerm( "createtalk" );
121 $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
122 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
123
124 $this->setTitle( NS_MAIN );
125 $this->setUserPerm( "" );
126 $res = self::$title->getUserPermissionsErrors( 'create', self::$user );
127 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
128
129 $this->setUser( 'anon' );
130 $this->setTitle( NS_USER, self::$userName . '' );
131 $this->setUserPerm( "" );
132 $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
133 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
134
135 $this->setTitle( NS_USER, self::$userName . '/subpage' );
136 $this->setUserPerm( "" );
137 $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
138 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
139
140 $this->setTitle( NS_USER, self::$userName . '' );
141 $this->setUserPerm( "move-rootuserpages" );
142 $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
143 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
144
145 $this->setTitle( NS_USER, self::$userName . '/subpage' );
146 $this->setUserPerm( "move-rootuserpages" );
147 $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
148 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
149
150 $this->setTitle( NS_USER, self::$userName . '' );
151 $this->setUserPerm( "" );
152 $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
153 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
154
155 $this->setTitle( NS_USER, self::$userName . '/subpage' );
156 $this->setUserPerm( "" );
157 $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
158 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
159
160 $this->setTitle( NS_USER, self::$userName . '' );
161 $this->setUserPerm( "move-rootuserpages" );
162 $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
163 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
164
165 $this->setTitle( NS_USER, self::$userName . '/subpage' );
166 $this->setUserPerm( "move-rootuserpages" );
167 $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
168 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
169
170 $this->setUser( self::$userName );
171 $this->setTitle( NS_FILE, "img.png" );
172 $this->setUserPerm( "" );
173 $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
174 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ), $res );
175
176 $this->setTitle( NS_FILE, "img.png" );
177 $this->setUserPerm( "movefile" );
178 $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
179 $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
180
181 $this->setUser( 'anon' );
182 $this->setTitle( NS_FILE, "img.png" );
183 $this->setUserPerm( "" );
184 $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
185 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ), $res );
186
187 $this->setTitle( NS_FILE, "img.png" );
188 $this->setUserPerm( "movefile" );
189 $res = self::$title->getUserPermissionsErrors( 'move', self::$user );
190 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
191
192 $this->setUser( self::$userName );
193 $this->setUserPerm( "move" );
194 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
195
196 $this->setUserPerm( "" );
197 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ) );
198
199 $this->setUser( 'anon' );
200 $this->setUserPerm( "move" );
201 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
202
203 $this->setUserPerm( "" );
204 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ),
205 array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ) );
206
207 $this->setTitle( NS_MAIN );
208 $this->setUser( 'anon' );
209 $this->setUserPerm( "move" );
210 $this->runGroupPermissions( 'move', array( ) );
211
212 $this->setUserPerm( "" );
213 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ),
214 array( array( 'movenologintext' ) ) );
215
216 $this->setUser( self::$userName );
217 $this->setUserPerm( "" );
218 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ) );
219
220 $this->setUserPerm( "move" );
221 $this->runGroupPermissions( 'move', array( ) );
222
223 $this->setUser( 'anon' );
224 $this->setUserPerm( 'move' );
225 $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user );
226 $this->assertEquals( array( ), $res );
227
228 $this->setUserPerm( '' );
229 $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user );
230 $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
231
232 $this->setTitle( NS_USER );
233 $this->setUser( self::$userName );
234 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
235 $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user );
236 $this->assertEquals( array( ), $res );
237
238 $this->setUserPerm( "move" );
239 $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user );
240 $this->assertEquals( array( array( 'cant-move-to-user-page' ) ), $res );
241
242 $this->setUser( 'anon' );
243 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
244 $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user );
245 $this->assertEquals( array( ), $res );
246
247 $this->setTitle( NS_USER, "User/subpage" );
248 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
249 $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user );
250 $this->assertEquals( array( ), $res );
251
252 $this->setUserPerm( "move" );
253 $res = self::$title->getUserPermissionsErrors( 'move-target', self::$user );
254 $this->assertEquals( array( ), $res );
255
256 $this->setUser( 'anon' );
257 $check = array( 'edit' => array( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ) ),
258 array( array( 'badaccess-group0' ) ),
259 array( ), true ),
260 'protect' => array( array( array( 'badaccess-groups', "[[$prefix:Administrators|Administrators]]", 1 ), array( 'protect-cantedit' ) ),
261 array( array( 'badaccess-group0' ), array( 'protect-cantedit' ) ),
262 array( array( 'protect-cantedit' ) ), false ),
263 '' => array( array( ), array( ), array( ), true ) );
264 global $wgUser;
265 $wgUser = self::$user;
266 foreach ( array( "edit", "protect", "" ) as $action ) {
267 $this->setUserPerm( null );
268 $this->assertEquals( $check[$action][0],
269 self::$title->getUserPermissionsErrors( $action, self::$user, true ) );
270
271 global $wgGroupPermissions;
272 $old = $wgGroupPermissions;
273 $wgGroupPermissions = array();
274
275 $this->assertEquals( $check[$action][1],
276 self::$title->getUserPermissionsErrors( $action, self::$user, true ) );
277 $wgGroupPermissions = $old;
278
279 $this->setUserPerm( $action );
280 $this->assertEquals( $check[$action][2],
281 self::$title->getUserPermissionsErrors( $action, self::$user, true ) );
282
283 $this->setUserPerm( $action );
284 $this->assertEquals( $check[$action][3],
285 self::$title->userCan( $action, true ) );
286 $this->assertEquals( $check[$action][3],
287 self::$title->quickUserCan( $action, false ) );
288
289 # count( User::getGroupsWithPermissions( $action ) ) < 1
290 }
291 }
292
293 function runGroupPermissions( $action, $result, $result2 = null ) {
294 global $wgGroupPermissions;
295
296 if ( $result2 === null ) $result2 = $result;
297
298 $wgGroupPermissions['autoconfirmed']['move'] = false;
299 $wgGroupPermissions['user']['move'] = false;
300 $res = self::$title->getUserPermissionsErrors( $action, self::$user );
301 $this->assertEquals( $result, $res );
302
303 $wgGroupPermissions['autoconfirmed']['move'] = true;
304 $wgGroupPermissions['user']['move'] = false;
305 $res = self::$title->getUserPermissionsErrors( $action, self::$user );
306 $this->assertEquals( $result2, $res );
307
308 $wgGroupPermissions['autoconfirmed']['move'] = true;
309 $wgGroupPermissions['user']['move'] = true;
310 $res = self::$title->getUserPermissionsErrors( $action, self::$user );
311 $this->assertEquals( $result2, $res );
312
313 $wgGroupPermissions['autoconfirmed']['move'] = false;
314 $wgGroupPermissions['user']['move'] = true;
315 $res = self::$title->getUserPermissionsErrors( $action, self::$user );
316 $this->assertEquals( $result2, $res );
317 }
318
319 function testPermissionHooks() { }
320 function testSpecialsAndNSPermissions() {
321 $this->setUser( self::$userName );
322 global $wgUser, $wgContLang;
323 $wgUser = self::$user;
324 $prefix = $wgContLang->getNsText( NS_PROJECT );
325
326 $this->setTitle( NS_SPECIAL );
327
328 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'ns-specialprotected' ) ),
329 self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
330 $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Administrators|Administrators]]", 2 ) ),
331 self::$title->getUserPermissionsErrors( 'createaccount', self::$user ) );
332 $this->assertEquals( array( array( 'badaccess-group0' ) ),
333 self::$title->getUserPermissionsErrors( 'execute', self::$user ) );
334
335 $this->setTitle( NS_MAIN );
336 $this->setUserPerm( 'bogus' );
337 $this->assertEquals( array( ),
338 self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
339
340 $this->setTitle( NS_MAIN );
341 $this->setUserPerm( '' );
342 $this->assertEquals( array( array( 'badaccess-group0' ) ),
343 self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
344
345 global $wgNamespaceProtection;
346 $wgNamespaceProtection[NS_USER] = array ( 'bogus' );
347 $this->setTitle( NS_USER );
348 $this->setUserPerm( '' );
349 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'namespaceprotected', 'User' ) ),
350 self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
351
352 $this->setTitle( NS_MEDIAWIKI );
353 $this->setUserPerm( 'bogus' );
354 $this->assertEquals( array( array( 'protectedinterface' ) ),
355 self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
356
357 $this->setTitle( NS_MEDIAWIKI );
358 $this->setUserPerm( 'bogus' );
359 $this->assertEquals( array( array( 'protectedinterface' ) ),
360 self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
361
362 $wgNamespaceProtection = null;
363 $this->setUserPerm( 'bogus' );
364 $this->assertEquals( array( ),
365 self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
366 $this->assertEquals( true,
367 self::$title->userCan( 'bogus' ) );
368
369 $this->setUserPerm( '' );
370 $this->assertEquals( array( array( 'badaccess-group0' ) ),
371 self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
372 $this->assertEquals( false,
373 self::$title->userCan( 'bogus' ) );
374 }
375
376 function testCSSandJSPermissions() {
377 $this->setUser( self::$userName );
378 global $wgUser;
379 $wgUser = self::$user;
380
381 $this->setTitle( NS_USER, self::$altUserName . '/test.js' );
382 $this->runCSSandJSPermissions(
383 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
384 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
385 array( array( 'badaccess-group0' ) ) );
386
387 $this->setTitle( NS_USER, self::$altUserName . '/test.css' );
388 $this->runCSSandJSPermissions(
389 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
390 array( array( 'badaccess-group0' ) ),
391 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ) );
392
393 $this->setTitle( NS_USER, self::$altUserName . '/tempo' );
394 $this->runCSSandJSPermissions(
395 array( array( 'badaccess-group0' ) ),
396 array( array( 'badaccess-group0' ) ),
397 array( array( 'badaccess-group0' ) ) );
398 }
399
400 function runCSSandJSPermissions( $result0, $result1, $result2 ) {
401 $this->setUserPerm( '' );
402 $this->assertEquals( $result0,
403 self::$title->getUserPermissionsErrors( 'bogus',
404 self::$user ) );
405
406 $this->setUserPerm( 'editusercss' );
407 $this->assertEquals( $result1,
408 self::$title->getUserPermissionsErrors( 'bogus',
409 self::$user ) );
410
411 $this->setUserPerm( 'edituserjs' );
412 $this->assertEquals( $result2,
413 self::$title->getUserPermissionsErrors( 'bogus',
414 self::$user ) );
415
416 $this->setUserPerm( 'editusercssjs' );
417 $this->assertEquals( array( array( 'badaccess-group0' ) ),
418 self::$title->getUserPermissionsErrors( 'bogus',
419 self::$user ) );
420
421 $this->setUserPerm( array( 'edituserjs', 'editusercss' ) );
422 $this->assertEquals( array( array( 'badaccess-group0' ) ),
423 self::$title->getUserPermissionsErrors( 'bogus',
424 self::$user ) );
425 }
426
427 function testPageRestrictions() {
428 global $wgUser, $wgContLang;
429
430 $prefix = $wgContLang->getNsText( NS_PROJECT );
431
432 $wgUser = self::$user;
433 $this->setTitle( NS_MAIN );
434 self::$title->mRestrictionsLoaded = true;
435 $this->setUserPerm( "edit" );
436 self::$title->mRestrictions = array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
437
438 $this->assertEquals( array( ),
439 self::$title->getUserPermissionsErrors( 'edit',
440 self::$user ) );
441
442 $this->assertEquals( true,
443 self::$title->quickUserCan( 'edit', false ) );
444 self::$title->mRestrictions = array( "edit" => array( 'bogus', "sysop", "protect", "" ),
445 "bogus" => array( 'bogus', "sysop", "protect", "" ) );
446
447 $this->assertEquals( array( array( 'badaccess-group0' ),
448 array( 'protectedpagetext', 'bogus' ),
449 array( 'protectedpagetext', 'protect' ),
450 array( 'protectedpagetext', 'protect' ) ),
451 self::$title->getUserPermissionsErrors( 'bogus',
452 self::$user ) );
453 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
454 array( 'protectedpagetext', 'protect' ),
455 array( 'protectedpagetext', 'protect' ) ),
456 self::$title->getUserPermissionsErrors( 'edit',
457 self::$user ) );
458 $this->setUserPerm( "" );
459 $this->assertEquals( array( array( 'badaccess-group0' ),
460 array( 'protectedpagetext', 'bogus' ),
461 array( 'protectedpagetext', 'protect' ),
462 array( 'protectedpagetext', 'protect' ) ),
463 self::$title->getUserPermissionsErrors( 'bogus',
464 self::$user ) );
465 $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ),
466 array( 'protectedpagetext', 'bogus' ),
467 array( 'protectedpagetext', 'protect' ),
468 array( 'protectedpagetext', 'protect' ) ),
469 self::$title->getUserPermissionsErrors( 'edit',
470 self::$user ) );
471 $this->setUserPerm( array( "edit", "editprotected" ) );
472 $this->assertEquals( array( array( 'badaccess-group0' ),
473 array( 'protectedpagetext', 'bogus' ),
474 array( 'protectedpagetext', 'protect' ),
475 array( 'protectedpagetext', 'protect' ) ),
476 self::$title->getUserPermissionsErrors( 'bogus',
477 self::$user ) );
478 $this->assertEquals( array( ),
479 self::$title->getUserPermissionsErrors( 'edit',
480 self::$user ) );
481 self::$title->mCascadeRestriction = true;
482 $this->assertEquals( false,
483 self::$title->quickUserCan( 'bogus', false ) );
484 $this->assertEquals( false,
485 self::$title->quickUserCan( 'edit', false ) );
486 $this->assertEquals( array( array( 'badaccess-group0' ),
487 array( 'protectedpagetext', 'bogus' ),
488 array( 'protectedpagetext', 'protect' ),
489 array( 'protectedpagetext', 'protect' ) ),
490 self::$title->getUserPermissionsErrors( 'bogus',
491 self::$user ) );
492 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
493 array( 'protectedpagetext', 'protect' ),
494 array( 'protectedpagetext', 'protect' ) ),
495 self::$title->getUserPermissionsErrors( 'edit',
496 self::$user ) );
497 }
498
499 function testCascadingSourcesRestrictions() {
500 global $wgUser;
501 $wgUser = self::$user;
502 $this->setTitle( NS_MAIN, "test page" );
503 $this->setUserPerm( array( "edit", "bogus" ) );
504
505 self::$title->mCascadeSources = array( Title::makeTitle( NS_MAIN, "Bogus" ), Title::makeTitle( NS_MAIN, "UnBogus" ) );
506 self::$title->mCascadingRestrictions = array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
507
508 $this->assertEquals( false,
509 self::$title->userCan( 'bogus' ) );
510 $this->assertEquals( array( array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ),
511 array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ) ),
512 self::$title->getUserPermissionsErrors( 'bogus', self::$user ) );
513
514 $this->assertEquals( true,
515 self::$title->userCan( 'edit' ) );
516 $this->assertEquals( array( ),
517 self::$title->getUserPermissionsErrors( 'edit', self::$user ) );
518
519 }
520
521 function testActionPermissions() {
522 global $wgUser;
523 $wgUser = self::$user;
524
525 $this->setUserPerm( array( "createpage" ) );
526 $this->setTitle( NS_MAIN, "test page" );
527 self::$title->mTitleProtection['pt_create_perm'] = '';
528 self::$title->mTitleProtection['pt_user'] = self::$user->getID();
529 self::$title->mTitleProtection['pt_expiry'] = Block::infinity();
530 self::$title->mTitleProtection['pt_reason'] = 'test';
531 self::$title->mCascadeRestriction = false;
532
533 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
534 self::$title->getUserPermissionsErrors( 'create', self::$user ) );
535 $this->assertEquals( false,
536 self::$title->userCan( 'create' ) );
537
538 self::$title->mTitleProtection['pt_create_perm'] = 'sysop';
539 $this->setUserPerm( array( 'createpage', 'protect' ) );
540 $this->assertEquals( array( ),
541 self::$title->getUserPermissionsErrors( 'create', self::$user ) );
542 $this->assertEquals( true,
543 self::$title->userCan( 'create' ) );
544
545
546 $this->setUserPerm( array( 'createpage' ) );
547 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
548 self::$title->getUserPermissionsErrors( 'create', self::$user ) );
549 $this->assertEquals( false,
550 self::$title->userCan( 'create' ) );
551
552 $this->setTitle( NS_MEDIA, "test page" );
553 $this->setUserPerm( array( "move" ) );
554 $this->assertEquals( false,
555 self::$title->userCan( 'move' ) );
556 $this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ),
557 self::$title->getUserPermissionsErrors( 'move', self::$user ) );
558
559 $this->setTitle( NS_MAIN, "test page" );
560 $this->assertEquals( array( ),
561 self::$title->getUserPermissionsErrors( 'move', self::$user ) );
562 $this->assertEquals( true,
563 self::$title->userCan( 'move' ) );
564
565 self::$title->mInterwiki = "no";
566 $this->assertEquals( array( array( 'immobile-page' ) ),
567 self::$title->getUserPermissionsErrors( 'move', self::$user ) );
568 $this->assertEquals( false,
569 self::$title->userCan( 'move' ) );
570
571 $this->setTitle( NS_MEDIA, "test page" );
572 $this->assertEquals( false,
573 self::$title->userCan( 'move-target' ) );
574 $this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ),
575 self::$title->getUserPermissionsErrors( 'move-target', self::$user ) );
576
577 $this->setTitle( NS_MAIN, "test page" );
578 $this->assertEquals( array( ),
579 self::$title->getUserPermissionsErrors( 'move-target', self::$user ) );
580 $this->assertEquals( true,
581 self::$title->userCan( 'move-target' ) );
582
583 self::$title->mInterwiki = "no";
584 $this->assertEquals( array( array( 'immobile-target-page' ) ),
585 self::$title->getUserPermissionsErrors( 'move-target', self::$user ) );
586 $this->assertEquals( false,
587 self::$title->userCan( 'move-target' ) );
588
589 }
590
591 function testUserBlock() {
592 global $wgUser, $wgEmailConfirmToEdit, $wgEmailAuthentication;
593 $wgEmailConfirmToEdit = true;
594 $wgEmailAuthentication = true;
595 $wgUser = self::$user;
596
597 $this->setUserPerm( array( "createpage", "move" ) );
598 $this->setTitle( NS_MAIN, "test page" );
599
600 # $short
601 $this->assertEquals( array( array( 'confirmedittext' ) ),
602 self::$title->getUserPermissionsErrors( 'move-target', self::$user ) );
603 $this->assertEquals( true, self::$title->userCan( 'move-target' ) );
604
605 $wgEmailConfirmToEdit = false;
606 # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
607 $this->assertEquals( array( ),
608 self::$title->getUserPermissionsErrors( 'move-target',
609 self::$user ) );
610
611 global $wgLang;
612 $prev = time();
613 $now = time() + 120;
614 self::$user->mBlockedby = self::$user->getId();
615 self::$user->mBlock = new Block( '127.0.8.1', self::$user->getId(), self::$user->getId(),
616 'no reason given', $prev + 3600, 1, 0 );
617 self::$user->mBlock->mTimestamp = 0;
618 $this->assertEquals( array( array( 'autoblockedtext',
619 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
620 'Useruser', 0, 'infinite', '127.0.8.1',
621 $wgLang->timeanddate( wfTimestamp( TS_MW, $prev ), true ) ) ),
622 self::$title->getUserPermissionsErrors( 'move-target',
623 self::$user ) );
624
625 $this->assertEquals( true,
626 self::$title->userCan( 'move-target', self::$user ) );
627
628 global $wgLocalTZoffset;
629 $wgLocalTZoffset = -60;
630 self::$user->mBlockedby = self::$user->getName();
631 self::$user->mBlock = new Block( '127.0.8.1', 2, 1, 'no reason given', $now, 0, 10 );
632 $this->assertEquals( array( array( 'blockedtext',
633 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
634 'Useruser', 0, '23:00, 31 December 1969', '127.0.8.1',
635 $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ) ),
636 self::$title->getUserPermissionsErrors( 'move-target', self::$user ) );
637
638 # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
639 # $user->blockedFor() == ''
640 # $user->mBlock->mExpiry == 'infinity'
641 }
642 }