From da4d17313d087993ca65ed662d3274c54db7065b Mon Sep 17 00:00:00 2001 From: Alexander Bias Date: Mon, 8 Oct 2018 22:49:36 +0200 Subject: [PATCH] MDL-60710 course: Overhaul of Behat tests --- course/tests/behat/behat_course.php | 34 ---- course/tests/behat/course_contact.feature | 233 +++++++++------------- 2 files changed, 93 insertions(+), 174 deletions(-) diff --git a/course/tests/behat/behat_course.php b/course/tests/behat/behat_course.php index 557d94e124a..93b88603692 100644 --- a/course/tests/behat/behat_course.php +++ b/course/tests/behat/behat_course.php @@ -1923,38 +1923,4 @@ class behat_course extends behat_base { throw new ExpectationException($msg, $this->getSession()); } } - - /** - * Moves up the specified role. - * - * @Given /^I move up role "(?P(?:[^"]|\\")*)" in the global role sortorder$/ - * @param String $role - */ - public function i_move_up_role($role) { - global $DB; - $roledb = $DB->get_record('role', array('shortname' => $role), 'id, sortorder', MUST_EXIST); - $query = "SELECT id, sortorder FROM {role} WHERE sortorder < ".$roledb->sortorder." ORDER BY sortorder DESC"; - $previousroles = $DB->get_records_sql($query, null, 0, 1); - foreach ($previousroles as $id => $previousrole) { - switch_roles($previousrole, $roledb); - break; - } - } - - /** - * Moves down the specified role. - * - * @Given /^I move down role "(?P(?:[^"]|\\")*)" in the global role sortorder$/ - * @param String $role - */ - public function i_move_down_role($role) { - global $DB; - $roledb = $DB->get_record('role', array('shortname' => $role), 'id, sortorder', MUST_EXIST); - $query = "SELECT id, sortorder FROM {role} WHERE sortorder > " . $roledb->sortorder . " ORDER BY sortorder ASC"; - $previousroles = $DB->get_records_sql($query, null, 0, 1); - foreach ($previousroles as $id => $previousrole) { - switch_roles($previousrole, $roledb); - break; - } - } } diff --git a/course/tests/behat/course_contact.feature b/course/tests/behat/course_contact.feature index e8ed7d0e607..78e2e01d48c 100644 --- a/course/tests/behat/course_contact.feature +++ b/course/tests/behat/course_contact.feature @@ -1,22 +1,22 @@ @core @core_course -Feature: Test we can see coursecontacts. - As a student I need to see coursecontacts - As a admin I need to test we can resort coursecontacts. - As a admin I need to test we can show duplicate course contacts - Scenario: Test coursecontacts functionality +Feature: Test if displaying the course contacts works correctly: + As a user I need to see the course contacts of a course. + As an admin I need to be able to control the appearance of the course contacts. + + Background: Given the following "categories" exist: | name | category | idnumber | | Cat 1 | 0 | CAT1 | And the following "courses" exist: | fullname | shortname | category | format | | Course 1 | C1 | CAT1 | topics | - Given the following "users" exist: + And the following "users" exist: | username | firstname | lastname | email | - | teacher1 | Teacher 1 | T | teacher1@example.com | - | teacher2 | Teacher 2 | T | teacher2@example.com | - | teacher3 | Teacher 3 | T | teacher3@example.com | - | manager1 | Manager 1 | M | manager1@example.com | - | student1 | Student 1 | S | student1@example.com | + | teacher1 | Teacher | 1 | teacher1@example.com | + | teacher2 | Teacher | 2 | teacher2@example.com | + | teacher3 | Teacher | 3 | teacher3@example.com | + | manager1 | Manager | 1 | manager1@example.com | + | student1 | Student | 1 | student1@example.com | And the following "course enrolments" exist: | user | course | role | | teacher1 | C1 | editingteacher | @@ -24,175 +24,128 @@ Feature: Test we can see coursecontacts. | teacher2 | C1 | teacher | | teacher3 | C1 | editingteacher | | manager1 | C1 | manager | - And I log in as "admin" - And I am on course index + + Scenario: Test general course contacts functionality for all user roles + Given I log in as "admin" + And I navigate to "Appearance > Courses" in site administration + And I set the following fields to these values: + | Manager | 0 | + | Teacher | 1 | + | Non-editing teacher | 0 | + | Display all course contact roles | 0 | + And I press "Save changes" + + When I am on course index And I should see "Cat 1" in the "#region-main" "css_element" And I follow "Cat 1" And I wait until the page is ready And I should see "Course 1" in the "#region-main" "css_element" - And I should see "Teacher 1" in the "#region-main" "css_element" - And I should not see "Teacher 2" in the "#region-main" "css_element" - And I log out + Then I should see "Teacher 1" in the ".teachers" "css_element" + And I should not see "Teacher 2" in the ".teachers" "css_element" + And I should not see "Manager 1" in the ".teachers" "css_element" + + When I log out And I log in as "manager1" And I am on course index And I should see "Cat 1" in the "#region-main" "css_element" And I follow "Cat 1" And I wait until the page is ready And I should see "Course 1" in the "#region-main" "css_element" - And I should see "Teacher 1" in the "#region-main" "css_element" - And I should not see "Teacher 2" in the "#region-main" "css_element" - And I log out + Then I should see "Teacher 1" in the ".teachers" "css_element" + And I should not see "Teacher 2" in the ".teachers" "css_element" + And I should not see "Manager 1" in the ".teachers" "css_element" + + When I log out And I log in as "teacher1" And I am on course index And I should see "Cat 1" in the "#region-main" "css_element" And I follow "Cat 1" And I wait until the page is ready And I should see "Course 1" in the "#region-main" "css_element" - And I should see "Teacher 1" in the "#region-main" "css_element" - And I should not see "Teacher 2" in the "#region-main" "css_element" - And I log out + Then I should see "Teacher 1" in the ".teachers" "css_element" + And I should not see "Teacher 2" in the ".teachers" "css_element" + And I should not see "Manager 1" in the ".teachers" "css_element" + + When I log out And I log in as "student1" And I am on course index And I should see "Cat 1" in the "#region-main" "css_element" And I follow "Cat 1" And I wait until the page is ready And I should see "Course 1" in the "#region-main" "css_element" - And I should see "Teacher 1" in the "#region-main" "css_element" - And I should not see "Teacher 2" in the "#region-main" "css_element" - And I should see teacher "Teacher 1 T" before "Teacher 3 T" in the course contact listing - And I should not see teacher "Teacher 1 T" after "Teacher 3 T" in the course contact listing - And I log out - Scenario: Test selection and duplicates of coursecontact roles - Given the following "categories" exist: - | name | category | idnumber | - | Cat 1 | 0 | CAT1 | - And the following "courses" exist: - | fullname | shortname | category | format | - | Course 1 | C1 | CAT1 | topics | - Given the following "users" exist: - | username | firstname | lastname | email | - | teacher1 | Teacher 1 | T | teacher1@example.com | - | teacher2 | Teacher 2 | T | teacher2@example.com | - | teacher3 | Teacher 3 | T | teacher3@example.com | - | manager1 | Manager 1 | M | manager1@example.com | - | student1 | Student 1 | S | student1@example.com | - And the following "course enrolments" exist: - | user | course | role | - | teacher1 | C1 | editingteacher | - | teacher1 | C1 | teacher | - | teacher2 | C1 | teacher | - | teacher3 | C1 | editingteacher | - | manager1 | C1 | manager | - And I log in as "admin" - And I am on course index - And I should see "Cat 1" in the "#region-main" "css_element" - And I follow "Cat 1" - And I wait until the page is ready - And I should see "Course 1" in the "#region-main" "css_element" - And I should see "Teacher 1" in the "#region-main" "css_element" - And I should not see "Teacher 2" in the "#region-main" "css_element" - And I should not see "Manager 1" in the "#region-main" "css_element" - And I am on site homepage - And I navigate to "Appearance > Courses" in site administration - And I set the following fields to these values: - | Manager | 1 | - | Non-editing teacher | 1 | - | Show duplicate course contacts | 1 | - And I press "Save changes" - And I am on course index - And I should see "Cat 1" in the "#region-main" "css_element" - And I follow "Cat 1" - And I wait until the page is ready - And I should see "Course 1" in the "#region-main" "css_element" - And I should see "Teacher 1" in the "#region-main" "css_element" - And I should see "Teacher 2" in the "#region-main" "css_element" - And I should see "Teacher 3" in the "#region-main" "css_element" - And I should see "Manager 1" in the "#region-main" "css_element" - And I should see teacher "Manager 1 M" before "Teacher 1 T" in the course contact listing - And I should see teacher "Teacher 1 T" before "Teacher 3 T" in the course contact listing - And I should see teacher "Teacher 3 T" before "Teacher 2 T" in the course contact listing - And I am on site homepage + Then I should see "Teacher 1" in the ".teachers" "css_element" + And I should not see "Teacher 2" in the ".teachers" "css_element" + And I should not see "Manager 1" in the ".teachers" "css_element" + + Scenario: Test course contact roles without displaying all roles + Given I log in as "admin" And I navigate to "Appearance > Courses" in site administration And I set the following fields to these values: | Manager | 0 | + | Teacher | 1 | + | Non-editing teacher | 1 | + | Display all course contact roles | 0 | And I press "Save changes" - And I log out - And I log in as "admin" - And I am on course index + When I am on course index And I should see "Cat 1" in the "#region-main" "css_element" And I follow "Cat 1" And I wait until the page is ready And I should see "Course 1" in the "#region-main" "css_element" - And I should see "Teacher 1" in the "#region-main" "css_element" - And I should not see "Manager 1" in the "#region-main" "css_element" - Scenario: Test selection of coursecontact roles - Given the following "categories" exist: - | name | category | idnumber | - | Cat 1 | 0 | CAT1 | - And the following "courses" exist: - | fullname | shortname | category | format | - | Course 1 | C1 | CAT1 | topics | - Given the following "users" exist: - | username | firstname | lastname | email | - | teacher1 | Teacher 1 | T | teacher1@example.com | - | teacher2 | Teacher 2 | T | teacher2@example.com | - | teacher3 | Teacher 3 | T | teacher3@example.com | - | manager1 | Manager 1 | M | manager1@example.com | - | manager2 | Manager 2 | M | manager1@example.com | - | student1 | Student 1 | S | student1@example.com | - And the following "course enrolments" exist: - | user | course | role | - | teacher1 | C1 | editingteacher | - | teacher1 | C1 | teacher | - | teacher2 | C1 | teacher | - | teacher3 | C1 | editingteacher | - | manager1 | C1 | manager | - And I log in as "admin" + Then I should see "Teacher 1" in the ".teachers" "css_element" + And I should see "Teacher 2" in the ".teachers" "css_element" + And I should see "Teacher 3" in the ".teachers" "css_element" + And I should see "Teacher: Teacher 1" in the ".teachers" "css_element" + And I should not see "Teacher, Non-editing teacher: Teacher 1" in the ".teachers" "css_element" + And I should not see "Manager 1" in the ".teachers" "css_element" + + Scenario: Test course contact roles with displaying all roles and standard sorting + Given I log in as "admin" And I navigate to "Appearance > Courses" in site administration And I set the following fields to these values: - | Manager | Yes | - | Non-editing teacher | Yes | - | Show duplicate course contacts | Yes | + | Manager | 0 | + | Teacher | 1 | + | Non-editing teacher | 1 | + | Display all course contact roles | 1 | And I press "Save changes" - And I am on course index + When I am on course index And I should see "Cat 1" in the "#region-main" "css_element" And I follow "Cat 1" And I wait until the page is ready And I should see "Course 1" in the "#region-main" "css_element" - And I should see "Teacher 1" in the "#region-main" "css_element" - And I should see "Teacher 2" in the "#region-main" "css_element" - And I should see "Teacher 3" in the "#region-main" "css_element" - And I should see "Manager 1" in the "#region-main" "css_element" - And I should see teacher "Manager 1 M" before "Teacher 1 T" in the course contact listing - And I should see teacher "Teacher 1 T" before "Teacher 3 T" in the course contact listing - And I should see teacher "Teacher 3 T" before "Teacher 2 T" in the course contact listing + Then I should see "Teacher 1" in the ".teachers" "css_element" + And I should see "Teacher 2" in the ".teachers" "css_element" + And I should see "Teacher 3" in the ".teachers" "css_element" + And I should see "Teacher, Non-editing teacher: Teacher 1" in the ".teachers" "css_element" + And I should not see "Teacher: Teacher 1" in the ".teachers" "css_element" + And I should not see "Manager 1" in the ".teachers" "css_element" + And I should see teacher "Teacher 1" before "Teacher 3" in the course contact listing + And I should see teacher "Teacher 3" before "Teacher 2" in the course contact listing + And I should not see teacher "Teacher 1" after "Teacher 3" in the course contact listing + And I should not see teacher "Teacher 3" after "Teacher 2" in the course contact listing + + Scenario: Test course contact roles with displaying all roles and modified sorting + Given I log in as "admin" And I navigate to "Appearance > Courses" in site administration - And I move up role "teacher" in the global role sortorder - And I move up role "teacher" in the global role sortorder - And I move up role "teacher" in the global role sortorder - And I move up role "teacher" in the global role sortorder - And I move up role "teacher" in the global role sortorder - And I move up role "teacher" in the global role sortorder - And I move up role "teacher" in the global role sortorder - And I move up role "teacher" in the global role sortorder + And I set the following fields to these values: + | Manager | 0 | + | Teacher | 1 | + | Non-editing teacher | 1 | + | Display all course contact roles | 1 | And I press "Save changes" - And I am on site homepage - And I follow "Course 1" - And I log out - And I log in as "admin" - And I am on course index - And I follow "Purge all caches" - And I wait until the page is ready - And I am on course index + And I navigate to "Users > Permissions > Define roles" in site administration + And I click on "Move up" "link" in the "//td[text()[contains(.,'Non-editing teacher')]]/parent::tr/td[contains(@class, 'lastcol')]" "xpath_element" + When I am on course index And I should see "Cat 1" in the "#region-main" "css_element" And I follow "Cat 1" And I wait until the page is ready And I should see "Course 1" in the "#region-main" "css_element" - And I should see "Teacher 1" in the "#region-main" "css_element" - And I should see "Teacher 2" in the "#region-main" "css_element" - And I should see "Teacher 3" in the "#region-main" "css_element" - And I should not see teacher "Teacher 2 T" after "Manager 1 M" in the course contact listing - And I should not see teacher "Teacher 2 T" after "Teacher 3 T" in the course contact listing - And I should see teacher "Teacher 1 T" before "Manager 1 M" in the course contact listing - And I should not see teacher "Teacher 2 T" after "Manager 1 M" in the course contact listing - And I should not see teacher "Teacher 2 T" after "Teacher 3 T" in the course contact listing + Then I should see "Teacher 1" in the ".teachers" "css_element" + And I should see "Teacher 2" in the ".teachers" "css_element" + And I should see "Teacher 3" in the ".teachers" "css_element" + And I should see "Non-editing teacher, Teacher: Teacher 1" in the ".teachers" "css_element" + And I should not see "Non-editing teacher: Teacher 1" in the ".teachers" "css_element" + And I should not see "Manager 1" in the ".teachers" "css_element" + And I should see teacher "Teacher 1" before "Teacher 2" in the course contact listing + And I should see teacher "Teacher 2" before "Teacher 3" in the course contact listing + And I should not see teacher "Teacher 1" after "Teacher 2" in the course contact listing + And I should not see teacher "Teacher 2" after "Teacher 3" in the course contact listing