2017-11-07 03:10:14 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
use MediaWiki\MediaWikiServices;
|
2019-08-22 22:53:05 +00:00
|
|
|
use MediaWiki\Permissions\PermissionManager;
|
2017-11-07 03:10:14 +00:00
|
|
|
use MediaWiki\Preferences\DefaultPreferencesFactory;
|
|
|
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @group Preferences
|
2020-02-04 12:42:03 +00:00
|
|
|
* @coversDefaultClass MediaWiki\Preferences\DefaultPreferencesFactory
|
2017-11-07 03:10:14 +00:00
|
|
|
*/
|
2020-06-30 15:09:24 +00:00
|
|
|
class DefaultPreferencesFactoryTest extends \MediaWikiIntegrationTestCase {
|
2019-08-14 12:58:53 +00:00
|
|
|
use TestAllServiceOptionsUsed;
|
2017-11-07 03:10:14 +00:00
|
|
|
|
|
|
|
|
/** @var IContextSource */
|
|
|
|
|
protected $context;
|
|
|
|
|
|
|
|
|
|
/** @var Config */
|
|
|
|
|
protected $config;
|
|
|
|
|
|
2020-06-14 10:51:39 +00:00
|
|
|
protected function setUp() : void {
|
2017-11-07 03:10:14 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
$this->context = new RequestContext();
|
|
|
|
|
$this->context->setTitle( Title::newFromText( self::class ) );
|
2018-08-03 08:43:00 +00:00
|
|
|
|
|
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
|
|
|
|
|
$this->setMwGlobals( 'wgParser', $services->getParserFactory()->create() );
|
2020-02-04 12:42:03 +00:00
|
|
|
$this->setMwGlobals( 'wgDisableLangConversion', false );
|
2018-08-03 08:43:00 +00:00
|
|
|
$this->config = $services->getMainConfig();
|
2017-11-07 03:10:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a basic PreferencesFactory for testing with.
|
2019-09-13 15:26:11 +00:00
|
|
|
* @param PermissionManager $mockPM
|
2020-02-04 12:42:03 +00:00
|
|
|
* @param Language $language
|
2017-11-07 03:10:14 +00:00
|
|
|
* @return DefaultPreferencesFactory
|
|
|
|
|
*/
|
2020-02-04 12:42:03 +00:00
|
|
|
protected function getPreferencesFactory( PermissionManager $mockPM, Language $language ) {
|
2018-08-05 12:56:23 +00:00
|
|
|
$mockNsInfo = $this->createMock( NamespaceInfo::class );
|
|
|
|
|
$mockNsInfo->method( 'getValidNamespaces' )->willReturn( [
|
|
|
|
|
NS_MAIN, NS_TALK, NS_USER, NS_USER_TALK
|
|
|
|
|
] );
|
|
|
|
|
$mockNsInfo->expects( $this->never() )
|
|
|
|
|
->method( $this->anythingBut( 'getValidNamespaces', '__destruct' ) );
|
|
|
|
|
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
|
2017-11-07 03:10:14 +00:00
|
|
|
return new DefaultPreferencesFactory(
|
2019-08-14 12:58:53 +00:00
|
|
|
new LoggedServiceOptions( self::$serviceOptionsAccessLog,
|
2019-10-08 18:28:15 +00:00
|
|
|
DefaultPreferencesFactory::CONSTRUCTOR_OPTIONS, $this->config ),
|
2020-02-04 12:42:03 +00:00
|
|
|
$language,
|
2020-03-31 18:51:49 +00:00
|
|
|
$services->getAuthManager(),
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
$services->getLinkRenderer(),
|
2019-08-22 22:53:05 +00:00
|
|
|
$mockNsInfo,
|
2020-02-04 12:42:03 +00:00
|
|
|
$mockPM,
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
$services->getLanguageConverterFactory()->getLanguageConverter( $language ),
|
|
|
|
|
$services->getLanguageNameUtils(),
|
2021-03-16 15:16:18 +00:00
|
|
|
$services->getHookContainer(),
|
|
|
|
|
$services->getUserOptionsLookup()
|
2017-11-07 03:10:14 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-02-04 12:42:03 +00:00
|
|
|
* @covers ::getForm
|
|
|
|
|
* @covers ::searchPreferences
|
2017-11-07 03:10:14 +00:00
|
|
|
*/
|
|
|
|
|
public function testGetForm() {
|
2018-07-19 15:35:59 +00:00
|
|
|
$this->setTemporaryHook( 'GetPreferences', null );
|
|
|
|
|
|
2017-11-07 03:10:14 +00:00
|
|
|
$testUser = $this->getTestUser();
|
2019-09-13 15:26:11 +00:00
|
|
|
$pm = $this->createMock( PermissionManager::class );
|
|
|
|
|
$pm->method( 'userHasRight' )->willReturn( true );
|
2020-04-13 01:21:01 +00:00
|
|
|
$prefFactory = $this->getPreferencesFactory( $pm, new Language() );
|
|
|
|
|
$form = $prefFactory->getForm( $testUser->getUser(), $this->context );
|
2019-04-14 00:43:33 +00:00
|
|
|
$this->assertInstanceOf( PreferencesFormOOUI::class, $form );
|
2017-11-07 03:10:14 +00:00
|
|
|
$this->assertCount( 5, $form->getPreferenceSections() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* CSS classes for emailauthentication preference field when there's no email.
|
|
|
|
|
* @see https://phabricator.wikimedia.org/T36302
|
2020-02-04 12:42:03 +00:00
|
|
|
*
|
|
|
|
|
* @covers ::profilePreferences
|
2017-11-07 03:10:14 +00:00
|
|
|
* @dataProvider emailAuthenticationProvider
|
|
|
|
|
*/
|
|
|
|
|
public function testEmailAuthentication( $user, $cssClass ) {
|
2019-08-22 22:53:05 +00:00
|
|
|
$pm = $this->createMock( PermissionManager::class );
|
|
|
|
|
$pm->method( 'userHasRight' )->willReturn( true );
|
2020-02-04 12:42:03 +00:00
|
|
|
$prefs = $this->getPreferencesFactory( $pm, new Language() )
|
|
|
|
|
->getFormDescriptor( $user, $this->context );
|
2017-11-07 03:10:14 +00:00
|
|
|
$this->assertArrayHasKey( 'cssclass', $prefs['emailauthentication'] );
|
|
|
|
|
$this->assertEquals( $cssClass, $prefs['emailauthentication']['cssclass'] );
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-19 13:37:14 +00:00
|
|
|
/**
|
2020-02-04 12:42:03 +00:00
|
|
|
* @covers ::renderingPreferences
|
2019-02-19 13:37:14 +00:00
|
|
|
*/
|
|
|
|
|
public function testShowRollbackConfIsHiddenForUsersWithoutRollbackRights() {
|
|
|
|
|
$userMock = $this->getMockBuilder( User::class )
|
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMock();
|
|
|
|
|
$userMock->method( 'getEffectiveGroups' )
|
|
|
|
|
->willReturn( [] );
|
|
|
|
|
$userMock->method( 'getGroupMemberships' )
|
|
|
|
|
->willReturn( [] );
|
|
|
|
|
$userMock->method( 'getOptions' )
|
|
|
|
|
->willReturn( [ 'test' => 'yes' ] );
|
2019-08-22 22:53:05 +00:00
|
|
|
$pm = $this->createMock( PermissionManager::class );
|
|
|
|
|
$pm->method( 'userHasRight' )
|
|
|
|
|
->will( $this->returnValueMap( [
|
|
|
|
|
[ $userMock, 'editmyoptions', true ]
|
|
|
|
|
] ) );
|
2020-02-04 12:42:03 +00:00
|
|
|
$prefs = $this->getPreferencesFactory( $pm, new Language() )
|
|
|
|
|
->getFormDescriptor( $userMock, $this->context );
|
2019-02-19 13:37:14 +00:00
|
|
|
$this->assertArrayNotHasKey( 'showrollbackconfirmation', $prefs );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-02-04 12:42:03 +00:00
|
|
|
* @covers ::renderingPreferences
|
2019-02-19 13:37:14 +00:00
|
|
|
*/
|
|
|
|
|
public function testShowRollbackConfIsShownForUsersWithRollbackRights() {
|
|
|
|
|
$userMock = $this->getMockBuilder( User::class )
|
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMock();
|
|
|
|
|
$userMock->method( 'getEffectiveGroups' )
|
|
|
|
|
->willReturn( [] );
|
|
|
|
|
$userMock->method( 'getGroupMemberships' )
|
|
|
|
|
->willReturn( [] );
|
|
|
|
|
$userMock->method( 'getOptions' )
|
|
|
|
|
->willReturn( [ 'test' => 'yes' ] );
|
2019-08-22 22:53:05 +00:00
|
|
|
$pm = $this->createMock( PermissionManager::class );
|
|
|
|
|
$pm->method( 'userHasRight' )
|
|
|
|
|
->will( $this->returnValueMap( [
|
|
|
|
|
[ $userMock, 'editmyoptions', true ],
|
|
|
|
|
[ $userMock, 'rollback', true ]
|
|
|
|
|
] ) );
|
2020-02-04 12:42:03 +00:00
|
|
|
$prefs = $this->getPreferencesFactory( $pm, new Language() )
|
|
|
|
|
->getFormDescriptor( $userMock, $this->context );
|
2019-02-19 13:37:14 +00:00
|
|
|
$this->assertArrayHasKey( 'showrollbackconfirmation', $prefs );
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
'rendering/advancedrendering',
|
|
|
|
|
$prefs['showrollbackconfirmation']['section']
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-07 03:10:14 +00:00
|
|
|
public function emailAuthenticationProvider() {
|
|
|
|
|
$userNoEmail = new User;
|
|
|
|
|
$userEmailUnauthed = new User;
|
|
|
|
|
$userEmailUnauthed->setEmail( 'noauth@example.org' );
|
|
|
|
|
$userEmailAuthed = new User;
|
|
|
|
|
$userEmailAuthed->setEmail( 'noauth@example.org' );
|
|
|
|
|
$userEmailAuthed->setEmailAuthenticationTimestamp( wfTimestamp() );
|
|
|
|
|
return [
|
|
|
|
|
[ $userNoEmail, 'mw-email-none' ],
|
|
|
|
|
[ $userEmailUnauthed, 'mw-email-not-authenticated' ],
|
|
|
|
|
[ $userEmailAuthed, 'mw-email-authenticated' ],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test that PreferencesFormPreSave hook has correct data:
|
|
|
|
|
* - user Object is passed
|
|
|
|
|
* - oldUserOptions contains previous user options (before save)
|
|
|
|
|
* - formData and User object have set up new properties
|
|
|
|
|
*
|
|
|
|
|
* @see https://phabricator.wikimedia.org/T169365
|
2020-02-04 12:42:03 +00:00
|
|
|
* @covers ::submitForm
|
2017-11-07 03:10:14 +00:00
|
|
|
*/
|
|
|
|
|
public function testPreferencesFormPreSaveHookHasCorrectData() {
|
|
|
|
|
$oldOptions = [
|
|
|
|
|
'test' => 'abc',
|
|
|
|
|
'option' => 'old'
|
|
|
|
|
];
|
|
|
|
|
$newOptions = [
|
|
|
|
|
'test' => 'abc',
|
|
|
|
|
'option' => 'new'
|
|
|
|
|
];
|
|
|
|
|
$configMock = new HashConfig( [
|
|
|
|
|
'HiddenPrefs' => []
|
|
|
|
|
] );
|
2019-04-14 00:43:33 +00:00
|
|
|
$form = $this->getMockBuilder( PreferencesFormOOUI::class )
|
2017-11-07 03:10:14 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
|
|
$userMock = $this->getMockBuilder( User::class )
|
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMock();
|
|
|
|
|
$userMock->method( 'getOptions' )
|
|
|
|
|
->willReturn( $oldOptions );
|
|
|
|
|
|
|
|
|
|
$userMock->expects( $this->exactly( 2 ) )
|
|
|
|
|
->method( 'setOption' )
|
|
|
|
|
->withConsecutive(
|
|
|
|
|
[ $this->equalTo( 'test' ), $this->equalTo( $newOptions[ 'test' ] ) ],
|
|
|
|
|
[ $this->equalTo( 'option' ), $this->equalTo( $newOptions[ 'option' ] ) ]
|
|
|
|
|
);
|
|
|
|
|
|
2019-08-22 22:53:05 +00:00
|
|
|
$form->method( 'getModifiedUser' )
|
2017-11-07 03:10:14 +00:00
|
|
|
->willReturn( $userMock );
|
|
|
|
|
|
2019-08-22 22:53:05 +00:00
|
|
|
$form->method( 'getContext' )
|
2017-11-07 03:10:14 +00:00
|
|
|
->willReturn( $this->context );
|
|
|
|
|
|
2019-08-22 22:53:05 +00:00
|
|
|
$form->method( 'getConfig' )
|
2017-11-07 03:10:14 +00:00
|
|
|
->willReturn( $configMock );
|
|
|
|
|
|
2019-08-22 22:53:05 +00:00
|
|
|
$pm = $this->createMock( PermissionManager::class );
|
|
|
|
|
$pm->method( 'userHasAnyRight' )
|
|
|
|
|
->will( $this->returnValueMap( [
|
|
|
|
|
[ $userMock, 'editmyprivateinfo', 'editmyoptions', true ]
|
|
|
|
|
] ) );
|
|
|
|
|
$pm->method( 'userHasRight' )
|
|
|
|
|
->will( $this->returnValueMap( [
|
|
|
|
|
[ $userMock, 'editmyoptions', true ]
|
|
|
|
|
] ) );
|
|
|
|
|
|
2017-11-07 03:10:14 +00:00
|
|
|
$this->setTemporaryHook( 'PreferencesFormPreSave',
|
|
|
|
|
function ( $formData, $form, $user, &$result, $oldUserOptions )
|
|
|
|
|
use ( $newOptions, $oldOptions, $userMock ) {
|
|
|
|
|
$this->assertSame( $userMock, $user );
|
|
|
|
|
foreach ( $newOptions as $option => $value ) {
|
|
|
|
|
$this->assertSame( $value, $formData[ $option ] );
|
|
|
|
|
}
|
|
|
|
|
foreach ( $oldOptions as $option => $value ) {
|
|
|
|
|
$this->assertSame( $value, $oldUserOptions[ $option ] );
|
|
|
|
|
}
|
2020-01-09 23:23:19 +00:00
|
|
|
$this->assertTrue( $result );
|
2017-11-07 03:10:14 +00:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2018-07-06 19:21:22 +00:00
|
|
|
/** @var DefaultPreferencesFactory $factory */
|
2020-02-04 12:42:03 +00:00
|
|
|
$factory = TestingAccessWrapper::newFromObject(
|
|
|
|
|
$this->getPreferencesFactory( $pm, new Language() )
|
|
|
|
|
);
|
2018-07-06 19:21:22 +00:00
|
|
|
$factory->saveFormData( $newOptions, $form, [] );
|
2017-11-07 03:10:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The rclimit preference should accept non-integer input and filter it to become an integer.
|
2018-05-07 08:22:40 +00:00
|
|
|
*
|
2020-02-04 12:42:03 +00:00
|
|
|
* @covers ::saveFormData
|
2017-11-07 03:10:14 +00:00
|
|
|
*/
|
|
|
|
|
public function testIntvalFilter() {
|
|
|
|
|
// Test a string with leading zeros (i.e. not octal) and spaces.
|
|
|
|
|
$this->context->getRequest()->setVal( 'wprclimit', ' 0012 ' );
|
|
|
|
|
$user = new User;
|
2019-08-22 22:53:05 +00:00
|
|
|
$pm = $this->createMock( PermissionManager::class );
|
|
|
|
|
$pm->method( 'userHasAnyRight' )
|
|
|
|
|
->willReturn( true );
|
|
|
|
|
$pm->method( 'userHasRight' )
|
|
|
|
|
->will( $this->returnValueMap( [
|
|
|
|
|
[ $user, 'editmyoptions', true ]
|
|
|
|
|
] ) );
|
2020-04-13 01:21:01 +00:00
|
|
|
$prefFactory = $this->getPreferencesFactory( $pm, new Language() );
|
|
|
|
|
$form = $prefFactory->getForm( $user, $this->context );
|
2017-11-07 03:10:14 +00:00
|
|
|
$form->show();
|
|
|
|
|
$form->trySubmit();
|
|
|
|
|
$this->assertEquals( 12, $user->getOption( 'rclimit' ) );
|
|
|
|
|
}
|
2019-08-14 12:58:53 +00:00
|
|
|
|
2020-02-04 12:42:03 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ::profilePreferences
|
|
|
|
|
*/
|
|
|
|
|
public function testVariantsSupport() {
|
|
|
|
|
$userMock = $this->getMockBuilder( User::class )
|
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMock();
|
|
|
|
|
$userMock->method( 'getEffectiveGroups' )
|
|
|
|
|
->willReturn( [] );
|
|
|
|
|
$userMock->method( 'getGroupMemberships' )
|
|
|
|
|
->willReturn( [] );
|
|
|
|
|
$userMock->method( 'getOptions' )
|
|
|
|
|
->willReturn( [ 'LanguageCode' => 'sr', 'variant' => 'sr' ] );
|
|
|
|
|
$pm = $this->createMock( PermissionManager::class );
|
|
|
|
|
|
|
|
|
|
$pm->method( 'userHasRight' )
|
|
|
|
|
->will( $this->returnValue( true ) );
|
|
|
|
|
|
|
|
|
|
$language = $this->createMock( Language::class );
|
|
|
|
|
$language->expects( $this->any() )->method( 'getCode' )
|
|
|
|
|
->willReturn( 'sr' );
|
|
|
|
|
|
|
|
|
|
$prefs = $this->getPreferencesFactory( $pm, $language )
|
|
|
|
|
->getFormDescriptor( $userMock, $this->context );
|
|
|
|
|
$this->assertArrayHasKey( 'default', $prefs['variant'] );
|
|
|
|
|
$this->assertEquals( 'sr', $prefs['variant']['default'] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers ::profilePreferences
|
|
|
|
|
*/
|
|
|
|
|
public function testUserGroupMemberships() {
|
|
|
|
|
$userMock = $this->getMockBuilder( User::class )
|
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMock();
|
|
|
|
|
$userMock->method( 'getEffectiveGroups' )
|
|
|
|
|
->willReturn( [ 'users' ] );
|
|
|
|
|
$userMock->method( 'getGroupMemberships' )
|
|
|
|
|
->willReturn( [ 'users' ] );
|
|
|
|
|
$userMock->method( 'getOptions' )
|
|
|
|
|
->willReturn( [] );
|
|
|
|
|
$pm = $this->createMock( PermissionManager::class );
|
|
|
|
|
|
|
|
|
|
$pm->method( 'userHasRight' )
|
|
|
|
|
->will( $this->returnValue( true ) );
|
|
|
|
|
|
|
|
|
|
$language = $this->createMock( Language::class );
|
|
|
|
|
$language->expects( $this->any() )->method( 'getCode' )
|
|
|
|
|
->willReturn( 'en' );
|
|
|
|
|
|
|
|
|
|
$prefs = $this->getPreferencesFactory( $pm, $language )
|
|
|
|
|
->getFormDescriptor( $userMock, $this->context );
|
|
|
|
|
$this->assertArrayHasKey( 'default', $prefs['usergroups'] );
|
|
|
|
|
$this->assertEquals( 'users', $prefs['usergroups']['default'] );
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-14 12:58:53 +00:00
|
|
|
/**
|
|
|
|
|
* @coversNothing
|
|
|
|
|
*/
|
|
|
|
|
public function testAllServiceOptionsUsed() {
|
preferences: Signature validation (lint errors, user links, nested subst)
Three new checks are now applied to user signatures in preferences:
* Disallow invalid HTML and lint errors (T140606)
Since 15e0e9bb4b we can rely on Parsoid to check the signature for
lint errors. (The old PHP Parser doesn't have this capability.)
Most importantly, this will disallow unclosed HTML tags. Unclosed
formatting tags like `<i>` (and also wikitext markup like `''`)
could affect the entire page with the bad markup.
New configuration variable $wgSignatureAllowedLintErrors is added
to allow ignoring some errors. The default value ignores the
'obsolete-tag' error (caused by HTML tags like `<font>` and `<tt>`.)
* Require a link to user page, talk page or contributions (T237700)
Various tools don't work correctly when such a link is missing. For
example, Echo notifications are not sent, DiscussionTools will not
allow replying to these comments, English Wikipedia's SineBot treats
these comments as unsigned.
Such requirement has been present for a long time in many Wikimedia
wikis' policies, but it was not enforced by software.
* Disallow "nested" substitution in signature (T230652)
Clever abuse of "subst" markup and tildes allows users to save edits
containing wikitext in which substitution occurs again when the page
is next saved. Disallow this in signatures, at least.
New configuration variable $wgSignatureValidation is added to control
what we do about the result of the validation described above. The
options are:
* 'warning':
Only displays a warning near the field on Special:Preferences if
the current signature is invalid. Signatures can still be changed
regardless of validity and will be used when signing comments.
* 'new':
In addition to the above, if a user tries to change their signature,
the new one must be valid. Existing invalid signatures are still
used when signing comments.
* 'disallow':
In addition to the above, existing invalid signatures are no longer
used when signing comments.
Bug: T140606
Bug: T237700
Bug: T230652
Change-Id: I07c575c2d9d2afe7a89c4847d16ac044417297bf
2019-11-09 00:15:51 +00:00
|
|
|
$this->assertAllServiceOptionsUsed( [
|
|
|
|
|
// Only used when $wgEnotifWatchlist or $wgEnotifUserTalk is true
|
|
|
|
|
'EnotifMinorEdits',
|
|
|
|
|
// Only used when $wgEnotifWatchlist or $wgEnotifUserTalk is true
|
|
|
|
|
'EnotifRevealEditorAddress',
|
|
|
|
|
// Only used when 'fancysig' preference is enabled
|
|
|
|
|
'SignatureValidation',
|
|
|
|
|
] );
|
2019-08-14 12:58:53 +00:00
|
|
|
}
|
2017-11-07 03:10:14 +00:00
|
|
|
}
|