Merge branch 'MDL-66132-master' of https://github.com/sammarshallou/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2019-07-22 20:56:29 +02:00
commit 797ef87344
3 changed files with 36 additions and 25 deletions

View file

@ -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;
}
}

View file

@ -135,4 +135,14 @@ class behat_search extends behat_base {
set_config('behat_fakeresult', json_encode($outdata), 'core_search');
}
/**
* Updates the global search index to take account of any added activities.
*
* @Given /^I update the global search index$/
* @throws moodle_exception
*/
public function i_update_the_global_search_index() {
\core_search\manager::instance()->index(false);
}
}

View file

@ -6,22 +6,20 @@ Feature: Use global search interface
Background:
Given the following config values are set as admin:
| enableglobalsearch | 1 |
| searchengine | solr |
| enableglobalsearch | 1 |
| searchengine | simpledb |
And the following "courses" exist:
| shortname | fullname |
| F1 | Amphibians |
And the following "activities" exist:
| activity | name | intro | course | idnumber |
| page | PageName1 | PageDesc1 | F1 | PAGE1 |
| forum | ForumName1 | ForumDesc1 | F1 | FORUM1 |
| activity | name | intro | course | idnumber |
| page | PageName1 frogs amphibians | PageDesc1 | F1 | PAGE1 |
| forum | ForumName1 toads amphibians | ForumDesc1 | F1 | FORUM1 |
And I update the global search index
And I log in as "admin"
@javascript
Scenario: Search from header search box with one result
Given global search expects the query "frogs" and will return:
| type | idnumber |
| activity | PAGE1 |
When I search for "frogs" using the header global search box
Then I should see "PageName1"
And I should see "PageDesc1"
@ -32,15 +30,9 @@ Feature: Use global search interface
@javascript
Scenario: Search from search page with two results
Given global search expects the query "zombies" and will return:
| nothing |
When I search for "zombies" using the header global search box
Then I should see "No results"
And I set the field "id_q" to "Toads"
And global search expects the query "Toads" and will return:
| type | idnumber |
| activity | FORUM1 |
| activity | PAGE1 |
And I set the field "id_q" to "amphibians"
# You cannot press "Search" because there's a fieldset with the same name that gets in the way.
And I press "id_submitbutton"
And I should see "ForumName1"
@ -54,9 +46,6 @@ Feature: Use global search interface
@javascript
Scenario: Search starting from site context (no within option)
Given global search expects the query "frogs" and will return:
| type | idnumber |
| activity | PAGE1 |
When I search for "frogs" using the header global search box
And I expand all fieldsets
Then I should not see "Search within"
@ -64,9 +53,6 @@ Feature: Use global search interface
@javascript
Scenario: Search starting from course context (within option lists course)
Given global search expects the query "frogs" and will return:
| type | idnumber |
| activity | PAGE1 |
When I am on "Amphibians" course homepage
And I search for "frogs" using the header global search box
And I expand all fieldsets
@ -78,9 +64,6 @@ Feature: Use global search interface
@javascript
Scenario: Search starting from forum context (within option lists course and forum)
Given global search expects the query "frogs" and will return:
| type | idnumber |
| activity | PAGE1 |
When I am on "Amphibians" course homepage
And I follow "ForumName1"
And I search for "frogs" using the header global search box
@ -95,7 +78,10 @@ Feature: Use global search interface
@javascript
Scenario: Check that groups option in search form appears when intended
Given the following "groups" exist:
# Switch to mocked Solr search because simpledb doesn't support groups.
Given the following config values are set as admin:
| searchengine | solr |
And the following "groups" exist:
| name | course | idnumber |
| A Group | F1 | G1 |
| B Group | F1 | G2 |