From d393030c588e0fe96db634d4b7e38ad843774f0e Mon Sep 17 00:00:00 2001 From: Angelia Dela Cruz Date: Wed, 18 Oct 2023 10:27:51 +0800 Subject: [PATCH 1/2] MDL-79702 core_tag: Behat for activity tags deletion during course reset --- .../behat/activity_tags_deletion.feature | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 course/tests/behat/activity_tags_deletion.feature diff --git a/course/tests/behat/activity_tags_deletion.feature b/course/tests/behat/activity_tags_deletion.feature new file mode 100644 index 00000000000..e89e3f81aa2 --- /dev/null +++ b/course/tests/behat/activity_tags_deletion.feature @@ -0,0 +1,121 @@ +@core @core_course @core_tag @javascript +Feature: Delete activity tags during course reset + As an admin, + I should be able to delete activity tags by performing course reset + + Background: + Given the following "courses" exist: + | 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 | + + 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: + | book | title | content | tags | + | Test Book | Chapter 1 | Chapter 1 content | SampleTag, ChapterTag | + # Perform course reset without checking anything. + And I log in as "admin" + And I am on the "Course 1" "reset" page + And I press "Reset" + And I press "Continue" + # Confirm that book chapter tags are not deleted. + When I am on the "Test Book" "book activity" page + Then I should see "SampleTag" + And I should see "ChapterTag" + # Delete book chapter tags using course reset. + And I am on the "Course 1" "reset" page + 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. + 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" + + 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" + # Perform course reset without checking anything. + And I am on the "Course 1" "reset" page + And I press "Reset" + And I press "Continue" + # Confirm that forum discussion tags are not deleted. + When I am on the "Test Forum" "forum activity" page + And I follow "Discussion 1" + Then I should see "SampleTag" + And I should see "DiscussionTag" + And I am on the "Course 1" "reset" page + And I expand all fieldsets + # Depending on value, either delete all discussion posts or remove all forum discussion tags only. + And I click on "" "checkbox" + # Confirm `Remove all forum tags` is disabled when `Delete all posts` on previous step is checked. + And the "Remove all forum tags" "checkbox" should be + And I press "Reset" + And I should see "" in the "Forums" "table_row" + And I press "Continue" + And I am on the "Test Forum" "forum activity" page + # Confirm discussion is deleted when `Delete all posts` was checked. + And I see "There are no discussion topics yet in this forum" + # Confirm all discussion tags are deleted. + And I should not see "SampleTag" + And I should not see "DiscussionTag" + + Examples: + | resetcheck | resetmessage | canbechecked | forumview | + | Delete all posts | Delete all posts | disabled | should | + | Remove all forum tags | Forum tags have been deleted | enabled | should not | + + 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" + # Perform course reset without checking anything. + And I am on the "Course 1" "reset" page + And I press "Reset" + And I press "Continue" + # Confirm that glossary entry tags are not deleted. + When I am on the "Test Glossary" "glossary activity" page + Then I should see "SampleTag" + And I should see "GlossaryTag" + And I am on the "Course 1" "reset" page + And I expand all fieldsets + # Depending on value, either delete all glossary entries or remove all glossary entry tags only. + And I click on "" "checkbox" + # Confirm `Remove all forum tags` is disabled when `Delete entries from all glossaries` on previous step is checked. + And the "Remove all glossary tags" "checkbox" should be + And I press "Reset" + And I should see "" in the "Glossaries" "table_row" + And I press "Continue" + And I am on the "Test Glossary" "glossary activity" page + # Confirm glossary entries are deleted when `Delete entries from all glossaries` is checked. + And I see "No entries found in this section" + # Confirm that glossary entry tags are deleted. + And I should not see "SampleTag" + And I should not see "GlossaryTag" + + Examples: + | resetcheck | resetmessage | canbechecked | glossaryview | + | Delete entries from all glossaries | Delete entries from all glossaries | disabled | should | + | Remove all glossary tags | Glossary tags have been deleted | enabled | should not | From 72c30389255e88f9318aa6f3da32713767d33052 Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Mon, 6 May 2024 16:39:44 +0800 Subject: [PATCH 2/2] MDL-79702 behat: improvements and fixes to new tests This commit adds the handling of tags as string separated by comma to forum and glossary modules. --- .../behat/activity_tags_deletion.feature | 41 +++++++------------ mod/forum/lib.php | 5 ++- mod/glossary/tests/generator/lib.php | 12 +++++- 3 files changed, 30 insertions(+), 28 deletions(-) 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 aa2f40b3db5..da61386c237 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -3272,7 +3272,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; } }