aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/api/ApiQueryPrefixSearchTest.php
diff options
context:
space:
mode:
authorErik Bernhardson <ebernhardson@wikimedia.org>2017-12-19 14:19:49 -0800
committerErik Bernhardson <ebernhardson@wikimedia.org>2018-06-11 13:35:44 -0700
commit2a43939ffb0cfb0808c2b56430be4f5e88d863ee (patch)
treeae9e2544f42db16a944721a0e6feec1682f18212 /tests/phpunit/includes/api/ApiQueryPrefixSearchTest.php
parentc2a308075f6a1740f06e05fbb2576a59d6ab0c87 (diff)
downloadmediawikicore-2a43939ffb0cfb0808c2b56430be4f5e88d863ee.tar.gz
mediawikicore-2a43939ffb0cfb0808c2b56430be4f5e88d863ee.zip
Push pagination decision for search into SearchEngine
Various code using the search engine shouldn't need to implement it's own methods, such as over-fetching, to determine if there are more results available. This should be knowledge internal to search that is exposed by a boolean. Change-Id: Ica094428700637dfdedb723b03f6aeadfe12b9f4
Diffstat (limited to 'tests/phpunit/includes/api/ApiQueryPrefixSearchTest.php')
-rw-r--r--tests/phpunit/includes/api/ApiQueryPrefixSearchTest.php48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/phpunit/includes/api/ApiQueryPrefixSearchTest.php b/tests/phpunit/includes/api/ApiQueryPrefixSearchTest.php
new file mode 100644
index 000000000000..ae5924d80056
--- /dev/null
+++ b/tests/phpunit/includes/api/ApiQueryPrefixSearchTest.php
@@ -0,0 +1,48 @@
+<?php
+
+/**
+ * @group API
+ * @group medium
+ *
+ * @covers ApiQueryPrefixSearch
+ */
+class ApiQueryPrefixSearchTest extends ApiTestCase {
+ public function offsetContinueProvider() {
+ return [
+ 'no offset' => [ 2, 2, 0, 2 ],
+ 'with offset' => [ 7, 2, 5, 2 ],
+ 'past end, no offset' => [ null, 11, 0, 20 ],
+ 'past end, with offset' => [ null, 5, 6, 10 ],
+ ];
+ }
+
+ /**
+ * @dataProvider offsetContinueProvider
+ */
+ public function testOffsetContinue( $expectedOffset, $expectedResults, $offset, $limit ) {
+ $this->registerMockSearchEngine();
+ $response = $this->doApiRequest( [
+ 'action' => 'query',
+ 'list' => 'prefixsearch',
+ 'pssearch' => 'example query terms',
+ 'psoffset' => $offset,
+ 'pslimit' => $limit,
+ ] );
+ $result = $response[0];
+ $this->assertArrayNotHasKey( 'warnings', $result );
+ $suggestions = $result['query']['prefixsearch'];
+ $this->assertCount( $expectedResults, $suggestions );
+ if ( $expectedOffset == null ) {
+ $this->assertArrayNotHasKey( 'continue', $result );
+ } else {
+ $this->assertArrayHasKey( 'continue', $result );
+ $this->assertEquals( $expectedOffset, $result['continue']['psoffset'] );
+ }
+ }
+
+ private function registerMockSearchEngine() {
+ $this->setMwGlobals( [
+ 'wgSearchType' => MockCompletionSearchEngine::class,
+ ] );
+ }
+}