Merge "Throw if Redis::SERIALIZER_IGBINARY is not defined"
[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 testT43337() {
25 // Set a low limit
26 $this->setMwGlobals( 'wgMaxSigChars', 2 );
27 $user = $this->createMock( User::class );
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 # Needs to return something
46 $user->method( 'getOptions' )
47 ->willReturn( [] );
48
49 // isAnyAllowed used to return null from the mock,
50 // thus revoke it's permissions.
51 $this->overrideUserPermissions( $user, [] );
52
53 # Forge a request to call the special page
54 $context = new RequestContext();
55 $context->setRequest( new FauxRequest() );
56 $context->setUser( $user );
57 $context->setTitle( Title::newFromText( 'Test' ) );
58
59 # Do the call, should not spurt a fatal error.
60 $special = new SpecialPreferences();
61 $special->setContext( $context );
62 $this->assertNull( $special->execute( [] ) );
63 }
64
65 }