Debian Codegraph @

tests/phpunit/includes/specials/SpecialPreferencesTest.php

raw symbols SCIP
1 <?php
2 /**
3 * Test class for SpecialPreferences class.
4 *
5 * Copyright © 2013, Antoine Musso
6 * Copyright © 2013, Wikimedia Foundation Inc.
7 */
8
9 use MediaWiki\MainConfigNames;
10 use MediaWiki\Specials\SpecialPreferences;
11 use MediaWiki\User\Options\UserOptionsManager;
12
13 /**
14 * @group Preferences
15 * @group Database
16 *
17 * @covers \MediaWiki\Specials\SpecialPreferences
18 */
19 class SpecialPreferencesTest extends SpecialPageTestBase {
20 /**
21 * HACK: use this variable to override UserOptionsManager for use in the special page. Ideally we'd just do
22 * $this->setService, but that's super hard because some places that use UserOptionsManager read a lot from the
23 * global state and a mock would need to be super-complex for all the various checks to work.
24 */
25 private ?UserOptionsManager $userOptionsManager = null;
26
27 protected function tearDown(): void {
28 $this->userOptionsManager = null;
29 parent::tearDown();
30 }
31
32 protected function newSpecialPage() {
33 return new SpecialPreferences(
34 $this->getServiceContainer()->getPreferencesFactory(),
35 $this->userOptionsManager ?? $this->getServiceContainer()->getUserOptionsManager()
36 );
37 }
38
39 /**
40 * Make sure a username which is longer than $wgMaxSigChars
41 * is not throwing a fatal error (T43337).
42 */
43 public function testLongUsernameDoesNotFatal() {
44 $maxSigChars = 2;
45 $this->overrideConfigValue( MainConfigNames::MaxSigChars, $maxSigChars );
46 $nickname = str_repeat( 'x', $maxSigChars + 1 );
47 $user = $this->getMutableTestUser()->getUser();
48
49 $this->userOptionsManager = $this->createMock( UserOptionsManager::class );
50 $this->userOptionsManager->method( 'getOption' )
51 ->with( $user, 'nickname' )
52 ->willReturn( $nickname );
53
54 $this->executeSpecialPage( '', null, null, $user );
55 // We assert that no error is thrown
56 $this->addToAssertionCount( 1 );
57 }
58
59 }