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