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