Skip to content

Commit

Permalink
MDL-74864 forum: Allow specifying group in discussions generator
Browse files Browse the repository at this point in the history
  • Loading branch information
dpalou committed Jun 28, 2022
1 parent 117b240 commit 341039b
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 20 deletions.
40 changes: 27 additions & 13 deletions mod/forum/tests/behat/separate_group_discussions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,36 @@ Feature: Posting to all groups in a separate group discussion is restricted to u
And the following "activities" exist:
| activity | name | intro | course | idnumber | groupmode |
| forum | Standard forum name | Standard forum description | C1 | sepgroups | 1 |
And the following "mod_forum > discussions" exist:
| forum | name | subject | message | group |
| sepgroups | Initial Disc ALL | Initial Disc ALL | Disc ALL content | All participants |
| sepgroups | Initial Disc G1 | Initial Disc G1 | Disc G1 content | G1 |
| sepgroups | Initial Disc G2 | Initial Disc G2 | Disc G2 content | G2 |
| sepgroups | Initial Disc G3 | Initial Disc G3 | Disc G3 content | G3 |

Scenario: Teacher with accessallgroups can view all groups
Given I log in as "teacher1"
And I am on "Course 1" course homepage
When I follow "Standard forum name"
Then the "Separate groups" select box should contain "All participants"
Then the "Separate groups" select box should contain "Group A"
Then the "Separate groups" select box should contain "Group B"
Then the "Separate groups" select box should contain "Group C"
And the "Separate groups" select box should contain "Group A"
And the "Separate groups" select box should contain "Group B"
And the "Separate groups" select box should contain "Group C"
And I select "All participants" from the "Separate groups" singleselect
And I should see "Initial Disc ALL"
And I should see "Initial Disc G1"
And I should see "Initial Disc G2"
And I should see "Initial Disc G2"
And I select "Group A" from the "Separate groups" singleselect
And I should see "Initial Disc ALL"
And I should see "Initial Disc G1"
But I should not see "Initial Disc G2"
And I should not see "Initial Disc G3"
And I select "Group B" from the "Separate groups" singleselect
And I should see "Initial Disc ALL"
And I should see "Initial Disc G2"
But I should not see "Initial Disc G1"
And I should not see "Initial Disc G3"

Scenario: Teacher with accessallgroups can select any group when posting
Given I log in as "teacher1"
Expand Down Expand Up @@ -249,14 +270,7 @@ Feature: Posting to all groups in a separate group discussion is restricted to u
And I should see "Post a copy to all groups"

Scenario: Students can view all participants discussions in separate groups mode
Given I log in as "teacher1"
And I am on "Course 1" course homepage
When I add a new discussion to "Standard forum name" forum with:
| Subject | Forum post to all participants |
| Message | This is the body |
| Group | All participants |
And I log out
And I log in as "student1"
Given I log in as "student1"
And I am on "Course 1" course homepage
And I follow "Standard forum name"
Then I should see "Forum post to all participants"
When I follow "Standard forum name"
Then I should see "Initial Disc ALL"
48 changes: 42 additions & 6 deletions mod/forum/tests/behat/visible_group_discussions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,36 @@ Feature: Posting to all groups in a visible group discussion is restricted to us
And the following "activities" exist:
| activity | name | intro | course | idnumber | groupmode |
| forum | Standard forum name | Standard forum description | C1 | groups | 2 |
And the following "mod_forum > discussions" exist:
| forum | name | subject | message | group |
| groups | Initial Disc ALL | Initial Disc ALL | Disc ALL content | All participants |
| groups | Initial Disc G1 | Initial Disc G1 | Disc G1 content | G1 |
| groups | Initial Disc G2 | Initial Disc G2 | Disc G2 content | G2 |
| groups | Initial Disc G3 | Initial Disc G3 | Disc G3 content | G3 |

Scenario: Teacher with accessallgroups can view all groups
Given I log in as "teacher1"
And I am on "Course 1" course homepage
When I follow "Standard forum name"
Then the "Visible groups" select box should contain "All participants"
Then the "Visible groups" select box should contain "Group A"
Then the "Visible groups" select box should contain "Group B"
Then the "Visible groups" select box should contain "Group C"
And the "Visible groups" select box should contain "Group A"
And the "Visible groups" select box should contain "Group B"
And the "Visible groups" select box should contain "Group C"
And I select "All participants" from the "Visible groups" singleselect
And I should see "Initial Disc ALL"
And I should see "Initial Disc G1"
And I should see "Initial Disc G2"
And I should see "Initial Disc G2"
And I select "Group A" from the "Visible groups" singleselect
And I should see "Initial Disc ALL"
And I should see "Initial Disc G1"
But I should not see "Initial Disc G2"
And I should not see "Initial Disc G3"
And I select "Group B" from the "Visible groups" singleselect
And I should see "Initial Disc ALL"
And I should see "Initial Disc G2"
But I should not see "Initial Disc G1"
And I should not see "Initial Disc G3"

Scenario: Teacher with accessallgroups can select any group when posting
Given I log in as "teacher1"
Expand Down Expand Up @@ -150,9 +171,24 @@ Feature: Posting to all groups in a visible group discussion is restricted to us
And I am on "Course 1" course homepage
When I follow "Standard forum name"
Then the "Visible groups" select box should contain "All participants"
Then the "Visible groups" select box should contain "Group A"
Then the "Visible groups" select box should contain "Group B"
Then the "Visible groups" select box should contain "Group C"
And the "Visible groups" select box should contain "Group A"
And the "Visible groups" select box should contain "Group B"
And the "Visible groups" select box should contain "Group C"
And I select "All participants" from the "Visible groups" singleselect
And I should see "Initial Disc ALL"
And I should see "Initial Disc G1"
And I should see "Initial Disc G2"
And I should see "Initial Disc G2"
And I select "Group A" from the "Visible groups" singleselect
And I should see "Initial Disc ALL"
And I should see "Initial Disc G1"
But I should not see "Initial Disc G2"
And I should not see "Initial Disc G3"
And I select "Group B" from the "Visible groups" singleselect
And I should see "Initial Disc ALL"
And I should see "Initial Disc G2"
But I should not see "Initial Disc G1"
And I should not see "Initial Disc G3"

Scenario: Students in one group can only post in their group
Given I log in as "student1"
Expand Down
17 changes: 16 additions & 1 deletion mod/forum/tests/generator/behat_mod_forum_generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected function get_creatable_entities(): array {
'singular' => 'discussion',
'datagenerator' => 'discussion',
'required' => ['forum'],
'switchids' => ['forum' => 'forumid', 'user' => 'userid'],
'switchids' => ['forum' => 'forumid', 'user' => 'userid', 'group' => 'groupid'],
],
'posts' => [
'singular' => 'post',
Expand All @@ -62,6 +62,21 @@ protected function get_forum_id(string $idnumber): int {
return $id;
}

/**
* Gets the group id from it's idnumber. It allows using 'All participants' as idnumber.
*
* @throws Exception
* @param string $idnumber
* @return int
*/
protected function get_group_id($idnumber): int {
if ($idnumber === 'All participants') {
return -1;
}

return parent::get_group_id($idnumber);
}

/**
* Preprocess discussion data.
*
Expand Down

0 comments on commit 341039b

Please sign in to comment.