Skip to content

Commit

Permalink
added Behat tests for search
Browse files Browse the repository at this point in the history
  • Loading branch information
rtschu committed Nov 30, 2020
1 parent 39dd4c0 commit a27adcf
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/behat/behat_mod_moodleoverflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,38 @@ protected function add_new_discussion($moodleoverflowname, TableNode $table, $bu
$this->execute('behat_forms::press_button', get_string('posttomoodleoverflow', 'moodleoverflow'));
$this->execute('behat_general::i_wait_to_be_redirected');
}

/**
* @Given I go to :link
*/
public function i_go_to($link) {
$this->visitPath($link);
}

/**
* Fills in form field with specified id|name|label|value
* Example: When I fill in "username" with: "bwayne"
* Example: And I fill in "bwayne" for "username"
*
* @When /^(?:|I )fill in "(?P<field>(?:[^"]|\\")*)" with "(?P<value>(?:[^"]|\\")*)"$/
* @When /^(?:|I )fill in "(?P<field>(?:[^"]|\\")*)" with:$/
* @When /^(?:|I )fill in "(?P<value>(?:[^"]|\\")*)" for "(?P<field>(?:[^"]|\\")*)"$/
*/
public function fill_field($field, $value) {
$field = $this->fix_step_argument($field);
$value = $this->fix_step_argument($value);
$this->getSession()->getPage()->fillField($field, $value);
}

/**
* Returns fixed step argument (with \\" replaced back to ")
*
* @param string $argument
*
* @return string
*/
protected function fix_step_argument($argument) {
return str_replace('\\"', '"', $argument);
}

}
62 changes: 62 additions & 0 deletions tests/behat/test_search.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
@mod @mod_moodleoverflow @mod_moodleoverflow_search
Feature: Add moodleoverflow activities and discussions
In order to find discussions
I need to be able to search them

Background: : Add a moodleoverflow and a discussion
Given the following config values are set as admin:
| enableglobalsearch | 1 |
| searchengine | simpledb |
And the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
| student2 | Student | 2 | 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 |
| student1 | C1 | student |
And I log in as "teacher1"
And I am on "Course 1" course homepage
And I turn editing mode on
And I add a "Moodleoverflow" to section "1" and I fill the form with:
| Moodleoverflow name | Test moodleoverflow name |
| Description | Test forum description |
And I log out
And I log in as "student1"
And I am on "Course 1" course homepage
And I add a new discussion to "Test moodleoverflow name" moodleoverflow with:
| Subject | Forum post 1 |
| Message | This is the body |
And I log out
And I log in as "teacher1"
And I update the global search index
And I log out

Scenario: As a teacher I should see all discussions in my course
Given I log in as "teacher1"
And I go to "search/index.php"
And I fill in "id_q" with "Forum post 1"
And I press "id_submitbutton"
Then I should see "Forum post 1"
And I should see "This is the body"

Scenario: As an enrolled student I should see all discussions in my course
Given I log in as "student1"
And I go to "search/index.php"
And I fill in "id_q" with "Forum post 1"
And I press "id_submitbutton"
Then I should see "Forum post 1"
And I should see "This is the body"

@test
Scenario: As an unenrolled student I should see all discussions in my course
Given I log in as "student2"
And I go to "search/index.php"
And I fill in "id_q" with "Forum post 1"
And I press "id_submitbutton"
Then I should not see "Forum post 1"
And I should not see "This is the body"

0 comments on commit a27adcf

Please sign in to comment.