Skip to content
Permalink
Browse files

Merge branch 'MDL-64729-36' into MOODLE_36_STABLE

  • Loading branch information...
abgreeve committed Feb 21, 2019
2 parents a628bbe + 1d4da3c commit 61451240d2c266cb1cfdddf5188a81b58d455417
Showing with 39 additions and 2 deletions.
  1. +2 −2 mod/glossary/lib.php
  2. +37 −0 mod/glossary/tests/lib_test.php
@@ -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);
@@ -466,4 +466,41 @@ public function test_mod_glossary_get_tagged_entries() {
$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);
}
}

0 comments on commit 6145124

Please sign in to comment.
You can’t perform that action at this time.