diff --git a/mod/forum/classes/local/vaults/discussion_list.php b/mod/forum/classes/local/vaults/discussion_list.php index 41866143d3c..e099a671ae0 100644 --- a/mod/forum/classes/local/vaults/discussion_list.php +++ b/mod/forum/classes/local/vaults/discussion_list.php @@ -350,7 +350,7 @@ class discussion_list extends db_table_vault { $favouritesort .= ", {$favalias}.itemtype DESC"; } - return "{$alias}.pinned DESC $favouritesort , {$keyfield} {$direction}"; + return "{$alias}.pinned DESC $favouritesort , {$keyfield} {$direction}, {$alias}.id {$direction}"; } /** diff --git a/mod/forum/tests/behat/discussion_navigation.feature b/mod/forum/tests/behat/discussion_navigation.feature index 4caa84a7081..045547a63d0 100644 --- a/mod/forum/tests/behat/discussion_navigation.feature +++ b/mod/forum/tests/behat/discussion_navigation.feature @@ -51,6 +51,11 @@ Feature: A user can navigate to previous and next discussions And I follow "Reply" And I set the following fields to these values: | Message | Answer to discussion | + # We need to wait a bit to guarantee that the post is created after the previous ones. + # because there is a bug in the forum_get_discussion_neighbours() when all the discussion + # last modified times are the same. See MDL-79247 for more details. Once that bug is fixed + # we can remove this wait. + And I wait "1" seconds And I press "Post to forum" And I should not see "Discussion 2" And I should see "Discussion 3"