Without the default the preference is never deleted from the database, even it was disabled by the user. This can be tested by check "all" on Special:Search and save it for future searches. After checking "none" and selecting the main namespace and save it for future searches there still the other searchNS options on the database. Bug: T291748 Change-Id: Idb3a8774b82f5f27fbeda4537dfdacf59768e8c0
56 lines
1.8 KiB
PHP
56 lines
1.8 KiB
PHP
<?php
|
|
|
|
use MediaWiki\User\DefaultOptionsLookup;
|
|
use MediaWiki\User\UserOptionsLookup;
|
|
|
|
/**
|
|
* @covers MediaWiki\User\DefaultOptionsLookup
|
|
*/
|
|
class DefaultOptionsLookupTest extends UserOptionsLookupTest {
|
|
protected function getLookup(
|
|
string $langCode = 'qqq',
|
|
array $defaultOptionsOverrides = []
|
|
): UserOptionsLookup {
|
|
return $this->getDefaultManager( $langCode, $defaultOptionsOverrides );
|
|
}
|
|
|
|
/**
|
|
* @covers MediaWiki\User\DefaultOptionsLookup::getOption
|
|
*/
|
|
public function testGetOptionsExcludeDefaults() {
|
|
$this->assertSame( [], $this->getLookup()
|
|
->getOptions( $this->getAnon(), DefaultOptionsLookup::EXCLUDE_DEFAULTS ) );
|
|
}
|
|
|
|
/**
|
|
* @covers MediaWiki\User\DefaultOptionsLookup::getDefaultOptions
|
|
*/
|
|
public function testGetDefaultOptionsHook() {
|
|
$this->setTemporaryHook( 'UserGetDefaultOptions', static function ( &$options ) {
|
|
$options['from_hook'] = 'value_from_hook';
|
|
} );
|
|
$this->assertSame( 'value_from_hook', $this->getLookup()->getDefaultOption( 'from_hook' ) );
|
|
}
|
|
|
|
/**
|
|
* @covers MediaWiki\User\DefaultOptionsLookup::getDefaultOptions
|
|
*/
|
|
public function testSearchNS() {
|
|
$lookup = $this->getLookup();
|
|
$this->assertSame( 1, $lookup->getDefaultOption( 'searchNs0' ) );
|
|
$this->assertSame( 0, $lookup->getDefaultOption( 'searchNs8' ) );
|
|
$this->assertSame( 0, $lookup->getDefaultOption( 'searchNs9' ) );
|
|
// Special namespace is not searchable and does not have a default
|
|
$this->assertNull( $lookup->getDefaultOption( 'searchNs-1' ) );
|
|
}
|
|
|
|
/**
|
|
* @covers MediaWiki\User\DefaultOptionsLookup::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' ) );
|
|
}
|
|
}
|