Merge "(bug 41042) Regression: API action=parse with nonexistent page"
[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 'wgLang' => $langObj,
34 'wgLocaltimezone' => $localZone,
35 'wgLocalTZoffset' => $localOffset,
36 'wgNamespaceProtection' => array(
37 NS_MEDIAWIKI => 'editinterface',
38 ),
39 ) );
40
41 $this->userName = 'Useruser';
42 $this->altUserName = 'Altuseruser';
43 date_default_timezone_set( $localZone );
44
45 $this->title = Title::makeTitle( NS_MAIN, "Main Page" );
46 if ( !isset( $this->userUser ) || !( $this->userUser instanceOf User ) ) {
47 $this->userUser = User::newFromName( $this->userName );
48
49 if ( !$this->userUser->getID() ) {
50 $this->userUser = User::createNew( $this->userName, array(
51 "email" => "test@example.com",
52 "real_name" => "Test User" ) );
53 $this->userUser->load();
54 }
55
56 $this->altUser = User::newFromName( $this->altUserName );
57 if ( !$this->altUser->getID() ) {
58 $this->altUser = User::createNew( $this->altUserName, array(
59 "email" => "alttest@example.com",
60 "real_name" => "Test User Alt" ) );
61 $this->altUser->load();
62 }
63
64 $this->anonUser = User::newFromId( 0 );
65
66 $this->user = $this->userUser;
67 }
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
320 # count( User::getGroupsWithPermissions( $action ) ) < 1
321 }
322 }
323
324 function runGroupPermissions( $action, $result, $result2 = null ) {
325 global $wgGroupPermissions;
326
327 if ( $result2 === null ) $result2 = $result;
328
329 $wgGroupPermissions['autoconfirmed']['move'] = false;
330 $wgGroupPermissions['user']['move'] = false;
331 $res = $this->title->getUserPermissionsErrors( $action, $this->user );
332 $this->assertEquals( $result, $res );
333
334 $wgGroupPermissions['autoconfirmed']['move'] = true;
335 $wgGroupPermissions['user']['move'] = false;
336 $res = $this->title->getUserPermissionsErrors( $action, $this->user );
337 $this->assertEquals( $result2, $res );
338
339 $wgGroupPermissions['autoconfirmed']['move'] = true;
340 $wgGroupPermissions['user']['move'] = true;
341 $res = $this->title->getUserPermissionsErrors( $action, $this->user );
342 $this->assertEquals( $result2, $res );
343
344 $wgGroupPermissions['autoconfirmed']['move'] = false;
345 $wgGroupPermissions['user']['move'] = true;
346 $res = $this->title->getUserPermissionsErrors( $action, $this->user );
347 $this->assertEquals( $result2, $res );
348 }
349
350 function testSpecialsAndNSPermissions() {
351 global $wgNamespaceProtection;
352 $this->setUser( $this->userName );
353
354 $this->setTitle( NS_SPECIAL );
355
356 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'ns-specialprotected' ) ),
357 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
358 $this->assertEquals( array( array( 'badaccess-group0' ) ),
359 $this->title->getUserPermissionsErrors( 'execute', $this->user ) );
360
361 $this->setTitle( NS_MAIN );
362 $this->setUserPerm( 'bogus' );
363 $this->assertEquals( array( ),
364 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
365
366 $this->setTitle( NS_MAIN );
367 $this->setUserPerm( '' );
368 $this->assertEquals( array( array( 'badaccess-group0' ) ),
369 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
370
371 $wgNamespaceProtection[NS_USER] = array( 'bogus' );
372
373 $this->setTitle( NS_USER );
374 $this->setUserPerm( '' );
375 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'namespaceprotected', 'User' ) ),
376 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
377
378 $this->setTitle( NS_MEDIAWIKI );
379 $this->setUserPerm( 'bogus' );
380 $this->assertEquals( array( array( 'protectedinterface' ) ),
381 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
382
383 $this->setTitle( NS_MEDIAWIKI );
384 $this->setUserPerm( 'bogus' );
385 $this->assertEquals( array( array( 'protectedinterface' ) ),
386 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
387
388 $wgNamespaceProtection = null;
389
390 $this->setUserPerm( 'bogus' );
391 $this->assertEquals( array( ),
392 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
393 $this->assertEquals( true,
394 $this->title->userCan( 'bogus', $this->user ) );
395
396 $this->setUserPerm( '' );
397 $this->assertEquals( array( array( 'badaccess-group0' ) ),
398 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
399 $this->assertEquals( false,
400 $this->title->userCan( 'bogus', $this->user ) );
401 }
402
403 function testCssAndJavascriptPermissions() {
404 $this->setUser( $this->userName );
405
406 $this->setTitle( NS_USER, $this->altUserName . '/test.js' );
407 $this->runCSSandJSPermissions(
408 array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
409 array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
410 array( array( 'badaccess-group0' ) ) );
411
412 $this->setTitle( NS_USER, $this->altUserName . '/test.css' );
413 $this->runCSSandJSPermissions(
414 array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ),
415 array( array( 'badaccess-group0' ) ),
416 array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ) );
417
418 $this->setTitle( NS_USER, $this->altUserName . '/tempo' );
419 $this->runCSSandJSPermissions(
420 array( array( 'badaccess-group0' ) ),
421 array( array( 'badaccess-group0' ) ),
422 array( array( 'badaccess-group0' ) ) );
423 }
424
425 function runCSSandJSPermissions( $result0, $result1, $result2 ) {
426 $this->setUserPerm( '' );
427 $this->assertEquals( $result0,
428 $this->title->getUserPermissionsErrors( 'bogus',
429 $this->user ) );
430
431 $this->setUserPerm( 'editusercss' );
432 $this->assertEquals( $result1,
433 $this->title->getUserPermissionsErrors( 'bogus',
434 $this->user ) );
435
436 $this->setUserPerm( 'edituserjs' );
437 $this->assertEquals( $result2,
438 $this->title->getUserPermissionsErrors( 'bogus',
439 $this->user ) );
440
441 $this->setUserPerm( 'editusercssjs' );
442 $this->assertEquals( array( array( 'badaccess-group0' ) ),
443 $this->title->getUserPermissionsErrors( 'bogus',
444 $this->user ) );
445
446 $this->setUserPerm( array( 'edituserjs', 'editusercss' ) );
447 $this->assertEquals( array( array( 'badaccess-group0' ) ),
448 $this->title->getUserPermissionsErrors( 'bogus',
449 $this->user ) );
450 }
451
452 function testPageRestrictions() {
453 global $wgContLang;
454
455 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT );
456
457 $this->setTitle( NS_MAIN );
458 $this->title->mRestrictionsLoaded = true;
459 $this->setUserPerm( "edit" );
460 $this->title->mRestrictions = array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
461
462 $this->assertEquals( array( ),
463 $this->title->getUserPermissionsErrors( 'edit',
464 $this->user ) );
465
466 $this->assertEquals( true,
467 $this->title->quickUserCan( 'edit', $this->user ) );
468 $this->title->mRestrictions = array( "edit" => array( 'bogus', "sysop", "protect", "" ),
469 "bogus" => array( 'bogus', "sysop", "protect", "" ) );
470
471 $this->assertEquals( array( array( 'badaccess-group0' ),
472 array( 'protectedpagetext', 'bogus' ),
473 array( 'protectedpagetext', 'protect' ),
474 array( 'protectedpagetext', 'protect' ) ),
475 $this->title->getUserPermissionsErrors( 'bogus',
476 $this->user ) );
477 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
478 array( 'protectedpagetext', 'protect' ),
479 array( 'protectedpagetext', 'protect' ) ),
480 $this->title->getUserPermissionsErrors( 'edit',
481 $this->user ) );
482 $this->setUserPerm( "" );
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( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ),
490 array( 'protectedpagetext', 'bogus' ),
491 array( 'protectedpagetext', 'protect' ),
492 array( 'protectedpagetext', 'protect' ) ),
493 $this->title->getUserPermissionsErrors( 'edit',
494 $this->user ) );
495 $this->setUserPerm( array( "edit", "editprotected" ) );
496 $this->assertEquals( array( array( 'badaccess-group0' ),
497 array( 'protectedpagetext', 'bogus' ),
498 array( 'protectedpagetext', 'protect' ),
499 array( 'protectedpagetext', 'protect' ) ),
500 $this->title->getUserPermissionsErrors( 'bogus',
501 $this->user ) );
502 $this->assertEquals( array( ),
503 $this->title->getUserPermissionsErrors( 'edit',
504 $this->user ) );
505 $this->title->mCascadeRestriction = true;
506 $this->assertEquals( false,
507 $this->title->quickUserCan( 'bogus', $this->user ) );
508 $this->assertEquals( false,
509 $this->title->quickUserCan( 'edit', $this->user ) );
510 $this->assertEquals( array( array( 'badaccess-group0' ),
511 array( 'protectedpagetext', 'bogus' ),
512 array( 'protectedpagetext', 'protect' ),
513 array( 'protectedpagetext', 'protect' ) ),
514 $this->title->getUserPermissionsErrors( 'bogus',
515 $this->user ) );
516 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
517 array( 'protectedpagetext', 'protect' ),
518 array( 'protectedpagetext', 'protect' ) ),
519 $this->title->getUserPermissionsErrors( 'edit',
520 $this->user ) );
521 }
522
523 function testCascadingSourcesRestrictions() {
524 $this->setTitle( NS_MAIN, "test page" );
525 $this->setUserPerm( array( "edit", "bogus" ) );
526
527 $this->title->mCascadeSources = array( Title::makeTitle( NS_MAIN, "Bogus" ), Title::makeTitle( NS_MAIN, "UnBogus" ) );
528 $this->title->mCascadingRestrictions = array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
529
530 $this->assertEquals( false,
531 $this->title->userCan( 'bogus', $this->user ) );
532 $this->assertEquals( array( array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ),
533 array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ) ),
534 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
535
536 $this->assertEquals( true,
537 $this->title->userCan( 'edit', $this->user ) );
538 $this->assertEquals( array( ),
539 $this->title->getUserPermissionsErrors( 'edit', $this->user ) );
540
541 }
542
543 function testActionPermissions() {
544 $this->setUserPerm( array( "createpage" ) );
545 $this->setTitle( NS_MAIN, "test page" );
546 $this->title->mTitleProtection['pt_create_perm'] = '';
547 $this->title->mTitleProtection['pt_user'] = $this->user->getID();
548 $this->title->mTitleProtection['pt_expiry'] = wfGetDB( DB_SLAVE )->getInfinity();
549 $this->title->mTitleProtection['pt_reason'] = 'test';
550 $this->title->mCascadeRestriction = false;
551
552 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
553 $this->title->getUserPermissionsErrors( 'create', $this->user ) );
554 $this->assertEquals( false,
555 $this->title->userCan( 'create', $this->user ) );
556
557 $this->title->mTitleProtection['pt_create_perm'] = 'sysop';
558 $this->setUserPerm( array( 'createpage', 'protect' ) );
559 $this->assertEquals( array( ),
560 $this->title->getUserPermissionsErrors( 'create', $this->user ) );
561 $this->assertEquals( true,
562 $this->title->userCan( 'create', $this->user ) );
563
564
565 $this->setUserPerm( array( 'createpage' ) );
566 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
567 $this->title->getUserPermissionsErrors( 'create', $this->user ) );
568 $this->assertEquals( false,
569 $this->title->userCan( 'create', $this->user ) );
570
571 $this->setTitle( NS_MEDIA, "test page" );
572 $this->setUserPerm( array( "move" ) );
573 $this->assertEquals( false,
574 $this->title->userCan( 'move', $this->user ) );
575 $this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ),
576 $this->title->getUserPermissionsErrors( 'move', $this->user ) );
577
578 $this->setTitle( NS_HELP, "test page" );
579 $this->assertEquals( array( ),
580 $this->title->getUserPermissionsErrors( 'move', $this->user ) );
581 $this->assertEquals( true,
582 $this->title->userCan( 'move', $this->user ) );
583
584 $this->title->mInterwiki = "no";
585 $this->assertEquals( array( array( 'immobile-source-page' ) ),
586 $this->title->getUserPermissionsErrors( 'move', $this->user ) );
587 $this->assertEquals( false,
588 $this->title->userCan( 'move', $this->user ) );
589
590 $this->setTitle( NS_MEDIA, "test page" );
591 $this->assertEquals( false,
592 $this->title->userCan( 'move-target', $this->user ) );
593 $this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ),
594 $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
595
596 $this->setTitle( NS_HELP, "test page" );
597 $this->assertEquals( array( ),
598 $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
599 $this->assertEquals( true,
600 $this->title->userCan( 'move-target', $this->user ) );
601
602 $this->title->mInterwiki = "no";
603 $this->assertEquals( array( array( 'immobile-target-page' ) ),
604 $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
605 $this->assertEquals( false,
606 $this->title->userCan( 'move-target', $this->user ) );
607
608 }
609
610 function testUserBlock() {
611 global $wgEmailConfirmToEdit, $wgEmailAuthentication;
612 $wgEmailConfirmToEdit = true;
613 $wgEmailAuthentication = true;
614
615 $this->setUserPerm( array( "createpage", "move" ) );
616 $this->setTitle( NS_HELP, "test page" );
617
618 # $short
619 $this->assertEquals( array( array( 'confirmedittext' ) ),
620 $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
621 $wgEmailConfirmToEdit = false;
622 $this->assertEquals( true, $this->title->userCan( 'move-target', $this->user ) );
623
624 # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
625 $this->assertEquals( array( ),
626 $this->title->getUserPermissionsErrors( 'move-target',
627 $this->user ) );
628
629 global $wgLang;
630 $prev = time();
631 $now = time() + 120;
632 $this->user->mBlockedby = $this->user->getId();
633 $this->user->mBlock = new Block( '127.0.8.1', 0, $this->user->getId(),
634 'no reason given', $prev + 3600, 1, 0 );
635 $this->user->mBlock->mTimestamp = 0;
636 $this->assertEquals( array( array( 'autoblockedtext',
637 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
638 'Useruser', null, 'infinite', '127.0.8.1',
639 $wgLang->timeanddate( wfTimestamp( TS_MW, $prev ), true ) ) ),
640 $this->title->getUserPermissionsErrors( 'move-target',
641 $this->user ) );
642
643 $this->assertEquals( false, $this->title->userCan( 'move-target', $this->user ) );
644 // quickUserCan should ignore user blocks
645 $this->assertEquals( true, $this->title->quickUserCan( 'move-target', $this->user ) );
646
647 global $wgLocalTZoffset;
648 $wgLocalTZoffset = -60;
649 $this->user->mBlockedby = $this->user->getName();
650 $this->user->mBlock = new Block( '127.0.8.1', 0, 1, 'no reason given', $now, 0, 10 );
651 $this->assertEquals( array( array( 'blockedtext',
652 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
653 'Useruser', null, '23:00, 31 December 1969', '127.0.8.1',
654 $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ) ),
655 $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
656
657 # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
658 # $user->blockedFor() == ''
659 # $user->mBlock->mExpiry == 'infinity'
660 }
661 }