Followup r83140: FakeMemCachedClient -> EmptyBagOStuff in tests
[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, $wgContLang;
333 $wgUser = $this->user;
334 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT );
335
336 $this->setTitle( NS_SPECIAL );
337
338 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'ns-specialprotected' ) ),
339 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
340 $this->assertEquals( array( array( 'badaccess-group0' ) ),
341 $this->title->getUserPermissionsErrors( 'execute', $this->user ) );
342
343 $this->setTitle( NS_MAIN );
344 $this->setUserPerm( 'bogus' );
345 $this->assertEquals( array( ),
346 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
347
348 $this->setTitle( NS_MAIN );
349 $this->setUserPerm( '' );
350 $this->assertEquals( array( array( 'badaccess-group0' ) ),
351 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
352
353 global $wgNamespaceProtection;
354 $wgNamespaceProtection[NS_USER] = array ( 'bogus' );
355 $this->setTitle( NS_USER );
356 $this->setUserPerm( '' );
357 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'namespaceprotected', 'User' ) ),
358 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
359
360 $this->setTitle( NS_MEDIAWIKI );
361 $this->setUserPerm( 'bogus' );
362 $this->assertEquals( array( array( 'protectedinterface' ) ),
363 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
364
365 $this->setTitle( NS_MEDIAWIKI );
366 $this->setUserPerm( 'bogus' );
367 $this->assertEquals( array( array( 'protectedinterface' ) ),
368 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
369
370 $wgNamespaceProtection = null;
371 $this->setUserPerm( 'bogus' );
372 $this->assertEquals( array( ),
373 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
374 $this->assertEquals( true,
375 $this->title->userCan( 'bogus' ) );
376
377 $this->setUserPerm( '' );
378 $this->assertEquals( array( array( 'badaccess-group0' ) ),
379 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
380 $this->assertEquals( false,
381 $this->title->userCan( 'bogus' ) );
382 }
383
384 function testCSSandJSPermissions() {
385 $this->setUser( $this->userName );
386 global $wgUser;
387 $wgUser = $this->user;
388
389 $this->setTitle( NS_USER, $this->altUserName . '/test.js' );
390 $this->runCSSandJSPermissions(
391 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
392 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
393 array( array( 'badaccess-group0' ) ) );
394
395 $this->setTitle( NS_USER, $this->altUserName . '/test.css' );
396 $this->runCSSandJSPermissions(
397 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ),
398 array( array( 'badaccess-group0' ) ),
399 array( array( 'badaccess-group0' ), array( 'customcssjsprotected' ) ) );
400
401 $this->setTitle( NS_USER, $this->altUserName . '/tempo' );
402 $this->runCSSandJSPermissions(
403 array( array( 'badaccess-group0' ) ),
404 array( array( 'badaccess-group0' ) ),
405 array( array( 'badaccess-group0' ) ) );
406 }
407
408 function runCSSandJSPermissions( $result0, $result1, $result2 ) {
409 $this->setUserPerm( '' );
410 $this->assertEquals( $result0,
411 $this->title->getUserPermissionsErrors( 'bogus',
412 $this->user ) );
413
414 $this->setUserPerm( 'editusercss' );
415 $this->assertEquals( $result1,
416 $this->title->getUserPermissionsErrors( 'bogus',
417 $this->user ) );
418
419 $this->setUserPerm( 'edituserjs' );
420 $this->assertEquals( $result2,
421 $this->title->getUserPermissionsErrors( 'bogus',
422 $this->user ) );
423
424 $this->setUserPerm( 'editusercssjs' );
425 $this->assertEquals( array( array( 'badaccess-group0' ) ),
426 $this->title->getUserPermissionsErrors( 'bogus',
427 $this->user ) );
428
429 $this->setUserPerm( array( 'edituserjs', 'editusercss' ) );
430 $this->assertEquals( array( array( 'badaccess-group0' ) ),
431 $this->title->getUserPermissionsErrors( 'bogus',
432 $this->user ) );
433 }
434
435 function testPageRestrictions() {
436 global $wgUser, $wgContLang;
437
438 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT );
439
440 $wgUser = $this->user;
441 $this->setTitle( NS_MAIN );
442 $this->title->mRestrictionsLoaded = true;
443 $this->setUserPerm( "edit" );
444 $this->title->mRestrictions = array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
445
446 $this->assertEquals( array( ),
447 $this->title->getUserPermissionsErrors( 'edit',
448 $this->user ) );
449
450 $this->assertEquals( true,
451 $this->title->quickUserCan( 'edit', false ) );
452 $this->title->mRestrictions = array( "edit" => array( 'bogus', "sysop", "protect", "" ),
453 "bogus" => array( 'bogus', "sysop", "protect", "" ) );
454
455 $this->assertEquals( array( array( 'badaccess-group0' ),
456 array( 'protectedpagetext', 'bogus' ),
457 array( 'protectedpagetext', 'protect' ),
458 array( 'protectedpagetext', 'protect' ) ),
459 $this->title->getUserPermissionsErrors( 'bogus',
460 $this->user ) );
461 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
462 array( 'protectedpagetext', 'protect' ),
463 array( 'protectedpagetext', 'protect' ) ),
464 $this->title->getUserPermissionsErrors( 'edit',
465 $this->user ) );
466 $this->setUserPerm( "" );
467 $this->assertEquals( array( array( 'badaccess-group0' ),
468 array( 'protectedpagetext', 'bogus' ),
469 array( 'protectedpagetext', 'protect' ),
470 array( 'protectedpagetext', 'protect' ) ),
471 $this->title->getUserPermissionsErrors( 'bogus',
472 $this->user ) );
473 $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ),
474 array( 'protectedpagetext', 'bogus' ),
475 array( 'protectedpagetext', 'protect' ),
476 array( 'protectedpagetext', 'protect' ) ),
477 $this->title->getUserPermissionsErrors( 'edit',
478 $this->user ) );
479 $this->setUserPerm( array( "edit", "editprotected" ) );
480 $this->assertEquals( array( array( 'badaccess-group0' ),
481 array( 'protectedpagetext', 'bogus' ),
482 array( 'protectedpagetext', 'protect' ),
483 array( 'protectedpagetext', 'protect' ) ),
484 $this->title->getUserPermissionsErrors( 'bogus',
485 $this->user ) );
486 $this->assertEquals( array( ),
487 $this->title->getUserPermissionsErrors( 'edit',
488 $this->user ) );
489 $this->title->mCascadeRestriction = true;
490 $this->assertEquals( false,
491 $this->title->quickUserCan( 'bogus', false ) );
492 $this->assertEquals( false,
493 $this->title->quickUserCan( 'edit', false ) );
494 $this->assertEquals( array( array( 'badaccess-group0' ),
495 array( 'protectedpagetext', 'bogus' ),
496 array( 'protectedpagetext', 'protect' ),
497 array( 'protectedpagetext', 'protect' ) ),
498 $this->title->getUserPermissionsErrors( 'bogus',
499 $this->user ) );
500 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
501 array( 'protectedpagetext', 'protect' ),
502 array( 'protectedpagetext', 'protect' ) ),
503 $this->title->getUserPermissionsErrors( 'edit',
504 $this->user ) );
505 }
506
507 function testCascadingSourcesRestrictions() {
508 global $wgUser;
509 $wgUser = $this->user;
510 $this->setTitle( NS_MAIN, "test page" );
511 $this->setUserPerm( array( "edit", "bogus" ) );
512
513 $this->title->mCascadeSources = array( Title::makeTitle( NS_MAIN, "Bogus" ), Title::makeTitle( NS_MAIN, "UnBogus" ) );
514 $this->title->mCascadingRestrictions = array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
515
516 $this->assertEquals( false,
517 $this->title->userCan( 'bogus' ) );
518 $this->assertEquals( array( array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ),
519 array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ) ),
520 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
521
522 $this->assertEquals( true,
523 $this->title->userCan( 'edit' ) );
524 $this->assertEquals( array( ),
525 $this->title->getUserPermissionsErrors( 'edit', $this->user ) );
526
527 }
528
529 function testActionPermissions() {
530 global $wgUser;
531 $wgUser = $this->user;
532
533 $this->setUserPerm( array( "createpage" ) );
534 $this->setTitle( NS_MAIN, "test page" );
535 $this->title->mTitleProtection['pt_create_perm'] = '';
536 $this->title->mTitleProtection['pt_user'] = $this->user->getID();
537 $this->title->mTitleProtection['pt_expiry'] = Block::infinity();
538 $this->title->mTitleProtection['pt_reason'] = 'test';
539 $this->title->mCascadeRestriction = false;
540
541 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
542 $this->title->getUserPermissionsErrors( 'create', $this->user ) );
543 $this->assertEquals( false,
544 $this->title->userCan( 'create' ) );
545
546 $this->title->mTitleProtection['pt_create_perm'] = 'sysop';
547 $this->setUserPerm( array( 'createpage', 'protect' ) );
548 $this->assertEquals( array( ),
549 $this->title->getUserPermissionsErrors( 'create', $this->user ) );
550 $this->assertEquals( true,
551 $this->title->userCan( 'create' ) );
552
553
554 $this->setUserPerm( array( 'createpage' ) );
555 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
556 $this->title->getUserPermissionsErrors( 'create', $this->user ) );
557 $this->assertEquals( false,
558 $this->title->userCan( 'create' ) );
559
560 $this->setTitle( NS_MEDIA, "test page" );
561 $this->setUserPerm( array( "move" ) );
562 $this->assertEquals( false,
563 $this->title->userCan( 'move' ) );
564 $this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ),
565 $this->title->getUserPermissionsErrors( 'move', $this->user ) );
566
567 $this->setTitle( NS_MAIN, "test page" );
568 $this->assertEquals( array( ),
569 $this->title->getUserPermissionsErrors( 'move', $this->user ) );
570 $this->assertEquals( true,
571 $this->title->userCan( 'move' ) );
572
573 $this->title->mInterwiki = "no";
574 $this->assertEquals( array( array( 'immobile-page' ) ),
575 $this->title->getUserPermissionsErrors( 'move', $this->user ) );
576 $this->assertEquals( false,
577 $this->title->userCan( 'move' ) );
578
579 $this->setTitle( NS_MEDIA, "test page" );
580 $this->assertEquals( false,
581 $this->title->userCan( 'move-target' ) );
582 $this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ),
583 $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
584
585 $this->setTitle( NS_MAIN, "test page" );
586 $this->assertEquals( array( ),
587 $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
588 $this->assertEquals( true,
589 $this->title->userCan( 'move-target' ) );
590
591 $this->title->mInterwiki = "no";
592 $this->assertEquals( array( array( 'immobile-target-page' ) ),
593 $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
594 $this->assertEquals( false,
595 $this->title->userCan( 'move-target' ) );
596
597 }
598
599 function testUserBlock() {
600 global $wgUser, $wgEmailConfirmToEdit, $wgEmailAuthentication;
601 $wgEmailConfirmToEdit = true;
602 $wgEmailAuthentication = true;
603 $wgUser = $this->user;
604
605 $this->setUserPerm( array( "createpage", "move" ) );
606 $this->setTitle( NS_MAIN, "test page" );
607
608 # $short
609 $this->assertEquals( array( array( 'confirmedittext' ) ),
610 $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
611 $wgEmailConfirmToEdit = false;
612 $this->assertEquals( true, $this->title->userCan( 'move-target' ) );
613
614 # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
615 $this->assertEquals( array( ),
616 $this->title->getUserPermissionsErrors( 'move-target',
617 $this->user ) );
618
619 global $wgLang;
620 $prev = time();
621 $now = time() + 120;
622 $this->user->mBlockedby = $this->user->getId();
623 $this->user->mBlock = new Block( '127.0.8.1', $this->user->getId(), $this->user->getId(),
624 'no reason given', $prev + 3600, 1, 0 );
625 $this->user->mBlock->mTimestamp = 0;
626 $this->assertEquals( array( array( 'autoblockedtext',
627 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
628 'Useruser', 0, 'infinite', '127.0.8.1',
629 $wgLang->timeanddate( wfTimestamp( TS_MW, $prev ), true ) ) ),
630 $this->title->getUserPermissionsErrors( 'move-target',
631 $this->user ) );
632
633 $this->assertEquals( false,
634 $this->title->userCan( 'move-target', $this->user ) );
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', 0, '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 }