Merge "(bug 37755) Set robot meta tags for 'view source' pages"
[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 $this->assertEquals( array( array( 'badaccess-group0' ) ),
360 $this->title->getUserPermissionsErrors( 'execute', $this->user ) );
361
362 $this->setTitle( NS_MAIN );
363 $this->setUserPerm( 'bogus' );
364 $this->assertEquals( array( ),
365 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
366
367 $this->setTitle( NS_MAIN );
368 $this->setUserPerm( '' );
369 $this->assertEquals( array( array( 'badaccess-group0' ) ),
370 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
371
372 $wgNamespaceProtection[NS_USER] = array( 'bogus' );
373
374 $this->setTitle( NS_USER );
375 $this->setUserPerm( '' );
376 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'namespaceprotected', 'User' ) ),
377 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
378
379 $this->setTitle( NS_MEDIAWIKI );
380 $this->setUserPerm( 'bogus' );
381 $this->assertEquals( array( array( 'protectedinterface' ) ),
382 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
383
384 $this->setTitle( NS_MEDIAWIKI );
385 $this->setUserPerm( 'bogus' );
386 $this->assertEquals( array( array( 'protectedinterface' ) ),
387 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
388
389 $wgNamespaceProtection = null;
390
391 $this->setUserPerm( 'bogus' );
392 $this->assertEquals( array( ),
393 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
394 $this->assertEquals( true,
395 $this->title->userCan( 'bogus', $this->user ) );
396
397 $this->setUserPerm( '' );
398 $this->assertEquals( array( array( 'badaccess-group0' ) ),
399 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
400 $this->assertEquals( false,
401 $this->title->userCan( 'bogus', $this->user ) );
402 }
403
404 function testCssAndJavascriptPermissions() {
405 $this->setUser( $this->userName );
406
407 $this->setTitle( NS_USER, $this->altUserName . '/test.js' );
408 $this->runCSSandJSPermissions(
409 array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
410 array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
411 array( array( 'badaccess-group0' ) ) );
412
413 $this->setTitle( NS_USER, $this->altUserName . '/test.css' );
414 $this->runCSSandJSPermissions(
415 array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ),
416 array( array( 'badaccess-group0' ) ),
417 array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ) );
418
419 $this->setTitle( NS_USER, $this->altUserName . '/tempo' );
420 $this->runCSSandJSPermissions(
421 array( array( 'badaccess-group0' ) ),
422 array( array( 'badaccess-group0' ) ),
423 array( array( 'badaccess-group0' ) ) );
424 }
425
426 function runCSSandJSPermissions( $result0, $result1, $result2 ) {
427 $this->setUserPerm( '' );
428 $this->assertEquals( $result0,
429 $this->title->getUserPermissionsErrors( 'bogus',
430 $this->user ) );
431
432 $this->setUserPerm( 'editusercss' );
433 $this->assertEquals( $result1,
434 $this->title->getUserPermissionsErrors( 'bogus',
435 $this->user ) );
436
437 $this->setUserPerm( 'edituserjs' );
438 $this->assertEquals( $result2,
439 $this->title->getUserPermissionsErrors( 'bogus',
440 $this->user ) );
441
442 $this->setUserPerm( 'editusercssjs' );
443 $this->assertEquals( array( array( 'badaccess-group0' ) ),
444 $this->title->getUserPermissionsErrors( 'bogus',
445 $this->user ) );
446
447 $this->setUserPerm( array( 'edituserjs', 'editusercss' ) );
448 $this->assertEquals( array( array( 'badaccess-group0' ) ),
449 $this->title->getUserPermissionsErrors( 'bogus',
450 $this->user ) );
451 }
452
453 function testPageRestrictions() {
454 global $wgContLang;
455
456 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT );
457
458 $this->setTitle( NS_MAIN );
459 $this->title->mRestrictionsLoaded = true;
460 $this->setUserPerm( "edit" );
461 $this->title->mRestrictions = array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
462
463 $this->assertEquals( array( ),
464 $this->title->getUserPermissionsErrors( 'edit',
465 $this->user ) );
466
467 $this->assertEquals( true,
468 $this->title->quickUserCan( 'edit', $this->user ) );
469 $this->title->mRestrictions = array( "edit" => array( 'bogus', "sysop", "protect", "" ),
470 "bogus" => array( 'bogus', "sysop", "protect", "" ) );
471
472 $this->assertEquals( array( array( 'badaccess-group0' ),
473 array( 'protectedpagetext', 'bogus' ),
474 array( 'protectedpagetext', 'protect' ),
475 array( 'protectedpagetext', 'protect' ) ),
476 $this->title->getUserPermissionsErrors( 'bogus',
477 $this->user ) );
478 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
479 array( 'protectedpagetext', 'protect' ),
480 array( 'protectedpagetext', 'protect' ) ),
481 $this->title->getUserPermissionsErrors( 'edit',
482 $this->user ) );
483 $this->setUserPerm( "" );
484 $this->assertEquals( array( array( 'badaccess-group0' ),
485 array( 'protectedpagetext', 'bogus' ),
486 array( 'protectedpagetext', 'protect' ),
487 array( 'protectedpagetext', 'protect' ) ),
488 $this->title->getUserPermissionsErrors( 'bogus',
489 $this->user ) );
490 $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ),
491 array( 'protectedpagetext', 'bogus' ),
492 array( 'protectedpagetext', 'protect' ),
493 array( 'protectedpagetext', 'protect' ) ),
494 $this->title->getUserPermissionsErrors( 'edit',
495 $this->user ) );
496 $this->setUserPerm( array( "edit", "editprotected" ) );
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( ),
504 $this->title->getUserPermissionsErrors( 'edit',
505 $this->user ) );
506 $this->title->mCascadeRestriction = true;
507 $this->assertEquals( false,
508 $this->title->quickUserCan( 'bogus', $this->user ) );
509 $this->assertEquals( false,
510 $this->title->quickUserCan( 'edit', $this->user ) );
511 $this->assertEquals( array( array( 'badaccess-group0' ),
512 array( 'protectedpagetext', 'bogus' ),
513 array( 'protectedpagetext', 'protect' ),
514 array( 'protectedpagetext', 'protect' ) ),
515 $this->title->getUserPermissionsErrors( 'bogus',
516 $this->user ) );
517 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
518 array( 'protectedpagetext', 'protect' ),
519 array( 'protectedpagetext', 'protect' ) ),
520 $this->title->getUserPermissionsErrors( 'edit',
521 $this->user ) );
522 }
523
524 function testCascadingSourcesRestrictions() {
525 $this->setTitle( NS_MAIN, "test page" );
526 $this->setUserPerm( array( "edit", "bogus" ) );
527
528 $this->title->mCascadeSources = array( Title::makeTitle( NS_MAIN, "Bogus" ), Title::makeTitle( NS_MAIN, "UnBogus" ) );
529 $this->title->mCascadingRestrictions = array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
530
531 $this->assertEquals( false,
532 $this->title->userCan( 'bogus', $this->user ) );
533 $this->assertEquals( array( array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ),
534 array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ) ),
535 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
536
537 $this->assertEquals( true,
538 $this->title->userCan( 'edit', $this->user ) );
539 $this->assertEquals( array( ),
540 $this->title->getUserPermissionsErrors( 'edit', $this->user ) );
541
542 }
543
544 function testActionPermissions() {
545 $this->setUserPerm( array( "createpage" ) );
546 $this->setTitle( NS_MAIN, "test page" );
547 $this->title->mTitleProtection['pt_create_perm'] = '';
548 $this->title->mTitleProtection['pt_user'] = $this->user->getID();
549 $this->title->mTitleProtection['pt_expiry'] = wfGetDB( DB_SLAVE )->getInfinity();
550 $this->title->mTitleProtection['pt_reason'] = 'test';
551 $this->title->mCascadeRestriction = false;
552
553 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
554 $this->title->getUserPermissionsErrors( 'create', $this->user ) );
555 $this->assertEquals( false,
556 $this->title->userCan( 'create', $this->user ) );
557
558 $this->title->mTitleProtection['pt_create_perm'] = 'sysop';
559 $this->setUserPerm( array( 'createpage', 'protect' ) );
560 $this->assertEquals( array( ),
561 $this->title->getUserPermissionsErrors( 'create', $this->user ) );
562 $this->assertEquals( true,
563 $this->title->userCan( 'create', $this->user ) );
564
565
566 $this->setUserPerm( array( 'createpage' ) );
567 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
568 $this->title->getUserPermissionsErrors( 'create', $this->user ) );
569 $this->assertEquals( false,
570 $this->title->userCan( 'create', $this->user ) );
571
572 $this->setTitle( NS_MEDIA, "test page" );
573 $this->setUserPerm( array( "move" ) );
574 $this->assertEquals( false,
575 $this->title->userCan( 'move', $this->user ) );
576 $this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ),
577 $this->title->getUserPermissionsErrors( 'move', $this->user ) );
578
579 $this->setTitle( NS_HELP, "test page" );
580 $this->assertEquals( array( ),
581 $this->title->getUserPermissionsErrors( 'move', $this->user ) );
582 $this->assertEquals( true,
583 $this->title->userCan( 'move', $this->user ) );
584
585 $this->title->mInterwiki = "no";
586 $this->assertEquals( array( array( 'immobile-source-page' ) ),
587 $this->title->getUserPermissionsErrors( 'move', $this->user ) );
588 $this->assertEquals( false,
589 $this->title->userCan( 'move', $this->user ) );
590
591 $this->setTitle( NS_MEDIA, "test page" );
592 $this->assertEquals( false,
593 $this->title->userCan( 'move-target', $this->user ) );
594 $this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ),
595 $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
596
597 $this->setTitle( NS_HELP, "test page" );
598 $this->assertEquals( array( ),
599 $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
600 $this->assertEquals( true,
601 $this->title->userCan( 'move-target', $this->user ) );
602
603 $this->title->mInterwiki = "no";
604 $this->assertEquals( array( array( 'immobile-target-page' ) ),
605 $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
606 $this->assertEquals( false,
607 $this->title->userCan( 'move-target', $this->user ) );
608
609 }
610
611 function testUserBlock() {
612 global $wgEmailConfirmToEdit, $wgEmailAuthentication;
613 $wgEmailConfirmToEdit = true;
614 $wgEmailAuthentication = true;
615
616 $this->setUserPerm( array( "createpage", "move" ) );
617 $this->setTitle( NS_HELP, "test page" );
618
619 # $short
620 $this->assertEquals( array( array( 'confirmedittext' ) ),
621 $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
622 $wgEmailConfirmToEdit = false;
623 $this->assertEquals( true, $this->title->userCan( 'move-target', $this->user ) );
624
625 # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
626 $this->assertEquals( array( ),
627 $this->title->getUserPermissionsErrors( 'move-target',
628 $this->user ) );
629
630 global $wgLang;
631 $prev = time();
632 $now = time() + 120;
633 $this->user->mBlockedby = $this->user->getId();
634 $this->user->mBlock = new Block( '127.0.8.1', 0, $this->user->getId(),
635 'no reason given', $prev + 3600, 1, 0 );
636 $this->user->mBlock->mTimestamp = 0;
637 $this->assertEquals( array( array( 'autoblockedtext',
638 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
639 'Useruser', null, 'infinite', '127.0.8.1',
640 $wgLang->timeanddate( wfTimestamp( TS_MW, $prev ), true ) ) ),
641 $this->title->getUserPermissionsErrors( 'move-target',
642 $this->user ) );
643
644 $this->assertEquals( false, $this->title->userCan( 'move-target', $this->user ) );
645 // quickUserCan should ignore user blocks
646 $this->assertEquals( true, $this->title->quickUserCan( 'move-target', $this->user ) );
647
648 global $wgLocalTZoffset;
649 $wgLocalTZoffset = -60;
650 $this->user->mBlockedby = $this->user->getName();
651 $this->user->mBlock = new Block( '127.0.8.1', 0, 1, 'no reason given', $now, 0, 10 );
652 $this->assertEquals( array( array( 'blockedtext',
653 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
654 'Useruser', null, '23:00, 31 December 1969', '127.0.8.1',
655 $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ) ),
656 $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
657
658 # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
659 # $user->blockedFor() == ''
660 # $user->mBlock->mExpiry == 'infinity'
661 }
662 }