From 33b71150249c53375cac286a4a4d524bc8000d41 Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Tue, 20 Dec 2022 15:18:14 +0800 Subject: [PATCH 1/2] MDL-76652 behat: add coverage for postwithoutthrottling logic --- .../discussion_post_threshold_warning.feature | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/mod/forum/tests/behat/discussion_post_threshold_warning.feature b/mod/forum/tests/behat/discussion_post_threshold_warning.feature index f305f395e2a..9059609bf8c 100644 --- a/mod/forum/tests/behat/discussion_post_threshold_warning.feature +++ b/mod/forum/tests/behat/discussion_post_threshold_warning.feature @@ -85,3 +85,42 @@ Feature: An admin or teacher sets the post threshold for blocking and warning And I click on "Test post subject two" "link" When I press "Reply" Then I should see "You are approaching the posting threshold. You have posted 2 times in the last 2 days and the limit is 3 posts." + + @javascript + Scenario: A student with postwithoutthrottling capability should be able to post unlimited number of times + Given the following "permission overrides" exist: + | capability | permission | role | contextlevel | reference | + | mod/forum:postwithoutthrottling | Allow | student | Course | C1 | + And I am on the "Test forum name" "forum activity" page logged in as "teacher1" + And I navigate to "Settings" in current page administration + And I expand all fieldsets + And I set the field "Time period for blocking" to "2 days" + And I set the field "Post threshold for blocking" to "3" + And I set the field "Post threshold for warning" to "2" + And I press "Save and display" + And I log out + And I am on the "Test forum name" "forum activity" page logged in as student1 + And I should see "This forum has a limit to the number of forum postings you can make in a given time period - this is currently set at 3 posting(s) in 2 days" + When I add a new discussion to "Test forum name" forum with: + | Subject | Test post subject one | + | Message | Test post message one | + And I add a new discussion to "Test forum name" forum with: + | Subject | Test post subject two | + | Message | Test post message two | + And I should see "Add discussion topic" + # Verify that when navigated to one of the topics and then click reply the warning notification is shown. + And I click on "Test post subject two" "link" + And I click on "Reply" "link" + # With mod/forum:postwithoutthrottling capability the message below should not be displayed. + And I should not see "You are approaching the posting threshold. You have posted 2 times in the last 2 days and the limit is 3 posts." + And I click on "Test forum name" "link" + And I add a new discussion to "Test forum name" forum with: + | Subject | Test post subject three | + | Message | Test post message three | + Then I should see "Add discussion topic" + # Verify that reply link is available in the posts. + And I click on "Test post subject three" "link" + And I should see "Reply" + And I am on the "Test forum name" "forum activity" page + And I click on "Test post subject two" "link" + And I should see "Reply" From e1204dc4f180a342ab73ba390e4e2f41c5ab4791 Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Tue, 20 Dec 2022 15:31:06 +0800 Subject: [PATCH 2/2] MDL-76652 behat: use data generator and remove duplicated steps --- .../discussion_post_threshold_warning.feature | 44 ++++--------------- 1 file changed, 9 insertions(+), 35 deletions(-) diff --git a/mod/forum/tests/behat/discussion_post_threshold_warning.feature b/mod/forum/tests/behat/discussion_post_threshold_warning.feature index 9059609bf8c..704dc5fc734 100644 --- a/mod/forum/tests/behat/discussion_post_threshold_warning.feature +++ b/mod/forum/tests/behat/discussion_post_threshold_warning.feature @@ -5,32 +5,22 @@ Feature: An admin or teacher sets the post threshold for blocking and warning Background: Given the following "users" exist: | username | firstname | lastname | email | - | teacher1 | Teacher | 1 | teacher1@example.com | | student1 | Student | 1 | student1@example.com | | student2 | Student | 1 | student2@example.com | And the following "courses" exist: | fullname | shortname | category | | Course 1 | C1 | 0 | And the following "course enrolments" exist: - | user | course | role | - | teacher1 | C1 | editingteacher | + | user | course | role | | student1 | C1 | student | | student2 | C1 | student | And the following "activities" exist: - | activity | name | intro | course | idnumber | groupmode | - | forum | Test forum name | Test forum name | C1 | forum | 0 | + | activity | name | course | blockperiod | blockafter | warnafter | + | forum | Test forum name | C1 | 172800 | 3 | 2 | @javascript Scenario: A student should not be able to post new discussion or reply to the existing discussion once the threshold block count is reached - Given I am on the "Test forum name" "forum activity" page logged in as teacher1 - And I navigate to "Settings" in current page administration - And I expand all fieldsets - And I set the field "Time period for blocking" to "2 days" - And I set the field "Post threshold for blocking" to "3" - And I set the field "Post threshold for warning" to "2" - And I press "Save and display" - And I log out - And I am on the "Test forum name" "forum activity" page logged in as student1 + Given I am on the "Test forum name" "forum activity" page logged in as student1 When I add a new discussion to "Test forum name" forum with: | Subject | Test post subject one | | Message | Test post message one | @@ -60,15 +50,7 @@ Feature: An admin or teacher sets the post threshold for blocking and warning @javascript Scenario: A student should see warning when the post is about to reach threshold when experimental nested discussion view is set - Given I am on the "Test forum name" "forum activity" page logged in as teacher1 - And I navigate to "Settings" in current page administration - And I expand all fieldsets - And I set the field "Time period for blocking" to "2 days" - And I set the field "Post threshold for blocking" to "3" - And I set the field "Post threshold for warning" to "2" - And I press "Save and display" - And I log out - And I am on the "Test forum name" "forum activity" page logged in as student1 + Given I am on the "Test forum name" "forum activity" page logged in as student1 When I add a new discussion to "Test forum name" forum with: | Subject | Test post subject one | | Message | Test post message one | @@ -87,18 +69,10 @@ Feature: An admin or teacher sets the post threshold for blocking and warning Then I should see "You are approaching the posting threshold. You have posted 2 times in the last 2 days and the limit is 3 posts." @javascript - Scenario: A student with postwithoutthrottling capability should be able to post unlimited number of times + Scenario: A student with 'mod/forum:postwithoutthrottling' capability should be able to post unlimited number of times Given the following "permission overrides" exist: - | capability | permission | role | contextlevel | reference | - | mod/forum:postwithoutthrottling | Allow | student | Course | C1 | - And I am on the "Test forum name" "forum activity" page logged in as "teacher1" - And I navigate to "Settings" in current page administration - And I expand all fieldsets - And I set the field "Time period for blocking" to "2 days" - And I set the field "Post threshold for blocking" to "3" - And I set the field "Post threshold for warning" to "2" - And I press "Save and display" - And I log out + | capability | permission | role | contextlevel | reference | + | mod/forum:postwithoutthrottling | Allow | student | Course | C1 | And I am on the "Test forum name" "forum activity" page logged in as student1 And I should see "This forum has a limit to the number of forum postings you can make in a given time period - this is currently set at 3 posting(s) in 2 days" When I add a new discussion to "Test forum name" forum with: @@ -111,7 +85,7 @@ Feature: An admin or teacher sets the post threshold for blocking and warning # Verify that when navigated to one of the topics and then click reply the warning notification is shown. And I click on "Test post subject two" "link" And I click on "Reply" "link" - # With mod/forum:postwithoutthrottling capability the message below should not be displayed. + # With 'mod/forum:postwithoutthrottling' assigned capability the message below should not be displayed. And I should not see "You are approaching the posting threshold. You have posted 2 times in the last 2 days and the limit is 3 posts." And I click on "Test forum name" "link" And I add a new discussion to "Test forum name" forum with: