From 341039b13bf69bc44d435c49d158313bde499aa7 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Fri, 27 May 2022 12:06:05 +0200 Subject: [PATCH] MDL-74864 forum: Allow specifying group in discussions generator --- .../behat/separate_group_discussions.feature | 40 +++++++++++----- .../behat/visible_group_discussions.feature | 48 ++++++++++++++++--- .../generator/behat_mod_forum_generator.php | 17 ++++++- 3 files changed, 85 insertions(+), 20 deletions(-) diff --git a/mod/forum/tests/behat/separate_group_discussions.feature b/mod/forum/tests/behat/separate_group_discussions.feature index bd1fa247c53..c75cd8be9ba 100644 --- a/mod/forum/tests/behat/separate_group_discussions.feature +++ b/mod/forum/tests/behat/separate_group_discussions.feature @@ -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" @@ -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" + Given I log in as "student1" 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" - 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" diff --git a/mod/forum/tests/behat/visible_group_discussions.feature b/mod/forum/tests/behat/visible_group_discussions.feature index d18013e35a4..b4b283d31ca 100644 --- a/mod/forum/tests/behat/visible_group_discussions.feature +++ b/mod/forum/tests/behat/visible_group_discussions.feature @@ -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" @@ -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" diff --git a/mod/forum/tests/generator/behat_mod_forum_generator.php b/mod/forum/tests/generator/behat_mod_forum_generator.php index eb7aa79fe88..5c16677796d 100644 --- a/mod/forum/tests/generator/behat_mod_forum_generator.php +++ b/mod/forum/tests/generator/behat_mod_forum_generator.php @@ -35,7 +35,7 @@ class behat_mod_forum_generator extends behat_generator_base { 'singular' => 'discussion', 'datagenerator' => 'discussion', 'required' => ['forum'], - 'switchids' => ['forum' => 'forumid', 'user' => 'userid'], + 'switchids' => ['forum' => 'forumid', 'user' => 'userid', 'group' => 'groupid'], ], 'posts' => [ 'singular' => 'post', @@ -62,6 +62,21 @@ class behat_mod_forum_generator extends behat_generator_base { 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. *