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