Skip to content

Commit

Permalink
Merge branch 'MDL-66132-master' of https://github.com/sammarshallou/m…
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Jul 22, 2019
2 parents c5b9f7f + ed73ff2 commit 797ef87
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 25 deletions.
15 changes: 15 additions & 0 deletions search/classes/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -887,6 +892,10 @@ public function paged_search(\stdClass $formdata, $pagenum) {
} 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);
}

Expand Down Expand Up @@ -955,6 +964,12 @@ public function search(\stdClass $formdata, $limit = 0) {
$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;
}
}
Expand Down
10 changes: 10 additions & 0 deletions search/tests/behat/behat_search.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,14 @@ public function global_search_expects_the_query_and_will_return($query, TableNod

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);
}
}
36 changes: 11 additions & 25 deletions search/tests/behat/search_query.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -54,19 +46,13 @@ 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"
And I should see "Courses" in the "region-main" "region"

@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
Expand All @@ -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
Expand All @@ -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 |
Expand Down

0 comments on commit 797ef87

Please sign in to comment.