mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
MDL-66132 Search: Behat tests should use simpledb, fix mock count
When searching using mock results (the 'global search expects the query' step), the result count is not correctly set. As a result, the page incorrectly reports that there are no results and doesn't correctly show the first page of multi-page results. Additionally, some of the core Behat tests can now be moved to use real searching with the simpledb engine, rather than using mock results at all. This gives better tests. Unfortunately it was not possible to move all of the core Behat tests and deprecate the mock step, because some of the tests are related to the UI for 'special' features searching by user or group, neither of which are supported by the simpledb engine.
This commit is contained in:
parent
f7e108438f
commit
ed73ff2b0e
3 changed files with 36 additions and 25 deletions
|
@ -154,6 +154,11 @@ class manager {
|
|||
*/
|
||||
protected static $phpunitfaketime = 0;
|
||||
|
||||
/**
|
||||
* @var int Result count when used with mock results for Behat tests.
|
||||
*/
|
||||
protected $behatresultcount = 0;
|
||||
|
||||
/**
|
||||
* Constructor, use \core_search\manager::instance instead to get a class instance.
|
||||
*
|
||||
|
@ -887,6 +892,10 @@ class manager {
|
|||
} else {
|
||||
// Get the possible count reported by engine, and limit to our max.
|
||||
$out->totalcount = $this->engine->get_query_total_count();
|
||||
if (defined('BEHAT_SITE_RUNNING') && $this->behatresultcount) {
|
||||
// Override results when using Behat mock results.
|
||||
$out->totalcount = $this->behatresultcount;
|
||||
}
|
||||
$out->totalcount = min($out->totalcount, static::MAX_RESULTS);
|
||||
}
|
||||
|
||||
|
@ -955,6 +964,12 @@ class manager {
|
|||
$docs[] = $doc;
|
||||
}
|
||||
|
||||
// Store the mock count, and apply the limit to the returned results.
|
||||
$this->behatresultcount = count($docs);
|
||||
if ($this->behatresultcount > $limit) {
|
||||
$docs = array_slice($docs, 0, $limit);
|
||||
}
|
||||
|
||||
return $docs;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue