first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+161
View File
@@ -0,0 +1,161 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Behat search-related step definitions.
*
* @package core_search
* @category test
* @copyright 2017 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// NOTE: no MOODLE_INTERNAL used, this file may be required by behat before including /config.php.
require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
use Behat\Gherkin\Node\TableNode as TableNode;
use Moodle\BehatExtension\Exception\SkippedException;
/**
* Behat search-related step definitions.
*
* @package core_search
* @category test
* @copyright 2017 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_search extends behat_base {
/**
* Create event when starting on the front page.
*
* @Given /^I search for "(?P<query>[^"]*)" using the header global search box$/
* @param string $query Query to search for
*/
public function i_search_for_using_the_header_global_search_box($query) {
// Click the search icon.
$this->execute("behat_general::i_click_on", [get_string('togglesearch', 'core'), 'button']);
// Set the field.
$this->execute('behat_forms::i_set_the_field_to', ['q', $query]);
// Submit the form.
$this->execute("behat_general::i_click_on_in_the",
[get_string('search', 'core'), 'button', '#usernavigation', 'css_element']);
}
/**
* Sets results which will be returned for the next search. It will only return links to
* activities at present.
*
* @Given /^global search expects the query "(?P<query>[^"]*)" and will return:$/
* @param string $query Expected query value (just used to check the query passed to the engine)
* @param TableNode $data Data rows
*/
public function global_search_expects_the_query_and_will_return($query, TableNode $data) {
global $DB;
$outdata = new stdClass();
$outdata->query = $query;
$outdata->results = [];
foreach ($data->getHash() as $rowdata) {
// Check and get the data from the user-entered row.
$input = [
'type' => '',
'idnumber' => '',
'title' => '',
'content' => '',
'modified' => ''
];
foreach ($rowdata as $key => $value) {
if (!array_key_exists($key, $input)) {
throw new Exception('Field ' . $key . '" does not exist');
}
$input[$key] = $value;
}
foreach (['idnumber', 'type'] as $requiredfield) {
if (!$input[$requiredfield]) {
throw new Exception('Must specify required field: ' . $requiredfield);
}
}
// Check type (we only support activity at present, this could be extended to allow
// faking other types of search results such as a user, course, or forum post).
if ($input['type'] !== 'activity') {
throw new Exception('Unsupported type: ' . $input['type']);
}
// Find the specified activity.
$idnumber = $input['idnumber'];
$cmid = $DB->get_field('course_modules', 'id', ['idnumber' => $idnumber], IGNORE_MISSING);
if (!$cmid) {
throw new Exception('Cannot find activity with idnumber: ' . $idnumber);
}
list ($course, $cm) = get_course_and_cm_from_cmid($cmid);
$rec = $DB->get_record($cm->modname, ['id' => $cm->instance], '*', MUST_EXIST);
$context = \context_module::instance($cm->id);
// Set up the internal fields used in creating the search document.
$out = new stdClass();
$out->itemid = $cm->instance;
$out->componentname = 'mod_' . $cm->modname;
$out->areaname = 'activity';
$out->fields = new stdClass();
$out->fields->contextid = $context->id;
$out->fields->courseid = $course->id;
if ($input['title']) {
$out->fields->title = $input['title'];
} else {
$out->fields->title = $cm->name;
}
if ($input['content']) {
$out->fields->content = $input['content'];
} else {
$out->fields->content = content_to_text($rec->intro, $rec->introformat);
}
if ($input['modified']) {
$out->fields->modified = strtotime($input['modified']);
} else {
$out->fields->modified = $cm->added;
}
$out->extrafields = new stdClass();
$out->extrafields->coursefullname = $course->fullname;
$outdata->results[] = $out;
}
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);
}
/**
* This step looks to see if Solr is installed or skip the rest of the scenario otherwise
*
* @Given /^solr is installed/
*/
public function solr_is_installed() {
if (!function_exists('solr_get_version')) {
throw new SkippedException('Skipping this scenario because Solr is not installed.');
}
}
}
+68
View File
@@ -0,0 +1,68 @@
@core @core_search
Feature: Select users when searching for user-created content
In order to search for content by specific users
As a user
I need to be able to add users to the select list in the search form
Background:
Given solr is installed
And the following config values are set as admin:
| enableglobalsearch | 1 |
| searchengine | solr |
And the following "courses" exist:
| shortname | fullname |
| C1 | Frogs |
| C2 | Zombies |
And the following "activities" exist:
| activity | name | intro | course | idnumber |
| page | PageName1 | PageDesc1 | C1 | PAGE1 |
And the following "users" exist:
| username | firstname | lastname |
| s1 | Anne | Other |
| s2 | Anne | Additional |
| t | Anne | Ditin |
And the following "course enrolments" exist:
| user | course | role |
| s1 | C1 | student |
| s2 | C2 | student |
| t | C1 | teacher |
@javascript
Scenario: As administrator, search for users from home page
Given I log in as "admin"
And global search expects the query "frogs" and will return:
| type | idnumber |
| activity | PAGE1 |
And I search for "frogs" using the header global search box
And I expand all fieldsets
When I expand the "Users" autocomplete
# Alphabetical last name order.
Then "Anne Additional" "text" should appear before "Anne Ditin" "text" in the "Users" "autocomplete"
And "Anne Ditin" "text" should appear before "Anne Other" "text" in the "Users" "autocomplete"
@javascript
Scenario: As administrator, search for users within course
Given I log in as "admin"
And I am on "Frogs" course homepage
And global search expects the query "frogs" and will return:
| type | idnumber |
| activity | PAGE1 |
And I search for "frogs" using the header global search box
And I expand all fieldsets
And I select "Course: Frogs" from the "Search within" singleselect
When I expand the "Users" autocomplete
# Users in selected course appear first.
Then "Anne Additional" "text" should appear after "Anne Other" "text" in the "Users" "autocomplete"
@javascript
Scenario: As student, cannot see users on other courses
Given I log in as "s1"
And I am on "Frogs" course homepage
And global search expects the query "frogs" and will return:
| type | idnumber |
| activity | PAGE1 |
And I search for "frogs" using the header global search box
And I expand all fieldsets
When I expand the "Users" autocomplete
Then "Anne Ditin" "text" should appear before "Anne Other" "text" in the "Users" "autocomplete"
And "Anne Additional" "text" should not exist
@@ -0,0 +1,36 @@
@core @core_search
Feature: Show system information in the search interface
In order to let users know if there are current problems with search
As an admin
I need to be able to show information on search pages
Background:
Given the following config values are set as admin:
| enableglobalsearch | 1 |
| searchengine | simpledb |
And I log in as "admin"
@javascript
Scenario: Information displays when enabled
When the following config values are set as admin:
| searchbannerenable | 1 |
| searchbanner | The search currently only finds frog-related content; we hope to fix it soon. |
And I search for "toads" using the header global search box
Then I should see "The search currently only finds frog-related content" in the ".notifywarning" "css_element"
@javascript
Scenario: Information does not display when not enabled
When the following config values are set as admin:
| searchbannerenable | 0 |
| searchbanner | The search currently only finds frog-related content; we hope to fix it soon. |
And I search for "toads" using the header global search box
Then I should not see "The search currently only finds frog-related content"
And ".notifywarning" "css_element" should not exist
@javascript
Scenario: Information does not display when left blank
When the following config values are set as admin:
| searchbannerenable | 1 |
| searchbanner | |
And I search for "toads" using the header global search box
Then ".notifywarning" "css_element" should not exist
+128
View File
@@ -0,0 +1,128 @@
@core @core_search
Feature: Use global search interface
In order to search for things
As a user
I need to be able to type search queries and see results
Background:
Given the following config values are set as admin:
| 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 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
When I search for "frogs" using the header global search box
Then I should see "PageName1"
And I should see "PageDesc1"
# Check the link works.
And I follow "PageName1"
And I should see "PageName1" in the ".breadcrumb" "css_element"
@javascript
Scenario: Search from search page with two results
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 "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"
And I should see "ForumDesc1"
And I should see "PageName1"
And I should see "PageDesc1"
# Check the link works.
And I follow "ForumName1"
And I should see "ForumName1" in the ".breadcrumb" "css_element"
@javascript
Scenario: Search from search page with quotes
Given I search for "zombies" using the header global search box
And I should see "No results"
When 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"
Then I should see "ForumName1"
And I should see "ForumDesc1"
And I should see "PageName1"
And I should see "PageDesc1"
# Check the link works.
And I follow "ForumName1"
And I should see "ForumName1" in the ".breadcrumb" "css_element"
@javascript
Scenario: Search starting from site context (no within option)
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)
When I am on "Amphibians" course homepage
And I search for "frogs" using the header global search box
And I expand all fieldsets
Then I should see "Search within"
And I select "Everywhere you can access" from the "Search within" singleselect
And I should see "Courses" in the "region-main" "region"
And I select "Course: Amphibians" from the "Search within" singleselect
And I should not see "Courses" in the "region-main" "region"
@javascript
Scenario: Search starting from forum context (within option lists course and forum)
Given I am on the "ForumName1 toads amphibians" "Forum activity" page
When I search for "frogs" using the header global search box
Then I expand all fieldsets
And I should see "Search within"
And I select "Everywhere you can access" from the "Search within" singleselect
And I should see "Courses" in the "region-main" "region"
And I select "Course: Amphibians" from the "Search within" singleselect
And I should not see "Courses" in the "region-main" "region"
And I select "Forum: ForumName1" from the "Search within" singleselect
And I should not see "Courses" in the "region-main" "region"
@javascript
Scenario: Check that groups option in search form appears when intended
# Switch to mocked Solr search because simpledb doesn't support groups.
Given solr is installed
And 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 |
And the following "activities" exist:
| activity | name | course | idnumber | groupmode |
| forum | ForumSG | F1 | FORUM2 | 1 |
When I am on the ForumSG "Forum activity" page
And global search expects the query "frogs" and will return:
| type | idnumber |
| activity | PAGE1 |
And I search for "frogs" using the header global search box
And I expand all fieldsets
Then I should not see "All groups" in the "region-main" "region"
And I select "Course: Amphibians" from the "Search within" singleselect
And I should see "All groups" in the "region-main" "region"
And I set the field "Groups" to "A Group"
And I select "Forum: ForumSG" from the "Search within" singleselect
And I should see "A Group" in the "region-main" "region"
And I am on the "ForumName1 toads amphibians" "Forum activity" page
And global search expects the query "frogs" and will return:
| type | idnumber |
| activity | PAGE1 |
And I search for "frogs" using the header global search box
And I expand all fieldsets
Then I should not see "All groups" in the "region-main" "region"
And I select "Course: Amphibians" from the "Search within" singleselect
And I should see "All groups" in the "region-main" "region"
And I select "Forum: ForumName1" from the "Search within" singleselect
And I should not see "All groups" in the "region-main" "region"
@@ -0,0 +1,22 @@
@core @core_search
Feature: Plugins > Search > Search setup contains Setup search engine only if the target section actually exists
In order to set up the selected search engine
As an admin
I need to be able to click the link 'Setup search engine' but only if the target section actually exists
Scenario: Selected search engine has an admin section
Given the following config values are set as admin:
| enableglobalsearch | 1 |
| searchengine | solr |
And I log in as "admin"
When I navigate to "Plugins > Search" in site administration
Then "Setup search engine" "link" should exist
Scenario: Selected search engine does not have an admin section
Given the following config values are set as admin:
| enableglobalsearch | 1 |
| searchengine | simpledb |
And I log in as "admin"
When I navigate to "Plugins > Search" in site administration
Then I should see "Setup search engine"
And "Setup search engine" "link" should not exist