This converts user options management to a separate service for use in DI context. User options are accessed quite early on in installation process and full-on options management depends on the database. Prior we have protected from accessing the DB by setting a hacky $wgUser with 0 id, and relying on the implementation that it doesn't go into the database to get the default user options. Now we can't really do that since DBLoadBalancer is required to instantiate the options manager. Instead, we redefine the options manager with a DefaultOptionsManager, that only provides access to default options and doesn't require DB access. UserOptionsManager uses PreferencesFactory, however injecting it will produce a cyclic dependency. The problem is that we separate options to different kinds, which are inferred from the PreferencesFactory declaration for those options (e.g. if it's a radio button in the UI declaration, the option is of multiselect kind). This is plain wrong, the dependency should be wise versa. This will be addressed separately, since it's requires larger refactoring. For now the PreferencesFactory is obtained on demand. This will be addressed in a followup. Bug: T248527 Change-Id: I74917c5eaec184d188911a319895b941ed55ee87
52 lines
1.6 KiB
PHP
52 lines
1.6 KiB
PHP
<?php
|
|
|
|
use MediaWiki\User\DefaultOptionsManager;
|
|
use MediaWiki\User\UserOptionsLookup;
|
|
|
|
/**
|
|
* @covers MediaWiki\User\DefaultOptionsManager
|
|
*/
|
|
class DefaultOptionsManagerTest extends UserOptionsLookupTest {
|
|
protected function getLookup(
|
|
string $langCode = 'qqq',
|
|
array $defaultOptionsOverrides = []
|
|
) : UserOptionsLookup {
|
|
return $this->getDefaultManager( $langCode, $defaultOptionsOverrides );
|
|
}
|
|
|
|
/**
|
|
* @covers MediaWiki\User\DefaultOptionsManager::getOption
|
|
*/
|
|
public function testGetOptionsExcludeDefaults() {
|
|
$this->assertSame( [], $this->getLookup()
|
|
->getOptions( $this->getAnon(), DefaultOptionsManager::EXCLUDE_DEFAULTS ) );
|
|
}
|
|
|
|
/**
|
|
* @covers MediaWiki\User\DefaultOptionsManager::getDefaultOptions
|
|
*/
|
|
public function testGetDefaultOptionsHook() {
|
|
$this->setTemporaryHook( 'UserGetDefaultOptions', function ( &$options ) {
|
|
$options['from_hook'] = 'value_from_hook';
|
|
} );
|
|
$this->assertSame( 'value_from_hook', $this->getLookup()->getDefaultOption( 'from_hook' ) );
|
|
}
|
|
|
|
/**
|
|
* @covers MediaWiki\User\DefaultOptionsManager::getDefaultOptions
|
|
*/
|
|
public function testSearchNS() {
|
|
$this->assertTrue( $this->getLookup()->getDefaultOption( 'searchNs0' ) );
|
|
$this->assertNull( $this->getLookup()->getDefaultOption( 'searchNs5' ) );
|
|
}
|
|
|
|
/**
|
|
* @covers MediaWiki\User\DefaultOptionsManager::getDefaultOptions
|
|
*/
|
|
public function testLangVariantOptions() {
|
|
$managerZh = $this->getLookup( 'zh' );
|
|
$this->assertSame( 'zh', $managerZh->getDefaultOption( 'language' ) );
|
|
$this->assertSame( 'gan', $managerZh->getDefaultOption( 'variant-gan' ) );
|
|
$this->assertSame( 'zh', $managerZh->getDefaultOption( 'variant' ) );
|
|
}
|
|
}
|