Skip to content

Commit

Permalink
MDL-79702 behat: improvements and fixes to new tests
Browse files Browse the repository at this point in the history
This commit adds the handling of tags as string separated by comma
to forum and glossary modules.
  • Loading branch information
lameze committed May 6, 2024
1 parent d393030 commit 72c3038
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 28 deletions.
41 changes: 15 additions & 26 deletions course/tests/behat/activity_tags_deletion.feature
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion mod/forum/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
12 changes: 11 additions & 1 deletion mod/glossary/tests/generator/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,16 @@ public function create_entry(array $data): stdClass {
$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;
}
}

0 comments on commit 72c3038

Please sign in to comment.