2012-11-01 21:07:37 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Test class for SpecialPreferences class.
|
|
|
|
|
*
|
|
|
|
|
* Copyright © 2013, Antoine Musso
|
|
|
|
|
* Copyright © 2013, Wikimedia Foundation Inc.
|
|
|
|
|
*/
|
|
|
|
|
|
2022-08-14 13:47:11 +00:00
|
|
|
use MediaWiki\MainConfigNames;
|
2022-08-26 20:03:38 +00:00
|
|
|
use MediaWiki\MainConfigSchema;
|
2022-10-28 10:04:25 +00:00
|
|
|
use MediaWiki\Request\FauxRequest;
|
2023-03-01 20:33:26 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2021-12-01 15:21:23 +00:00
|
|
|
use MediaWiki\User\UserOptionsLookup;
|
2022-08-14 13:47:11 +00:00
|
|
|
|
2013-10-24 20:30:43 +00:00
|
|
|
/**
|
2017-11-07 03:10:14 +00:00
|
|
|
* @group Preferences
|
2015-04-01 07:35:32 +00:00
|
|
|
* @group Database
|
|
|
|
|
*
|
2013-10-24 20:30:43 +00:00
|
|
|
* @covers SpecialPreferences
|
|
|
|
|
*/
|
2020-06-30 15:09:24 +00:00
|
|
|
class SpecialPreferencesTest extends MediaWikiIntegrationTestCase {
|
2012-11-01 21:07:37 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Make sure a nickname which is longer than $wgMaxSigChars
|
|
|
|
|
* is not throwing a fatal error.
|
|
|
|
|
*
|
|
|
|
|
* Test specifications by Alexandre "ialex" Emsenhuber.
|
2014-03-07 20:22:13 +00:00
|
|
|
* @todo give this test a real name explaining what is being tested here
|
2012-11-01 21:07:37 +00:00
|
|
|
*/
|
2018-08-18 13:51:29 +00:00
|
|
|
public function testT43337() {
|
2012-11-01 21:07:37 +00:00
|
|
|
// Set a low limit
|
2022-08-14 13:47:11 +00:00
|
|
|
$this->overrideConfigValue( MainConfigNames::MaxSigChars, 2 );
|
2018-01-13 00:02:09 +00:00
|
|
|
$user = $this->createMock( User::class );
|
2022-07-28 16:46:58 +00:00
|
|
|
$user->method( 'getTitleKey' )
|
|
|
|
|
->willReturn( __CLASS__ );
|
2021-04-22 08:28:11 +00:00
|
|
|
$user->method( 'isAnon' )
|
|
|
|
|
->willReturn( false );
|
2022-04-11 01:39:33 +00:00
|
|
|
$user->method( 'isNamed' )
|
|
|
|
|
->willReturn( true );
|
2012-11-01 21:07:37 +00:00
|
|
|
|
|
|
|
|
# The mocked user has a long nickname
|
2021-12-01 15:21:23 +00:00
|
|
|
$userOptionsLookup = $this->createMock( UserOptionsLookup::class );
|
|
|
|
|
$userOptionsLookup->method( 'getOption' )
|
2022-06-05 23:39:02 +00:00
|
|
|
->willReturnMap( [
|
2022-08-26 20:03:38 +00:00
|
|
|
[
|
|
|
|
|
$user,
|
|
|
|
|
'nickname',
|
|
|
|
|
null,
|
|
|
|
|
false,
|
|
|
|
|
UserOptionsLookup::READ_NORMAL,
|
|
|
|
|
'superlongnickname'
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
$user,
|
|
|
|
|
'language',
|
|
|
|
|
null,
|
|
|
|
|
false,
|
|
|
|
|
UserOptionsLookup::READ_NORMAL,
|
|
|
|
|
MainConfigSchema::LanguageCode['default']
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
$user,
|
|
|
|
|
'skin',
|
|
|
|
|
null,
|
|
|
|
|
false,
|
|
|
|
|
UserOptionsLookup::READ_NORMAL,
|
|
|
|
|
MainConfigSchema::DefaultSkin['default']
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
$user,
|
|
|
|
|
'timecorrection',
|
|
|
|
|
null,
|
|
|
|
|
false,
|
|
|
|
|
UserOptionsLookup::READ_NORMAL,
|
|
|
|
|
"System|-420"
|
|
|
|
|
],
|
|
|
|
|
// MessageCache::getParserOptions() uses the main context
|
|
|
|
|
[
|
|
|
|
|
RequestContext::getMain()->getUser(),
|
|
|
|
|
'language',
|
|
|
|
|
null,
|
|
|
|
|
false,
|
|
|
|
|
UserOptionsLookup::READ_NORMAL,
|
|
|
|
|
MainConfigSchema::LanguageCode['default']
|
|
|
|
|
],
|
|
|
|
|
] );
|
2021-12-01 15:21:23 +00:00
|
|
|
$this->setService( 'UserOptionsLookup', $userOptionsLookup );
|
2012-11-01 21:07:37 +00:00
|
|
|
|
2019-08-21 22:42:08 +00:00
|
|
|
// isAnyAllowed used to return null from the mock,
|
|
|
|
|
// thus revoke it's permissions.
|
|
|
|
|
$this->overrideUserPermissions( $user, [] );
|
|
|
|
|
|
2012-11-01 21:07:37 +00:00
|
|
|
# Forge a request to call the special page
|
|
|
|
|
$context = new RequestContext();
|
|
|
|
|
$context->setRequest( new FauxRequest() );
|
|
|
|
|
$context->setUser( $user );
|
2022-07-05 22:21:30 +00:00
|
|
|
$context->setTitle( Title::makeTitle( NS_MAIN, 'Test' ) );
|
2012-11-01 21:07:37 +00:00
|
|
|
|
2022-01-12 20:13:39 +00:00
|
|
|
$services = $this->getServiceContainer();
|
2012-11-01 21:07:37 +00:00
|
|
|
# Do the call, should not spurt a fatal error.
|
2020-10-18 11:35:42 +00:00
|
|
|
$special = new SpecialPreferences(
|
|
|
|
|
$services->getPreferencesFactory(),
|
|
|
|
|
$services->getUserOptionsManager()
|
|
|
|
|
);
|
2012-11-01 21:07:37 +00:00
|
|
|
$special->setContext( $context );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->assertNull( $special->execute( [] ) );
|
2012-11-01 21:07:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|