Skip to content

Commit

Permalink
Merge branch 'MDL-64729-36' into MOODLE_36_STABLE
Browse files Browse the repository at this point in the history
  • Loading branch information
abgreeve committed Feb 21, 2019
2 parents a628bbe + 1d4da3c commit 6145124
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mod/glossary/lib.php
Expand Up @@ -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);
Expand Down
37 changes: 37 additions & 0 deletions mod/glossary/tests/lib_test.php
Expand Up @@ -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.