MediaWiki  1.32.5
SearchNearMatcherTest.php
Go to the documentation of this file.
1 <?php
2 
6 class SearchNearMatcherTest extends \PHPUnit\Framework\TestCase {
7  public function nearMatchProvider() {
8  return [
9  'empty request returns nothing' => [ null, 'en', '' ],
10  'default behaviour' => [ 'Near Match Test', 'en', 'near match test' ],
11  'with a hash returns nothing' => [ null, 'en', '#near match test' ],
12  ];
13  }
14 
18  public function testNearMatch( $expected, $langCode, $searchterm ) {
19  $linkCache = MediaWiki\MediaWikiServices::getInstance()->getLinkCache();
20  $linkCache->addGoodLinkObj( 42, Title::newFromText( 'Near Match Test' ) );
21  $config = new HashConfig( [
22  'EnableSearchContributorsByIP' => false,
23  ] );
24  $lang = Language::factory( $langCode );
25  $matcher = new SearchNearMatcher( $config, $lang );
26 
27  $title = $matcher->getNearMatch( $searchterm );
28  $this->assertEquals( $expected, $title === null ? null : (string)$title );
29  }
30 }
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:280
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
HashConfig
A Config instance which stores all settings as a member variable.
Definition: HashConfig.php:28
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:964
SearchNearMatcher
Implementation of near match title search.
Definition: SearchNearMatcher.php:7
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
Definition: MediaWikiServices.php:120
SearchNearMatcherTest\nearMatchProvider
nearMatchProvider()
Definition: SearchNearMatcherTest.php:7
SearchNearMatcherTest\testNearMatch
testNearMatch( $expected, $langCode, $searchterm)
nearMatchProvider
Definition: SearchNearMatcherTest.php:18
Language\factory
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:214
SearchNearMatcherTest
SearchNearMatcher.
Definition: SearchNearMatcherTest.php:6