MDL-78498 mod_forum: Prevent race condition in forum recent activity

* Using the generator to create the forum discussions, the timecreated
of a discussion can be set before the user's last course access which
will prevent forum_print_recent_activity() from including this generated
discussion in the recent activity results. To work around this, generate
the forum discussion 1 second after the current time to make sure that
the user's last course access will always be before the discussion's
creation time.
* This patch also includes some optimisations by:
  - Removing the unnecessary @javascript tag for the
    `Time limit expires` scenario
  - Bringing the discussion generation to each scenario to allow each
    scenario to customise the data passed to the generator like for the
    `Time limit expires` scenario.
  - Navigating directly to the forum instance.
This commit is contained in:
Jun Pataleta
2023-08-03 11:31:45 +08:00
parent aeeb1653c0
commit 567f4c0669
@@ -17,14 +17,13 @@ Feature: Students can edit or delete their forum posts within a set time limit
And the following "activities" exist:
| activity | name | course | idnumber |
| forum | Test forum name | C1 | forum |
And I am on the "Course 1" course page logged in as student1
And the following "mod_forum > discussions" exist:
| user | forum | name | message |
| student1 | forum | Forum post subject | This is the body |
And I am on the "Test forum name" "forum activity" page
Scenario: Edit forum post
Given I follow "Forum post subject"
Given the following "mod_forum > discussions" exist:
| user | forum | name | message |
| student1 | forum | Forum post subject | This is the body |
And I am on the "Test forum name" "forum activity" page logged in as "student1"
And I follow "Forum post subject"
And I follow "Edit"
When I set the following fields to these values:
| Subject | Edited post subject |
@@ -35,18 +34,25 @@ Feature: Students can edit or delete their forum posts within a set time limit
And I should see "Edited post body"
Scenario: Delete forum post
Given I follow "Forum post subject"
Given the following "mod_forum > discussions" exist:
| user | forum | name | message |
| student1 | forum | Forum post subject | This is the body |
And I am on the "Test forum name" "forum activity" page logged in as "student1"
And I follow "Forum post subject"
When I follow "Delete"
And I press "Continue"
Then I should not see "Forum post subject"
@javascript @block_recent_activity
@block_recent_activity
Scenario: Time limit expires
Given the following "blocks" exist:
| blockname | contextlevel | reference | pagetypepattern | defaultregion |
| recent_activity | Course | C1 | course-view-* | side-pre |
And the following config values are set as admin:
| maxeditingtime | 1 |
And the following "mod_forum > discussions" exist:
| user | forum | name | message | timemodified |
| student1 | forum | Forum post subject | This is the body | ##now +1 second## |
And I am on the "Course 1" course page logged in as student1
And I should see "New forum posts:" in the "Recent activity" "block"
And I should see "Forum post subject" in the "Recent activity" "block"