3 class MockSearchEngine
extends SearchEngine
{
4 use LinkCacheTestTrait
;
6 /** @var SearchResult[][] */
7 private static $results = [];
8 /** @var ISearchResultSet[][] */
9 private static $interwikiResults = [];
11 public static function clearMockResults() {
13 self
::$interwikiResults = [];
17 * @param string $query The query searched for *after* initial
18 * transformations have been applied.
19 * @param SearchResult[] $results The results to return for $query
21 public static function addMockResults( $query, array $results ) {
22 $mockSearchEngine = new self();
23 foreach ( $results as &$result ) {
24 // Resolve deferred results; needed to work around T203279
25 if ( is_callable( $result ) ) {
29 // TODO: better page ids? Does it matter?
30 $mockSearchEngine->addGoodLinkObject( mt_rand(), $result->getTitle() );
32 self
::$results[$query] = $results;
36 * @param ISearchResultSet[][] $interwikiResults
38 public static function setMockInterwikiResults( array $interwikiResults ) {
39 self
::$interwikiResults = $interwikiResults;
42 protected function doSearchText( $term ) {
43 if ( isset( self
::$results[ $term ] ) ) {
44 $results = array_slice( self
::$results[ $term ], $this->offset
, $this->limit
);
48 return new MockSearchResultSet( $results, self
::$interwikiResults );