File: SpecialPreferencesTest.php

package info (click to toggle)
mediawiki 1%3A1.43.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 417,464 kB
  • sloc: php: 1,062,949; javascript: 664,290; sql: 9,714; python: 5,458; xml: 3,489; sh: 1,131; makefile: 64
file content (59 lines) | stat: -rw-r--r-- 1,828 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/**
 * Test class for SpecialPreferences class.
 *
 * Copyright © 2013, Antoine Musso
 * Copyright © 2013, Wikimedia Foundation Inc.
 */

use MediaWiki\MainConfigNames;
use MediaWiki\Specials\SpecialPreferences;
use MediaWiki\User\Options\UserOptionsManager;

/**
 * @group Preferences
 * @group Database
 *
 * @covers \MediaWiki\Specials\SpecialPreferences
 */
class SpecialPreferencesTest extends SpecialPageTestBase {
	/**
	 * HACK: use this variable to override UserOptionsManager for use in the special page. Ideally we'd just do
	 * $this->setService, but that's super hard because some places that use UserOptionsManager read a lot from the
	 * global state and a mock would need to be super-complex for all the various checks to work.
	 */
	private ?UserOptionsManager $userOptionsManager = null;

	protected function tearDown(): void {
		$this->userOptionsManager = null;
		parent::tearDown();
	}

	protected function newSpecialPage() {
		return new SpecialPreferences(
			$this->getServiceContainer()->getPreferencesFactory(),
			$this->userOptionsManager ?? $this->getServiceContainer()->getUserOptionsManager()
		);
	}

	/**
	 * Make sure a username which is longer than $wgMaxSigChars
	 * is not throwing a fatal error (T43337).
	 */
	public function testLongUsernameDoesNotFatal() {
		$maxSigChars = 2;
		$this->overrideConfigValue( MainConfigNames::MaxSigChars, $maxSigChars );
		$nickname = str_repeat( 'x', $maxSigChars + 1 );
		$user = $this->getMutableTestUser()->getUser();

		$this->userOptionsManager = $this->createMock( UserOptionsManager::class );
		$this->userOptionsManager->method( 'getOption' )
			->with( $user, 'nickname' )
			->willReturn( $nickname );

		$this->executeSpecialPage( '', null, null, $user );
		// We assert that no error is thrown
		$this->addToAssertionCount( 1 );
	}

}