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