Merge "(bug 17808) (bug 21167) use real links for search suggestions"
[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
72 function setUserPerm( $perm ) {
73 // Setting member variables is evil!!!
74
75 if ( is_array( $perm ) ) {
76 $this->user->mRights = $perm;
77 } else {
78 $this->user->mRights = array( $perm );
79 }
80 }
81
82 function setTitle( $ns, $title = "Main_Page" ) {
83 $this->title = Title::makeTitle( $ns, $title );
84 }
85
86 function setUser( $userName = null ) {
87 if ( $userName === 'anon' ) {
88 $this->user = $this->anonUser;
89 } elseif ( $userName === null || $userName === $this->userName ) {
90 $this->user = $this->userUser;
91 } else {
92 $this->user = $this->altUser;
93 }
94 }
95
96 function testQuickPermissions() {
97 global $wgContLang;
98 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT );
99
100 $this->setUser( 'anon' );
101 $this->setTitle( NS_TALK );
102 $this->setUserPerm( "createtalk" );
103 $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
104 $this->assertEquals( array(), $res );
105
106 $this->setTitle( NS_TALK );
107 $this->setUserPerm( "createpage" );
108 $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
109 $this->assertEquals( array( array( "nocreatetext" ) ), $res );
110
111 $this->setTitle( NS_TALK );
112 $this->setUserPerm( "" );
113 $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
114 $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
115
116 $this->setTitle( NS_MAIN );
117 $this->setUserPerm( "createpage" );
118 $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
119 $this->assertEquals( array( ), $res );
120
121 $this->setTitle( NS_MAIN );
122 $this->setUserPerm( "createtalk" );
123 $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
124 $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
125
126 $this->setUser( $this->userName );
127 $this->setTitle( NS_TALK );
128 $this->setUserPerm( "createtalk" );
129 $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
130 $this->assertEquals( array( ), $res );
131
132 $this->setTitle( NS_TALK );
133 $this->setUserPerm( "createpage" );
134 $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
135 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
136
137 $this->setTitle( NS_TALK );
138 $this->setUserPerm( "" );
139 $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
140 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
141
142 $this->setTitle( NS_MAIN );
143 $this->setUserPerm( "createpage" );
144 $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
145 $this->assertEquals( array( ), $res );
146
147 $this->setTitle( NS_MAIN );
148 $this->setUserPerm( "createtalk" );
149 $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
150 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
151
152 $this->setTitle( NS_MAIN );
153 $this->setUserPerm( "" );
154 $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
155 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
156
157 $this->setUser( 'anon' );
158 $this->setTitle( NS_USER, $this->userName . '' );
159 $this->setUserPerm( "" );
160 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
161 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
162
163 $this->setTitle( NS_USER, $this->userName . '/subpage' );
164 $this->setUserPerm( "" );
165 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
166 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
167
168 $this->setTitle( NS_USER, $this->userName . '' );
169 $this->setUserPerm( "move-rootuserpages" );
170 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
171 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
172
173 $this->setTitle( NS_USER, $this->userName . '/subpage' );
174 $this->setUserPerm( "move-rootuserpages" );
175 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
176 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
177
178 $this->setTitle( NS_USER, $this->userName . '' );
179 $this->setUserPerm( "" );
180 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
181 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
182
183 $this->setTitle( NS_USER, $this->userName . '/subpage' );
184 $this->setUserPerm( "" );
185 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
186 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
187
188 $this->setTitle( NS_USER, $this->userName . '' );
189 $this->setUserPerm( "move-rootuserpages" );
190 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
191 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
192
193 $this->setTitle( NS_USER, $this->userName . '/subpage' );
194 $this->setUserPerm( "move-rootuserpages" );
195 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
196 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
197
198 $this->setUser( $this->userName );
199 $this->setTitle( NS_FILE, "img.png" );
200 $this->setUserPerm( "" );
201 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
202 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ), $res );
203
204 $this->setTitle( NS_FILE, "img.png" );
205 $this->setUserPerm( "movefile" );
206 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
207 $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
208
209 $this->setUser( 'anon' );
210 $this->setTitle( NS_FILE, "img.png" );
211 $this->setUserPerm( "" );
212 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
213 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ), $res );
214
215 $this->setTitle( NS_FILE, "img.png" );
216 $this->setUserPerm( "movefile" );
217 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
218 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
219
220 $this->setUser( $this->userName );
221 $this->setUserPerm( "move" );
222 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
223
224 $this->setUserPerm( "" );
225 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ) );
226
227 $this->setUser( 'anon' );
228 $this->setUserPerm( "move" );
229 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
230
231 $this->setUserPerm( "" );
232 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ),
233 array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ) );
234
235 if ( $this->isWikitextNS( NS_MAIN ) ) {
236 //NOTE: some content models don't allow moving
237 //@todo: find a Wikitext namespace for testing
238
239 $this->setTitle( NS_MAIN );
240 $this->setUser( 'anon' );
241 $this->setUserPerm( "move" );
242 $this->runGroupPermissions( 'move', array( ) );
243
244 $this->setUserPerm( "" );
245 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ),
246 array( array( 'movenologintext' ) ) );
247
248 $this->setUser( $this->userName );
249 $this->setUserPerm( "" );
250 $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ) );
251
252 $this->setUserPerm( "move" );
253 $this->runGroupPermissions( 'move', array( ) );
254
255 $this->setUser( 'anon' );
256 $this->setUserPerm( 'move' );
257 $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
258 $this->assertEquals( array( ), $res );
259
260 $this->setUserPerm( '' );
261 $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
262 $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
263 }
264
265 $this->setTitle( NS_USER );
266 $this->setUser( $this->userName );
267 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
268 $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
269 $this->assertEquals( array( ), $res );
270
271 $this->setUserPerm( "move" );
272 $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
273 $this->assertEquals( array( array( 'cant-move-to-user-page' ) ), $res );
274
275 $this->setUser( 'anon' );
276 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
277 $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
278 $this->assertEquals( array( ), $res );
279
280 $this->setTitle( NS_USER, "User/subpage" );
281 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
282 $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
283 $this->assertEquals( array( ), $res );
284
285 $this->setUserPerm( "move" );
286 $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
287 $this->assertEquals( array( ), $res );
288
289 $this->setUser( 'anon' );
290 $check = array( 'edit' => array( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ) ),
291 array( array( 'badaccess-group0' ) ),
292 array( ), true ),
293 'protect' => array( array( array( 'badaccess-groups', "[[$prefix:Administrators|Administrators]]", 1 ), array( 'protect-cantedit' ) ),
294 array( array( 'badaccess-group0' ), array( 'protect-cantedit' ) ),
295 array( array( 'protect-cantedit' ) ), false ),
296 '' => array( array( ), array( ), array( ), true ) );
297
298 foreach ( array( "edit", "protect", "" ) as $action ) {
299 $this->setUserPerm( null );
300 $this->assertEquals( $check[$action][0],
301 $this->title->getUserPermissionsErrors( $action, $this->user, true ) );
302
303 global $wgGroupPermissions;
304 $old = $wgGroupPermissions;
305 $wgGroupPermissions = array();
306
307 $this->assertEquals( $check[$action][1],
308 $this->title->getUserPermissionsErrors( $action, $this->user, true ) );
309 $wgGroupPermissions = $old;
310
311 $this->setUserPerm( $action );
312 $this->assertEquals( $check[$action][2],
313 $this->title->getUserPermissionsErrors( $action, $this->user, true ) );
314
315 $this->setUserPerm( $action );
316 $this->assertEquals( $check[$action][3],
317 $this->title->userCan( $action, $this->user, true ) );
318 $this->assertEquals( $check[$action][3],
319 $this->title->quickUserCan( $action, $this->user ) );
320
321 # count( User::getGroupsWithPermissions( $action ) ) < 1
322 }
323 }
324
325 function runGroupPermissions( $action, $result, $result2 = null ) {
326 global $wgGroupPermissions;
327
328 if ( $result2 === null ) $result2 = $result;
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
542 function testActionPermissions() {
543 $this->setUserPerm( array( "createpage" ) );
544 $this->setTitle( NS_MAIN, "test page" );
545 $this->title->mTitleProtection['pt_create_perm'] = '';
546 $this->title->mTitleProtection['pt_user'] = $this->user->getID();
547 $this->title->mTitleProtection['pt_expiry'] = wfGetDB( DB_SLAVE )->getInfinity();
548 $this->title->mTitleProtection['pt_reason'] = 'test';
549 $this->title->mCascadeRestriction = false;
550
551 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
552 $this->title->getUserPermissionsErrors( 'create', $this->user ) );
553 $this->assertEquals( false,
554 $this->title->userCan( 'create', $this->user ) );
555
556 $this->title->mTitleProtection['pt_create_perm'] = 'sysop';
557 $this->setUserPerm( array( 'createpage', 'protect' ) );
558 $this->assertEquals( array( ),
559 $this->title->getUserPermissionsErrors( 'create', $this->user ) );
560 $this->assertEquals( true,
561 $this->title->userCan( 'create', $this->user ) );
562
563
564 $this->setUserPerm( array( 'createpage' ) );
565 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
566 $this->title->getUserPermissionsErrors( 'create', $this->user ) );
567 $this->assertEquals( false,
568 $this->title->userCan( 'create', $this->user ) );
569
570 $this->setTitle( NS_MEDIA, "test page" );
571 $this->setUserPerm( array( "move" ) );
572 $this->assertEquals( false,
573 $this->title->userCan( 'move', $this->user ) );
574 $this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ),
575 $this->title->getUserPermissionsErrors( 'move', $this->user ) );
576
577 $this->setTitle( NS_HELP, "test page" );
578 $this->assertEquals( array( ),
579 $this->title->getUserPermissionsErrors( 'move', $this->user ) );
580 $this->assertEquals( true,
581 $this->title->userCan( 'move', $this->user ) );
582
583 $this->title->mInterwiki = "no";
584 $this->assertEquals( array( array( 'immobile-source-page' ) ),
585 $this->title->getUserPermissionsErrors( 'move', $this->user ) );
586 $this->assertEquals( false,
587 $this->title->userCan( 'move', $this->user ) );
588
589 $this->setTitle( NS_MEDIA, "test page" );
590 $this->assertEquals( false,
591 $this->title->userCan( 'move-target', $this->user ) );
592 $this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ),
593 $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
594
595 $this->setTitle( NS_HELP, "test page" );
596 $this->assertEquals( array( ),
597 $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
598 $this->assertEquals( true,
599 $this->title->userCan( 'move-target', $this->user ) );
600
601 $this->title->mInterwiki = "no";
602 $this->assertEquals( array( array( 'immobile-target-page' ) ),
603 $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
604 $this->assertEquals( false,
605 $this->title->userCan( 'move-target', $this->user ) );
606
607 }
608
609 function testUserBlock() {
610 global $wgEmailConfirmToEdit, $wgEmailAuthentication;
611 $wgEmailConfirmToEdit = true;
612 $wgEmailAuthentication = true;
613
614 $this->setUserPerm( array( "createpage", "move" ) );
615 $this->setTitle( NS_HELP, "test page" );
616
617 # $short
618 $this->assertEquals( array( array( 'confirmedittext' ) ),
619 $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
620 $wgEmailConfirmToEdit = false;
621 $this->assertEquals( true, $this->title->userCan( 'move-target', $this->user ) );
622
623 # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
624 $this->assertEquals( array( ),
625 $this->title->getUserPermissionsErrors( 'move-target',
626 $this->user ) );
627
628 global $wgLang;
629 $prev = time();
630 $now = time() + 120;
631 $this->user->mBlockedby = $this->user->getId();
632 $this->user->mBlock = new Block( '127.0.8.1', 0, $this->user->getId(),
633 'no reason given', $prev + 3600, 1, 0 );
634 $this->user->mBlock->mTimestamp = 0;
635 $this->assertEquals( array( array( 'autoblockedtext',
636 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
637 'Useruser', null, 'infinite', '127.0.8.1',
638 $wgLang->timeanddate( wfTimestamp( TS_MW, $prev ), true ) ) ),
639 $this->title->getUserPermissionsErrors( 'move-target',
640 $this->user ) );
641
642 $this->assertEquals( false, $this->title->userCan( 'move-target', $this->user ) );
643 // quickUserCan should ignore user blocks
644 $this->assertEquals( true, $this->title->quickUserCan( 'move-target', $this->user ) );
645
646 global $wgLocalTZoffset;
647 $wgLocalTZoffset = -60;
648 $this->user->mBlockedby = $this->user->getName();
649 $this->user->mBlock = new Block( '127.0.8.1', 0, 1, 'no reason given', $now, 0, 10 );
650 $this->assertEquals( array( array( 'blockedtext',
651 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
652 'Useruser', null, '23:00, 31 December 1969', '127.0.8.1',
653 $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ) ),
654 $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
655
656 # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
657 # $user->blockedFor() == ''
658 # $user->mBlock->mExpiry == 'infinity'
659 }
660 }