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