Skip to content

Commit 73097ae

Browse files
author
Rafael Becerra
committed
INT-16699: Add item tags to a discussion that was just created
1 parent 511b2b7 commit 73097ae

File tree

2 files changed

+54
-11
lines changed

2 files changed

+54
-11
lines changed

lib.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4466,12 +4466,17 @@ function hsuforum_add_discussion($discussion, $mform=null, $unused=null, $userid
44664466
}
44674467
$post->id = $DB->insert_record("hsuforum_posts", $post);
44684468

4469+
44694470
// TODO: Fix the calling code so that there always is a $cm when this function is called
44704471
if (!empty($cm->id) && !empty($discussion->itemid)) { // In "single simple discussions" this may not exist yet
44714472
$context = context_module::instance($cm->id);
44724473
$text = file_save_draft_area_files($discussion->itemid, $context->id, 'mod_hsuforum', 'post', $post->id,
44734474
mod_hsuforum_post_form::editor_options($context, null), $post->message);
44744475
$DB->set_field('hsuforum_posts', 'message', $text, array('id'=>$post->id));
4476+
4477+
if (isset($discussion->tags)) {
4478+
core_tag_tag::set_item_tags('mod_hsuforum', 'hsuforum_posts', $post->id, $context, $discussion->tags);
4479+
}
44754480
}
44764481

44774482
// Now do the main entry for the discussion, linking to this first post

tests/behat/edit_tags.feature renamed to tests/behat/hsuforum_tags.feature

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,27 @@
1+
# This file is part of Moodle - http://moodle.org/
2+
#
3+
# Moodle is free software: you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License as published by
5+
# the Free Software Foundation, either version 3 of the License, or
6+
# (at your option) any later version.
7+
#
8+
# Moodle is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
# GNU General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU General Public License
14+
# along with Moodle. If not, see <http://www.gnu.org/licenses/>.
15+
#
16+
# Tests for course resource and activity editing features.
17+
#
18+
# @package mod_hsuforum
19+
# @copyright Copyright (c) 2017 Open LMS (http://www.openlms.net)
20+
# @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
21+
122
@mod @mod_hsuforum @core_tag
2-
Feature: Edited Open Forum posts handle tags correctly
3-
In order to get forum posts properly labelled
4-
As a user
5-
I need to introduce the tags while editing
23+
Feature: Open forum posts and new discussions handle tags correctly, in order to get forum posts or discussions labelled.
24+
As a user I need to introduce the tags while creating, editing, or replying.
625

726
Background:
827
Given the following "users" exist:
@@ -25,6 +44,13 @@ Feature: Edited Open Forum posts handle tags correctly
2544
| Subject | Teacher post subject |
2645
| Message | Teacher post message |
2746
And I log out
47+
Given I log in as "admin"
48+
And I navigate to "Appearance > Manage tags" in site administration
49+
And I follow "Default collection"
50+
And I follow "Add standard tags"
51+
And I set the field "Enter comma-separated list of new tags" to "OT1, OT2, OT3"
52+
And I press "Continue"
53+
And I log out
2854

2955
@javascript
3056
Scenario: Forum post edition of custom tags works as expected
@@ -41,13 +67,6 @@ Feature: Edited Open Forum posts handle tags correctly
4167

4268
@javascript
4369
Scenario: Forum post edition of standard tags works as expected
44-
Given I log in as "admin"
45-
And I navigate to "Appearance > Manage tags" in site administration
46-
And I follow "Default collection"
47-
And I follow "Add standard tags"
48-
And I set the field "Enter comma-separated list of new tags" to "OT1, OT2, OT3"
49-
And I press "Continue"
50-
And I log out
5170
And I log in as "teacher1"
5271
And I am on "Course 1" course homepage
5372
And I follow "Test forum"
@@ -70,3 +89,22 @@ Feature: Edited Open Forum posts handle tags correctly
7089
And I should see "OT1" in the ".form-autocomplete-selection" "css_element"
7190
And I should see "OT3" in the ".form-autocomplete-selection" "css_element"
7291
And I should not see "OT2" in the ".form-autocomplete-selection" "css_element"
92+
93+
@javascript
94+
Scenario: Tags are displayed in a discussion that was just created.
95+
Given I log in as "teacher1"
96+
And I am on "Course 1" course homepage
97+
And I follow "Test forum"
98+
And I click on "Add a new discussion" "button"
99+
And I follow "Use advanced editor and additional options"
100+
And I expand all fieldsets
101+
And I click on ".form-autocomplete-downarrow" "css_element"
102+
And I should see "OT1" in the ".form-autocomplete-suggestions" "css_element"
103+
And I should see "OT2" in the ".form-autocomplete-suggestions" "css_element"
104+
And I should see "OT3" in the ".form-autocomplete-suggestions" "css_element"
105+
And I set the field "Subject" to "Subject test"
106+
And I set the field "Message" to "Message test"
107+
And I set the field "Tags" to "OT1"
108+
And I press "Post to forum"
109+
And I follow "Subject test"
110+
And I should see "OT1"

0 commit comments

Comments
 (0)