Skip to content

Commit

Permalink
MDL-78843 behat: update get_forum_id to search for idnumber or name
Browse files Browse the repository at this point in the history
This commit also converts manual steps to create discussions on the
Annoucements forum to data generator.
  • Loading branch information
lameze committed Aug 10, 2023
1 parent af934a7 commit a60977e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 52 deletions.
17 changes: 6 additions & 11 deletions blocks/news_items/tests/behat/display_news.feature
Expand Up @@ -18,17 +18,12 @@ Feature: Latest announcements block displays the course latest news
And the following "blocks" exist:
| blockname | contextlevel | reference | pagetypepattern | defaultregion |
| news_items | Course | C1 | course-view-* | side-pre |
And I am on the "Course 1" Course page logged in as teacher1
When I add a new topic to "Announcements" forum with:
| Subject | Discussion One |
| Message | Not important |
And I add a new topic to "Announcements" forum with:
| Subject | Discussion Two |
| 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
And the following "mod_forum > discussions" exist:
| user | forum | name | message |
| teacher1 | Announcements | Discussion One | Not important |
| teacher1 | Announcements | Discussion Two | Not important |
| teacher1 | Announcements | Discussion Three | Not important |
When I am on the "Course 1" Course page logged in as teacher1
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 Three" in the "Latest announcements" "block"
Expand Down
Expand Up @@ -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 set the field "id_newsitems" to "1"
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
Given I am on the "Course 1" course page logged in as student1
Expand All @@ -32,12 +35,7 @@ Feature: The search forums block allows users to search for forum posts on cours
Then I should see "No 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:
| 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 "Edit settings" in current page administration
Given I am on the "Announcements" "forum activity editing" page logged in as teacher1
And I expand all fieldsets
And I set the field "id_visible" to "0"
And I press "Save and return to course"
Expand All @@ -49,10 +47,7 @@ Feature: The search forums block allows users to search for forum posts on cours
Then I should see "No posts"

Scenario: Use the search forum block in a course and search for posts
Given I add a new topic to "Announcements" forum with:
| Subject | My subject |
| Message | My message |
When 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
And "Search forums" "block" should exist
And I set the following fields to these values:
| searchform_search | message |
Expand Down
32 changes: 11 additions & 21 deletions mod/forum/tests/behat/advanced_search.feature
Expand Up @@ -11,8 +11,8 @@ Feature: The forum search allows users to perform advanced searches for forum po
| teacher2 | Teacher | TWO | teacher2@example.com | T1 |
| student1 | Student | 1 | student1@example.com | S1 |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
| fullname | shortname | category | newsitems |
| Course 1 | C1 | 0 | 1 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
Expand All @@ -24,17 +24,10 @@ Feature: The forum search allows users to perform advanced searches for forum po
And the following "blocks" exist:
| blockname | contextlevel | reference | pagetypepattern | defaultregion |
| news_items | Course | C1 | course-view-* | side-pre |
And I am on the "Course 1" "course editing" page logged in as teacher1
And I expand all fieldsets
And I set the field "id_newsitems" to "1"
And I press "Save and display"
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 |
And the following "mod_forum > discussions" exist:
| user | forum | name | subject | message |
| teacher1 | Announcements | My subject | My subject | My message |
| teacher1 | Announcements | Your subjective | Your subjective | Your long message |

Scenario: Perform an advanced search using any term
Given I am on the "Announcements" "forum activity" page logged in as student1
Expand Down Expand Up @@ -77,14 +70,11 @@ Feature: The forum search allows users to perform advanced searches for forum po
And I should see "Your subjective"

Scenario: Perform an advanced search matching the author
Given I log in as "teacher2"
And I am on "Course 1" course homepage
And I add a new topic to "Announcements" forum with:
| Subject | My Subjects |
| Message | My message |
And I log out
When I am on the "Announcements" "forum activity" page logged in as student1
And I press "Search forums"
Given the following "mod_forum > discussions" exist:
| user | forum | name | subject | message |
| teacher2 | Announcements | My Subjects | My Subjects | My message |
And I am on the "Announcements" "forum activity" page logged in as student1
When I press "Search forums"
And I should see "Advanced search"
And I set the field "user" to "TWO"
And I press "Search forums"
Expand Down
14 changes: 4 additions & 10 deletions mod/forum/tests/generator/behat_mod_forum_generator.php
Expand Up @@ -47,19 +47,13 @@ protected function get_creatable_entities(): array {
}

/**
* 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
*/
protected function get_forum_id(string $idnumber): int {
global $DB;

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;
protected function get_forum_id(string $idnumberorname): int {
return $this->get_cm_by_activity_name('forum', $idnumberorname)->instance;
}

/**
Expand Down

0 comments on commit a60977e

Please sign in to comment.