moodle/availability/condition/profile/tests/behat/availability_profile.feature
Simey Lameze fdeeaff954 MDL-58265 core_test: replace I turn editing on steps
Also remove few more unnecessary steps that redirects behat to
site home page to actually get to the course.

Part of MDL-55611 epic.
2017-04-03 11:37:07 +08:00

108 lines
4.2 KiB
Gherkin

@availability @availability_profile
Feature: availability_profile
In order to control student access to activities
As a teacher
I need to set profile conditions which prevent student access
Background:
Given the following "courses" exist:
| fullname | shortname | format | enablecompletion |
| Course 1 | C1 | topics | 1 |
And the following "users" exist:
| username | email |
| teacher1 | t@example.com |
| student1 | s@example.com |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
@javascript
Scenario: Test condition
# Basic setup.
Given I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
# Add
And I add a "Page" to section "1"
And I set the following fields to these values:
| Name | P1 |
| Description | x |
| Page content | x |
And I expand all fieldsets
And I click on "Add restriction..." "button"
And I click on "User profile" "button"
And I set the field "User profile field" to "Email address"
And I set the field "Value to compare against" to "s@example.com"
And I click on ".availability-item .availability-eye img" "css_element"
And I click on "Save and return to course" "button"
# Add
And I add a "Page" to section "2"
And I set the following fields to these values:
| Name | P2 |
| Description | x |
| Page content | x |
And I expand all fieldsets
And I click on "Add restriction..." "button"
And I click on "User profile" "button"
And I set the field "User profile field" to "Email address"
And I set the field "Value to compare against" to "q@example.com"
And I click on ".availability-item .availability-eye img" "css_element"
And I click on "Save and return to course" "button"
# Log back in as student.
When I log out
And I log in as "student1"
And I am on "Course 1" course homepage
# I see P1 but not P2.
Then I should see "P1" in the "region-main" "region"
And I should not see "P2" in the "region-main" "region"
@javascript
Scenario: Test with custom user profile field
# Add custom field.
Given I log in as "admin"
And I navigate to "User profile fields" node in "Site administration > Users > Accounts"
And I set the field "datatype" to "Text input"
And I set the following fields to these values:
| Short name | superfield |
| Name | Super field |
And I click on "Save changes" "button"
# Set field value for user.
And I navigate to "Browse list of users" node in "Site administration > Users > Accounts"
And I click on ".icon[title=Edit]" "css_element" in the "s@example.com" "table_row"
And I expand all fieldsets
And I set the field "Super field" to "Bananaman"
And I click on "Update profile" "button"
# Set Page activity which has requirement on this field.
And I am on "Course 1" course homepage with editing mode on
And I add a "Page" to section "1"
And I set the following fields to these values:
| Name | P1 |
| Description | x |
| Page content | x |
And I expand all fieldsets
And I click on "Add restriction..." "button"
And I click on "User profile" "button"
And I set the following fields to these values:
| User profile field | Super field |
| Value to compare against | Bananaman |
And I click on ".availability-item .availability-eye img" "css_element"
And I click on "Save and return to course" "button"
# Edit it again and check the setting still works.
When I follow "P1"
And I navigate to "Edit settings" in current page administration
And I expand all fieldsets
Then the field "User profile field" matches value "Super field"
And the field "Value to compare against" matches value "Bananaman"
# Log out and back in as student. Should be able to see activity.
And I log out
And I log in as "student1"
And I am on "Course 1" course homepage
Then I should see "P1" in the "region-main" "region"