Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7428161
ApiQueryPrefixSearchTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
ApiQueryPrefixSearchTest.php
View Options
<?php
namespace
MediaWiki\Tests\Api\Query
;
use
MediaWiki\MainConfigNames
;
use
MediaWiki\Tests\Api\ApiTestCase
;
use
MockCompletionSearchEngine
;
/**
* @group API
* @group medium
* @group Database
*
* @covers \MediaWiki\Api\ApiQueryPrefixSearch
*/
class
ApiQueryPrefixSearchTest
extends
ApiTestCase
{
private
const
TEST_QUERY
=
'unittest'
;
protected
function
setUp
():
void
{
parent
::
setUp
();
$this
->
overrideConfigValue
(
MainConfigNames
::
SearchType
,
MockCompletionSearchEngine
::
class
);
MockCompletionSearchEngine
::
clearMockResults
();
$results
=
[];
foreach
(
range
(
0
,
10
)
as
$i
)
{
$title
=
"Search_Result_$i"
;
$results
[]
=
$title
;
$this
->
editPage
(
$title
,
'hi there'
);
}
MockCompletionSearchEngine
::
addMockResults
(
self
::
TEST_QUERY
,
$results
);
}
public
static
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
->
overrideConfigValue
(
MainConfigNames
::
UsePigLatinVariant
,
false
);
$response
=
$this
->
doApiRequest
(
[
'action'
=>
'query'
,
'list'
=>
'prefixsearch'
,
'pssearch'
=>
self
::
TEST_QUERY
,
'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'
]
);
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Nov 22, 09:20 (14 h, 18 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
87/dc/386e1e91de9d06b7013afa3f8d12
Default Alt Text
ApiQueryPrefixSearchTest.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment