Merge "Simplify watchlist edit mode handling"
[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 /**
11 * @covers SpecialPreferences
12 */
13 class SpecialPreferencesTest extends MediaWikiTestCase {
14
15 /**
16 * Make sure a nickname which is longer than $wgMaxSigChars
17 * is not throwing a fatal error.
18 *
19 * Test specifications by Alexandre "ialex" Emsenhuber.
20 */
21 public function testBug41337() {
22
23 // Set a low limit
24 $this->setMwGlobals( 'wgMaxSigChars', 2 );
25
26 $user = $this->getMock( 'User' );
27 $user->expects( $this->any() )
28 ->method( 'isAnon' )
29 ->will( $this->returnValue( false ) );
30
31 # Yeah foreach requires an array, not NULL =(
32 $user->expects( $this->any() )
33 ->method( 'getEffectiveGroups' )
34 ->will( $this->returnValue( array() ) );
35
36 # The mocked user has a long nickname
37 $user->expects( $this->any() )
38 ->method( 'getOption' )
39 ->will( $this->returnValueMap( array(
40 array( 'nickname', null, false, 'superlongnickname' ),
41 )
42 ) );
43
44 # Validate the mock (FIXME should probably be removed)
45 $this->assertFalse( $user->isAnon() );
46 $this->assertEquals( array(),
47 $user->getEffectiveGroups() );
48 $this->assertEquals( 'superlongnickname',
49 $user->getOption( 'nickname' ) );
50
51 # Forge a request to call the special page
52 $context = new RequestContext();
53 $context->setRequest( new FauxRequest() );
54 $context->setUser( $user );
55 $context->setTitle( Title::newFromText( 'Test' ) );
56
57 # Do the call, should not spurt a fatal error.
58 $special = new SpecialPreferences();
59 $special->setContext( $context );
60 $special->execute( array() );
61 }
62
63 }