MDL-78843 behat: update get_forum_id to search for idnumber or name

This commit also converts manual steps to create discussions on the
Annoucements forum to data generator.
This commit is contained in:
Simey Lameze 2023-08-02 10:16:00 +08:00
parent 6f40d9ffd7
commit aa0785431a
4 changed files with 26 additions and 50 deletions

View file

@ -18,17 +18,12 @@ Feature: Latest announcements block displays the course latest news
And the following "blocks" exist: And the following "blocks" exist:
| blockname | contextlevel | reference | pagetypepattern | defaultregion | | blockname | contextlevel | reference | pagetypepattern | defaultregion |
| news_items | Course | C1 | course-view-* | side-pre | | news_items | Course | C1 | course-view-* | side-pre |
And I am on the "Course 1" Course page logged in as teacher1 And the following "mod_forum > discussions" exist:
When I add a new topic to "Announcements" forum with: | user | forum | name | message |
| Subject | Discussion One | | teacher1 | Announcements | Discussion One | Not important |
| Message | Not important | | teacher1 | Announcements | Discussion Two | Not important |
And I add a new topic to "Announcements" forum with: | teacher1 | Announcements | Discussion Three | Not important |
| Subject | Discussion Two | When I am on the "Course 1" Course page logged in as teacher1
| Message | Not important |
And I add a new topic to "Announcements" forum with:
| Subject | Discussion Three |
| Message | Not important |
And I am on "Course 1" course homepage
Then I should see "Discussion One" in the "Latest announcements" "block" Then I should see "Discussion One" in the "Latest announcements" "block"
And I should see "Discussion Two" in the "Latest announcements" "block" And I should see "Discussion Two" in the "Latest announcements" "block"
And I should see "Discussion Three" in the "Latest announcements" "block" And I should see "Discussion Three" in the "Latest announcements" "block"

View file

@ -23,6 +23,9 @@ Feature: The search forums block allows users to search for forum posts on cours
And I am on the "Course 1" "course editing" page logged in as teacher1 And I am on the "Course 1" "course editing" page logged in as teacher1
And I set the field "id_newsitems" to "1" And I set the field "id_newsitems" to "1"
And I press "Save and display" And I press "Save and display"
And the following "mod_forum > discussions" exist:
| user | forum | name | message |
| teacher1 | Announcements | My subject | My message |
Scenario: Use the search forum block in a course without any forum posts Scenario: Use the search forum block in a course without any forum posts
Given I am on the "Course 1" course page logged in as student1 Given I am on the "Course 1" course page logged in as student1
@ -31,12 +34,7 @@ Feature: The search forums block allows users to search for forum posts on cours
Then I should see "No posts" Then I should see "No posts"
Scenario: Use the search forum block in a course with a hidden forum and search for posts Scenario: Use the search forum block in a course with a hidden forum and search for posts
Given I add a new topic to "Announcements" forum with: Given I am on the "Announcements" "forum activity editing" page logged in as teacher1
| Subject | My subject |
| Message | My message |
And I am on "Course 1" course homepage with editing mode on
And I follow "Announcements"
And I navigate to "Settings" in current page administration
And I expand all fieldsets And I expand all fieldsets
And I set the field "id_visible" to "0" And I set the field "id_visible" to "0"
And I press "Save and return to course" And I press "Save and return to course"
@ -47,10 +45,7 @@ Feature: The search forums block allows users to search for forum posts on cours
Then I should see "No posts" Then I should see "No posts"
Scenario: Use the search forum block in a course and search for posts Scenario: Use the search forum block in a course and search for posts
Given I add a new topic to "Announcements" forum with: Given I am on the "Course 1" course page logged in as student1
| Subject | My subject |
| Message | My message |
When I am on the "Course 1" course page logged in as student1
And "Search forums" "block" should exist And "Search forums" "block" should exist
And I set the field "Search" to "message" And I set the field "Search" to "message"
And I press "Search" And I press "Search"

View file

@ -11,8 +11,8 @@ Feature: The forum search allows users to perform advanced searches for forum po
| teacher2 | Teacher | TWO | teacher2@example.com | T1 | | teacher2 | Teacher | TWO | teacher2@example.com | T1 |
| student1 | Student | 1 | student1@example.com | S1 | | student1 | Student | 1 | student1@example.com | S1 |
And the following "courses" exist: And the following "courses" exist:
| fullname | shortname | category | | fullname | shortname | category | newsitems |
| Course 1 | C1 | 0 | | Course 1 | C1 | 0 | 1 |
And the following "course enrolments" exist: And the following "course enrolments" exist:
| user | course | role | | user | course | role |
| teacher1 | C1 | editingteacher | | teacher1 | C1 | editingteacher |
@ -24,17 +24,10 @@ Feature: The forum search allows users to perform advanced searches for forum po
And the following "blocks" exist: And the following "blocks" exist:
| blockname | contextlevel | reference | pagetypepattern | defaultregion | | blockname | contextlevel | reference | pagetypepattern | defaultregion |
| news_items | Course | C1 | course-view-* | side-pre | | news_items | Course | C1 | course-view-* | side-pre |
And I am on the "Course 1" "course editing" page logged in as teacher1 And the following "mod_forum > discussions" exist:
And I expand all fieldsets | user | forum | name | subject | message |
And I set the field "id_newsitems" to "1" | teacher1 | Announcements | My subject | My subject | My message |
And I press "Save and display" | teacher1 | Announcements | Your subjective | Your subjective | Your long message |
And I add a new topic to "Announcements" forum with:
| Subject | My subject |
| Message | My message |
And I am on "Course 1" course homepage
And I add a new topic to "Announcements" forum with:
| Subject | Your subjective|
| Message | Your long message |
Scenario: Perform an advanced search using any term Scenario: Perform an advanced search using any term
Given I am on the "Announcements" "forum activity" page logged in as student1 Given I am on the "Announcements" "forum activity" page logged in as student1
@ -77,12 +70,11 @@ Feature: The forum search allows users to perform advanced searches for forum po
And I should see "Your subjective" And I should see "Your subjective"
Scenario: Perform an advanced search matching the author Scenario: Perform an advanced search matching the author
Given I am on the "Course 1" course page logged in as teacher2 Given the following "mod_forum > discussions" exist:
And I add a new topic to "Announcements" forum with: | user | forum | name | subject | message |
| Subject | My Subjects | | teacher2 | Announcements | My Subjects | My Subjects | My message |
| Message | My message | And I am on the "Announcements" "forum activity" page logged in as student1
When I am on the "Announcements" "forum activity" page logged in as student1 When I press "Search"
And I press "Search"
And I should see "Please enter search terms into one or more of the following fields" And I should see "Please enter search terms into one or more of the following fields"
And I set the field "user" to "TWO" And I set the field "user" to "TWO"
And I press "Search" And I press "Search"

View file

@ -47,19 +47,13 @@ class behat_mod_forum_generator extends behat_generator_base {
} }
/** /**
* Get the forum id using an activity idnumber. * Get the forum id using an activity idnumber or name.
* *
* @param string $idnumber * @param string $idnumberorname The forum activity idnumber or name.
* @return int The forum id * @return int The forum id
*/ */
protected function get_forum_id(string $idnumber): int { protected function get_forum_id(string $idnumberorname): int {
global $DB; return $this->get_cm_by_activity_name('forum', $idnumberorname)->instance;
if (!$id = $DB->get_field('course_modules', 'instance', ['idnumber' => $idnumber])) {
throw new Exception('The specified activity with idnumber "' . $idnumber . '" could not be found.');
}
return $id;
} }
/** /**