ac58d68c57c266e03c5904a1bf317964cb9936f9
[lhc/web/wiklou.git] / tests / phpunit / includes / specials / SpecialPreferencesTest.php
1 <?php
2 /**
3 * Test class for SpecialPreferences class.
4 *
5 * Copyright © 2013, Antoine Musso
6 * Copyright © 2013, Wikimedia Foundation Inc.
7 */
8
9 /**
10 * @group Database
11 *
12 * @covers SpecialPreferences
13 */
14 class SpecialPreferencesTest extends MediaWikiTestCase {
15
16 /**
17 * Make sure a nickname which is longer than $wgMaxSigChars
18 * is not throwing a fatal error.
19 *
20 * Test specifications by Alexandre "ialex" Emsenhuber.
21 * @todo give this test a real name explaining what is being tested here
22 */
23 public function testBug41337() {
24 // Set a low limit
25 $this->setMwGlobals( 'wgMaxSigChars', 2 );
26
27 $user = $this->createMock( 'User' );
28 $user->expects( $this->any() )
29 ->method( 'isAnon' )
30 ->will( $this->returnValue( false ) );
31
32 # Yeah foreach requires an array, not NULL =(
33 $user->expects( $this->any() )
34 ->method( 'getEffectiveGroups' )
35 ->will( $this->returnValue( [] ) );
36
37 # The mocked user has a long nickname
38 $user->expects( $this->any() )
39 ->method( 'getOption' )
40 ->will( $this->returnValueMap( [
41 [ 'nickname', null, false, 'superlongnickname' ],
42 ]
43 ) );
44
45 # Forge a request to call the special page
46 $context = new RequestContext();
47 $context->setRequest( new FauxRequest() );
48 $context->setUser( $user );
49 $context->setTitle( Title::newFromText( 'Test' ) );
50
51 # Do the call, should not spurt a fatal error.
52 $special = new SpecialPreferences();
53 $special->setContext( $context );
54 $this->assertNull( $special->execute( [] ) );
55 }
56
57 }