Merge branch 'wip-MDL-64729-master' of https://github.com/Beedell/moodle

This commit is contained in:
Adrian Greeve 2019-02-21 12:20:48 +01:00
commit de1f00fdbe
2 changed files with 39 additions and 2 deletions

View File

@ -1046,8 +1046,8 @@ function glossary_get_entries_search($concept, $courseid) {
(cm.course = :courseid1 AND cm.visible = $bypassteacher)) AND
g.id = cm.instance AND
e.glossaryid = g.id AND
( (e.casesensitive != 0 AND LOWER(concept) = :conceptlower) OR
(e.casesensitive = 0 and concept = :concept)) AND
( (e.casesensitive != 1 AND LOWER(concept) = :conceptlower) OR
(e.casesensitive = 1 and concept = :concept)) AND
(g.course = :courseid2 OR g.globalglossary = 1) AND
e.usedynalink != 0 AND
g.usedynalink != 0", $params);

View File

@ -466,4 +466,41 @@ class mod_glossary_lib_testcase extends advanced_testcase {
$this->assertNotRegExp('/'.$entry16->concept.'/', $res->content);
$this->assertRegExp('/'.$entry17->concept.'/', $res->content);
}
public function test_glossary_get_entries_search() {
$this->resetAfterTest();
$this->setAdminUser();
// Turn on glossary autolinking (usedynalink).
set_config('glossary_linkentries', 1);
$glossarygenerator = $this->getDataGenerator()->get_plugin_generator('mod_glossary');
$course = $this->getDataGenerator()->create_course();
$glossary = $this->getDataGenerator()->create_module('glossary', array('course' => $course->id));
// Note this entry is not case sensitive by default (casesensitive = 0).
$entry = $glossarygenerator->create_content($glossary);
// Check that a search for the concept return the entry.
$concept = $entry->concept;
$search = glossary_get_entries_search($concept, $course->id);
$this->assertCount(1, $search);
$foundentry = array_shift($search);
$this->assertEquals($foundentry->concept, $entry->concept);
// Now try the same search but with a lowercase term.
$concept = strtolower($entry->concept);
$search = glossary_get_entries_search($concept, $course->id);
$this->assertCount(1, $search);
$foundentry = array_shift($search);
$this->assertEquals($foundentry->concept, $entry->concept);
// Make an entry that is case sensitive (casesensitive = 1).
set_config('glossary_casesensitive', 1);
$entry = $glossarygenerator->create_content($glossary);
$concept = $entry->concept;
$search = glossary_get_entries_search($concept, $course->id);
$this->assertCount(1, $search);
$foundentry = array_shift($search);
$this->assertEquals($foundentry->concept, $entry->concept);
// Now try the same search but with a lowercase term.
$concept = strtolower($entry->concept);
$search = glossary_get_entries_search($concept, $course->id);
$this->assertCount(0, $search);
}
}