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