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