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