diff --git a/course/tests/behat/activity_tags_deletion.feature b/course/tests/behat/activity_tags_deletion.feature index e89e3f81aa2..3d829af5884 100644 --- a/course/tests/behat/activity_tags_deletion.feature +++ b/course/tests/behat/activity_tags_deletion.feature @@ -1,4 +1,4 @@ -@core @core_course @core_tag @javascript +@core @core_course @core_tag Feature: Delete activity tags during course reset As an admin, I should be able to delete activity tags by performing course reset @@ -8,11 +8,12 @@ Feature: Delete activity tags during course reset | fullname | shortname | | Course 1 | C1 | And the following "activities" exist: - | activity | name | course | - | book | Test Book | C1 | - | forum | Test Forum | C1 | - | glossary | Test Glossary | C1 | + | activity | name | course | idnumber | + | book | Test Book | C1 | book1 | + | forum | Test Forum | C1 | forum1 | + | glossary | Test Glossary | C1 | glossary1 | + @javascript Scenario: Delete book chapter tags using course reset # Added multiple tags to confirm that all tags are deleted on course reset. Given the following "mod_book > chapters" exist: @@ -32,26 +33,20 @@ Feature: Delete activity tags during course reset And I expand all fieldsets And I click on "Remove all book tags" "checkbox" And I press "Reset" - # Confirm that book chapter tags are sucessfully deleted. + # Confirm that book chapter tags are deleted. And I should see "Book tags have been deleted" in the "Books" "table_row" And I press "Continue" And I am on the "Test Book" "book activity" page And I should not see "SampleTag" And I should not see "ChapterTag" + @javascript Scenario Outline: Delete forum discussion tags using course reset Given the following "mod_forum > discussions" exist: - | user | forum | name | message | - | admin | Test Forum | Discussion 1 | Discussion 1 message | - # Added multiple tags to confirm that all tags are deleted on course reset. - And I am on the "Test Forum" "forum activity" page logged in as admin - And I follow "Discussion 1" - And I click on "Edit" "link" - And I set the following fields to these values: - | Tags | SampleTag, DiscussionTag | - And I press "Save changes" + | user | forum | name | message | tags | + | admin | forum1 | Discussion 1 | Discussion 1 message | SampleTag, DiscussionTag | # Perform course reset without checking anything. - And I am on the "Course 1" "reset" page + And I am on the "Course 1" "reset" page logged in as admin And I press "Reset" And I press "Continue" # Confirm that forum discussion tags are not deleted. @@ -80,19 +75,13 @@ Feature: Delete activity tags during course reset | Delete all posts | Delete all posts | disabled | should | | Remove all forum tags | Forum tags have been deleted | enabled | should not | + @javascript Scenario Outline: Delete glossary entry tags using course reuse Given the following "mod_glossary > entries" exist: - | glossary | concept | definition | user | - | Test Glossary | Aubergine | Also eggpgplant | admin | - # Added multiple tags to confirm that all tags are deleted on course reset. - And I am on the "Test Glossary" "glossary activity" page logged in as admin - And I click on "Edit entry: Aubergine" "link" - And I expand all fieldsets - And I set the following fields to these values: - | Tags | SampleTag, GlossaryTag | - And I press "Save changes" + | glossary | concept | definition | user | tags | + | Test Glossary | Aubergine | Also eggpgplant | admin | SampleTag, GlossaryTag | # Perform course reset without checking anything. - And I am on the "Course 1" "reset" page + And I am on the "Course 1" "reset" page logged in as admin And I press "Reset" And I press "Continue" # Confirm that glossary entry tags are not deleted. diff --git a/mod/forum/lib.php b/mod/forum/lib.php index f8746ba995f..77c61cdd0e2 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -3107,7 +3107,10 @@ function forum_add_discussion($discussion, $mform=null, $unused=null, $userid=nu } if (isset($discussion->tags)) { - core_tag_tag::set_item_tags('mod_forum', 'forum_posts', $post->id, context_module::instance($cm->id), $discussion->tags); + $tags = is_array($discussion->tags) ? $discussion->tags : explode(',', $discussion->tags); + + core_tag_tag::set_item_tags('mod_forum', 'forum_posts', $post->id, + context_module::instance($cm->id), $tags); } if (forum_tp_can_track_forums($forum) && forum_tp_is_tracked($forum)) { diff --git a/mod/glossary/tests/generator/lib.php b/mod/glossary/tests/generator/lib.php index 56debf62cca..67a3be40ebb 100644 --- a/mod/glossary/tests/generator/lib.php +++ b/mod/glossary/tests/generator/lib.php @@ -188,6 +188,16 @@ class mod_glossary_generator extends testing_module_generator { $DB->insert_record('glossary_entries_categories', ['entryid' => $id, 'categoryid' => $categoryid]); } - return $DB->get_record('glossary_entries', array('id' => $id), '*', MUST_EXIST); + $entries = $DB->get_record('glossary_entries', ['id' => $id], '*', MUST_EXIST); + + if (isset($record['tags'])) { + $cm = get_coursemodule_from_instance('glossary', $glossary->id); + $tags = is_array($record['tags']) ? $record['tags'] : explode(',', $record['tags']); + + core_tag_tag::set_item_tags('mod_glossary', 'glossary_entries', $id, + context_module::instance($cm->id), $tags); + } + + return $entries; } }