3 * Test class for SpecialPreferences class.
5 * Copyright © 2013, Antoine Musso
6 * Copyright © 2013, Wikimedia Foundation Inc.
13 * @covers SpecialPreferences
15 class SpecialPreferencesTest
extends MediaWikiTestCase
{
18 * Make sure a nickname which is longer than $wgMaxSigChars
19 * is not throwing a fatal error.
21 * Test specifications by Alexandre "ialex" Emsenhuber.
22 * @todo give this test a real name explaining what is being tested here
24 public function testT43337() {
26 $this->setMwGlobals( 'wgMaxSigChars', 2 );
27 $user = $this->createMock( User
::class );
28 $user->expects( $this->any() )
30 ->will( $this->returnValue( false ) );
32 # Yeah foreach requires an array, not NULL =(
33 $user->expects( $this->any() )
34 ->method( 'getEffectiveGroups' )
35 ->will( $this->returnValue( [] ) );
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' ],
45 # Needs to return something
46 $user->method( 'getOptions' )
49 // isAnyAllowed used to return null from the mock,
50 // thus revoke it's permissions.
51 $this->overrideUserPermissions( $user, [] );
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' ) );
59 # Do the call, should not spurt a fatal error.
60 $special = new SpecialPreferences();
61 $special->setContext( $context );
62 $this->assertNull( $special->execute( [] ) );