MDL-64729 mod_glossary: glossary_get_entries_search case sensitivity
authorJohn Beedell <jb23347@open.ac.uk>
Wed, 30 Jan 2019 14:46:40 +0000 (14:46 +0000)
committerJohn Beedell <jb23347@open.ac.uk>
Fri, 15 Feb 2019 16:53:20 +0000 (16:53 +0000)
mod/glossary/lib.php
mod/glossary/tests/lib_test.php

index b447071..65ab0b3 100644 (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);
index 3262239..58de9ee 100644 (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);
+    }
 }