MediaWiki REL1_33
ApiQuerySearchTest.php
Go to the documentation of this file.
1<?php
2
8 public function provideSearchResults() {
9 return [
10 'empty search result' => [ [], [] ],
11 'has search results' => [
12 [ 'Zomg' ],
13 [ $this->mockResultClosure( 'Zomg' ) ],
14 ],
15 'filters broken search results' => [
16 [ 'A', 'B' ],
17 [
18 $this->mockResultClosure( 'a' ),
19 $this->mockResultClosure( 'Zomg', [ 'setBrokenTitle' => true ] ),
20 $this->mockResultClosure( 'b' ),
21 ],
22 ],
23 'filters results with missing revision' => [
24 [ 'B', 'A' ],
25 [
26 $this->mockResultClosure( 'Zomg', [ 'setMissingRevision' => true ] ),
27 $this->mockResultClosure( 'b' ),
28 $this->mockResultClosure( 'a' ),
29 ],
30 ],
31 ];
32 }
33
37 public function testSearchResults( $expect, $hits, array $params = [] ) {
38 MockSearchEngine::addMockResults( 'my query', $hits );
40 'action' => 'query',
41 'list' => 'search',
42 'srsearch' => 'my query',
43 ] );
44 $titles = [];
45 foreach ( $response['query']['search'] as $result ) {
46 $titles[] = $result['title'];
47 }
48 $this->assertEquals( $expect, $titles );
49 }
50
51 public function provideInterwikiResults() {
52 return [
53 'empty' => [ [], [] ],
54 'one wiki response' => [
55 [ 'utwiki' => [ 'Qwerty' ] ],
56 [
57 SearchResultSet::SECONDARY_RESULTS => [
58 'utwiki' => new MockSearchResultSet( [
59 $this->mockResultClosure(
60 'Qwerty',
61 [ 'setInterwikiPrefix' => 'utwiki' ]
62 ),
63 ] ),
64 ],
65 ]
66 ],
67 ];
68 }
69
73 public function testInterwikiResults( $expect, $hits, array $params = [] ) {
76 'action' => 'query',
77 'list' => 'search',
78 'srsearch' => 'my query',
79 'srinterwiki' => true,
80 ] );
81 if ( !$expect ) {
82 $this->assertArrayNotHasKey( 'interwikisearch', $response['query'] );
83 return;
84 }
85 $results = [];
86 $this->assertArrayHasKey( 'interwikisearchinfo', $response['query'] );
87 foreach ( $response['query']['interwikisearch'] as $wiki => $wikiResults ) {
88 $results[$wiki] = [];
89 foreach ( $wikiResults as $wikiResult ) {
90 $results[$wiki][] = $wikiResult['title'];
91 }
92 }
93 $this->assertEquals( $expect, $results );
94 }
95
96 public function setUp() {
97 parent::setUp();
100 }
101
102 private function registerMockSearchEngine() {
103 $this->setMwGlobals( [
104 'wgSearchType' => MockSearchEngine::class,
105 ] );
106 }
107
120 private function mockResultClosure( $title, $setters = [] ) {
121 return function () use ( $title, $setters ){
122 $result = MockSearchResult::newFromTitle( Title::newFromText( $title ) );
123
124 foreach ( $setters as $method => $param ) {
125 $result->$method( $param );
126 }
127
128 return $result;
129 };
130 }
131
132}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
medium ApiQuerySearch
testSearchResults( $expect, $hits, array $params=[])
provideSearchResults
mockResultClosure( $title, $setters=[])
Returns a closure that evaluates to a MockSearchResult, to be resolved by MockSearchEngine::addMockRe...
testInterwikiResults( $expect, $hits, array $params=[])
provideInterwikiResults
doApiRequest(array $params, array $session=null, $appendModule=false, User $user=null, $tokenType=null)
Does the API request and returns the result.
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
static setMockInterwikiResults(array $interwikiResults)
static addMockResults( $query, array $results)
static newFromTitle( $title, SearchResultSet $parentSet=null)
Return a new SearchResult and initializes it with a title.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition deferred.txt:11
namespace being checked & $result
Definition hooks.txt:2340
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
Definition hooks.txt:2843
this hook is for auditing only $response
Definition hooks.txt:780
linkcache txt The LinkCache class maintains a list of article titles and the information about whether or not the article exists in the database This is used to mark up links when displaying a page If the same link appears more than once on any page then it only has to be looked up once In most cases link lookups are done in batches with the LinkBatch class or the equivalent in so the link cache is mostly useful for short snippets of parsed and for links in the navigation areas of the skin The link cache was formerly used to track links used in a document for the purposes of updating the link tables This application is now deprecated To create a you can use the following $titles
Definition linkcache.txt:17
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
$params