diff --git a/mod/glossary/edit_form.php b/mod/glossary/edit_form.php index f6253b0a78a..e68014df314 100644 --- a/mod/glossary/edit_form.php +++ b/mod/glossary/edit_form.php @@ -107,6 +107,13 @@ class mod_glossary_entry_form extends moodleform { $id = (int)$data['id']; $data['concept'] = trim($data['concept']); + $aliases = explode("\r\n", trim($data['aliases'])); + foreach ($aliases as $alias) { + // Check if the alias is just a single character and that it doesn't match reserved symbols. + if (strlen(trim($alias)) == 1 && preg_match('/[$-\/:-?{-~!"^_`\[\]]/', trim($alias))) { + $errors['aliases'] = get_string('errreservedkeywords', 'glossary'); + } + } if ($id) { //We are updating an entry, so we compare current session user with diff --git a/mod/glossary/lang/en/glossary.php b/mod/glossary/lang/en/glossary.php index 35500edabfa..21765a3f94d 100644 --- a/mod/glossary/lang/en/glossary.php +++ b/mod/glossary/lang/en/glossary.php @@ -166,6 +166,7 @@ $string['errconceptalreadyexists'] = 'This concept already exists. No duplicates $string['errdeltimeexpired'] = 'You can\'t delete this. Time expired!'; $string['erredittimeexpired'] = 'The editing time for this entry has expired.'; $string['errorparsingxml'] = 'Errors occurred while parsing the file. Make sure it is valid XML syntax.'; +$string['errreservedkeywords'] = 'Some/All of the entered keywords cannot be used as they are reserved.'; $string['eventcategorycreated'] = 'Category has been created'; $string['eventcategorydeleted'] = 'Category has been deleted'; $string['eventcategoryupdated'] = 'Category has been updated'; diff --git a/mod/glossary/tests/behat/create_entry.feature b/mod/glossary/tests/behat/create_entry.feature new file mode 100644 index 00000000000..09833e0cafb --- /dev/null +++ b/mod/glossary/tests/behat/create_entry.feature @@ -0,0 +1,33 @@ +@mod @mod_glossary @javascript +Feature: Create a glossary entry. As a user + I should be able to enter an entry without + using reserved keywords + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@example.com | + | student1 | Student | 1 | student1@example.com | + And the following "courses" exist: + | fullname | shortname | format | + | Course 1 | C1 | topics | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + And I log in as "teacher1" + And I am on "Course 1" course homepage with editing mode on + And I add a "Glossary" to section "1" and I fill the form with: + | Name | Test glossary | + | Description | A glossary about dreams! | + And I log out + + Scenario: Glossary entry edition of custom tags works as expected + Given I am on the "Test glossary" "glossary activity" page logged in as "teacher1" + And I press "Add entry" + And I set the following fields to these values: + | Concept | Dummy first entry | + | Definition | Dream is the start of a journey | + | Keyword(s) | " | + And I press "Save changes" + Then I should see "Some/All of the entered keywords cannot be used as they are reserved."