Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Class: engine_test  - X-Ref

Solr search engine base unit tests.

Required params:
- define('TEST_SEARCH_SOLR_HOSTNAME', '127.0.0.1');
- define('TEST_SEARCH_SOLR_PORT', '8983');
- define('TEST_SEARCH_SOLR_INDEXNAME', 'unittest');

Optional params:
- define('TEST_SEARCH_SOLR_USERNAME', '');
- define('TEST_SEARCH_SOLR_PASSWORD', '');
- define('TEST_SEARCH_SOLR_SSLCERT', '');
- define('TEST_SEARCH_SOLR_SSLKEY', '');
- define('TEST_SEARCH_SOLR_KEYPASSWORD', '');
- define('TEST_SEARCH_SOLR_CAINFOCERT', '');

setUp()   X-Ref


tearDown()   X-Ref
No description

file_indexing_provider()   X-Ref
Simple data provider to allow tests to be run with file indexing on and off.


test_connection()   X-Ref
No description

test_alternate_settings()   X-Ref
Tests that the alternate settings are used when configured.


test_index($fileindexing)   X-Ref


test_search($fileindexing)   X-Ref
Better keep this not very strict about which or how many results are returned as may depend on solr engine config.

return: void

test_delete($fileindexing)   X-Ref


test_alloweduserid($fileindexing)   X-Ref


test_highlight($fileindexing)   X-Ref


test_export_file_for_engine()   X-Ref
No description

test_index_file()   X-Ref
No description

test_reindexing_files()   X-Ref
No description

test_index_filtered_file()   X-Ref
Test indexing a file we don't consider indexable.


test_delete_by_id()   X-Ref
No description

test_solr_filling($fileindexing)   X-Ref
Test that expected results are returned, even with low check_access success rate.


setup_user_hidden_docs($user)   X-Ref
Create 40 docs, that will be return from Solr in 10 hidden, 10 visible, 10 hidden, 10 visible if you query for:
Something1 Something2 Something3 Something4, with the specified user set.


test_get_query_total_count($fileindexing)   X-Ref
Test that counts are what we expect.


test_manager_paged_search($fileindexing)   X-Ref
Test that paged results are what we expect.


test_context_restriction()   X-Ref
Tests searching for results restricted to context id.


test_groups()   X-Ref
Tests searching for results in groups, either by specified group ids or based on user
access permissions.


test_user_restriction()   X-Ref
Tests searching for results restricted to specific user id(s).


test_italics()   X-Ref
Tests searching for results containing words in italic text. (This used to fail.)


assert_result_titles(array $expected, array $results)   X-Ref
Asserts that the returned documents have the expected titles (regardless of order).

param: string[] $expected List of expected document titles
param: \core_search\document[] $results List of returned documents

test_get_supported_orders_relevance_only()   X-Ref
Tests the get_supported_orders function for contexts where we can only use relevance
(system, category).


test_get_supported_orders_relevance_and_location()   X-Ref
Tests the get_supported_orders function for contexts where we support location as well
(course, activity, block).


test_ordering()   X-Ref
Tests ordering by relevance vs location.


test_bogus_content()   X-Ref
Tests with bogus content (that can be entered into Moodle) to see if it crashes.


create_search_record($courseid, $contextid, $title, $content)   X-Ref
Adds a record to the mock search area, so that the search engine can find it later.

param: int $courseid Course id
param: int $contextid Context id
param: string $title Title for search index
param: string $content Content for search index

test_deleted_contexts_and_courses()   X-Ref
Tries out deleting data for a context or a course.


test_add_document_batch()   X-Ref
Specific test of the add_document_batch function (also used in many other tests).


test_batching()   X-Ref
Tests the batching logic, specifically the limit to 100 documents per
batch, and not batching very large documents.


test_add_document_batch_large()   X-Ref
Tests with large documents. The point of this test is that we stop batching
documents if they are bigger than 1MB, and the maximum batch count is 100,
so the maximum size batch will be about 100 1MB documents.


assert_raw_solr_query_result(string $q, array $expected)   X-Ref
Carries out a raw Solr query using the Solr basic query syntax.

This is used to test data contained in the index without going through Moodle processing.

param: string $q Search query
param: string[] $expected Expected titles of results, in alphabetical order