| 1 | efrain | 1 | @availability @availability_grouping
 | 
        
           |  |  | 2 | Feature: availability_grouping
 | 
        
           |  |  | 3 |   In order to control student access to activities
 | 
        
           |  |  | 4 |   As a teacher
 | 
        
           |  |  | 5 |   I need to set grouping conditions which prevent student access
 | 
        
           |  |  | 6 |   | 
        
           |  |  | 7 |   Background:
 | 
        
           |  |  | 8 |     Given the following "courses" exist:
 | 
        
           |  |  | 9 |       | fullname | shortname | format | enablecompletion |
 | 
        
           |  |  | 10 |       | Course 1 | C1        | topics | 1                |
 | 
        
           |  |  | 11 |     And the following "users" exist:
 | 
        
           |  |  | 12 |       | username |
 | 
        
           |  |  | 13 |       | teacher1 |
 | 
        
           |  |  | 14 |       | student1 |
 | 
        
           |  |  | 15 |     And the following "course enrolments" exist:
 | 
        
           |  |  | 16 |       | user     | course | role           |
 | 
        
           |  |  | 17 |       | teacher1 | C1     | editingteacher |
 | 
        
           |  |  | 18 |       | student1 | C1     | student        |
 | 
        
           |  |  | 19 |     And the following "groups" exist:
 | 
        
           |  |  | 20 |       | name | course | idnumber |
 | 
        
           |  |  | 21 |       | G1   | C1     | GI1      |
 | 
        
           |  |  | 22 |     And the following "group members" exist:
 | 
        
           |  |  | 23 |       | user     | group |
 | 
        
           |  |  | 24 |       | student1 | GI1   |
 | 
        
           |  |  | 25 |     # Basic setup.
 | 
        
           |  |  | 26 |     And the following "activities" exist:
 | 
        
           |  |  | 27 |       | activity | course | name  |
 | 
        
           |  |  | 28 |       | page     | C1     | P1    |
 | 
        
           |  |  | 29 |       | page     | C1     | P2    |
 | 
        
           |  |  | 30 |   | 
        
           |  |  | 31 |   @javascript
 | 
        
           |  |  | 32 |   Scenario: Test condition
 | 
        
           |  |  | 33 |     # Start to add a Page. If there aren't any groupings, there's no Grouping option.
 | 
        
           |  |  | 34 |     Given I am on the "P1" "page activity editing" page logged in as "teacher1"
 | 
        
           |  |  | 35 |     And I expand all fieldsets
 | 
        
           |  |  | 36 |     And I click on "Add restriction..." "button"
 | 
        
           |  |  | 37 |     Then "Grouping" "button" should not exist in the "Add restriction..." "dialogue"
 | 
        
           |  |  | 38 |     And I click on "Cancel" "button" in the "Add restriction..." "dialogue"
 | 
        
           |  |  | 39 |   | 
        
           |  |  | 40 |     # Back to course page but add groups.
 | 
        
           |  |  | 41 |     # This step used to be 'And I follow "C1"', but Chrome thinks the breadcrumb
 | 
        
           |  |  | 42 |     # is not clickable, so we'll go via the home page instead.
 | 
        
           |  |  | 43 |     And I am on "Course 1" course homepage
 | 
        
           |  |  | 44 |     And the following "groupings" exist:
 | 
        
           |  |  | 45 |       | name | course | idnumber |
 | 
        
           |  |  | 46 |       | GX1  | C1     | GXI1     |
 | 
        
           |  |  | 47 |       | GX2  | C1     | GXI2     |
 | 
        
           |  |  | 48 |     And I am on the "P1" "page activity editing" page
 | 
        
           |  |  | 49 |     And I expand all fieldsets
 | 
        
           |  |  | 50 |     And I click on "Add restriction..." "button"
 | 
        
           |  |  | 51 |     Then "Grouping" "button" should exist in the "Add restriction..." "dialogue"
 | 
        
           |  |  | 52 |   | 
        
           |  |  | 53 |     # Page P1 grouping GX1.
 | 
        
           |  |  | 54 |     Given I click on "Grouping" "button"
 | 
        
           |  |  | 55 |     And I set the field "Grouping" to "GX1"
 | 
        
           |  |  | 56 |     And I click on ".availability-item .availability-eye img" "css_element"
 | 
        
           |  |  | 57 |     And I click on "Save and return to course" "button"
 | 
        
           |  |  | 58 |   | 
        
           |  |  | 59 |     # Page P2 with grouping GX2.
 | 
        
           |  |  | 60 |     And I am on the "P2" "page activity editing" page
 | 
        
           |  |  | 61 |     And I expand all fieldsets
 | 
        
           |  |  | 62 |     And I click on "Add restriction..." "button"
 | 
        
           |  |  | 63 |     And I click on "Grouping" "button"
 | 
        
           |  |  | 64 |     And I set the field "Grouping" to "GX2"
 | 
        
           |  |  | 65 |     And I click on ".availability-item .availability-eye img" "css_element"
 | 
        
           |  |  | 66 |     And I click on "Save and return to course" "button"
 | 
        
           |  |  | 67 |   | 
        
           |  |  | 68 |     # Log back in as student.
 | 
        
           |  |  | 69 |     When I am on the "Course 1" "course" page logged in as "student1"
 | 
        
           |  |  | 70 |   | 
        
           |  |  | 71 |     # No pages should appear yet.
 | 
        
           |  |  | 72 |     Then I should not see "P1" in the "region-main" "region"
 | 
        
           |  |  | 73 |     And I should not see "P2" in the "region-main" "region"
 | 
        
           |  |  | 74 |   | 
        
           |  |  | 75 |     # Add group to grouping and log out/in again.
 | 
        
           |  |  | 76 |     And the following "grouping groups" exist:
 | 
        
           |  |  | 77 |       | grouping | group  |
 | 
        
           |  |  | 78 |       | GXI1     | GI1    |
 | 
        
           |  |  | 79 |     And I am on the "Course 1" "course" page logged in as "student1"
 | 
        
           |  |  | 80 |   | 
        
           |  |  | 81 |     # P1 should show but not B2.
 | 
        
           |  |  | 82 |     Then I should see "P1" in the "region-main" "region"
 | 
        
           |  |  | 83 |     And I should not see "P2" in the "region-main" "region"
 | 
        
           |  |  | 84 |   | 
        
           |  |  | 85 |   @javascript
 | 
        
           |  |  | 86 |   Scenario: Check grouping access restriction message on course homepage
 | 
        
           |  |  | 87 |     Given the following "groupings" exist:
 | 
        
           |  |  | 88 |       | name        | course | idnumber |
 | 
        
           |  |  | 89 |       | Grouping A  | C1     | GA      |
 | 
        
           |  |  | 90 |     And the following "grouping groups" exist:
 | 
        
           |  |  | 91 |       | grouping  | group |
 | 
        
           |  |  | 92 |       | GA        | GI1   |
 | 
        
           |  |  | 93 |     And the following "activities" exist:
 | 
        
           |  |  | 94 |       | activity  | name        | intro              | course | idnumber | groupmode | grouping |
 | 
        
           |  |  | 95 |       | assign    | Test assign | Assign description | C1     | assign1  | 1         | GA       |
 | 
        
           |  |  | 96 |     And I log in as "teacher1"
 | 
        
           |  |  | 97 |     And I am on "Course 1" course homepage
 | 
        
           |  |  | 98 |     And I turn editing mode on
 | 
        
           |  |  | 99 |     And I open "Test assign" actions menu
 | 
        
           |  |  | 100 |     And I choose "Edit settings" in the open action menu
 | 
        
           |  |  | 101 |     And I expand all fieldsets
 | 
        
           |  |  | 102 |     And the field "groupingid" matches value "Grouping A"
 | 
        
           |  |  | 103 |     And I press "Add group/grouping access restriction"
 | 
        
           |  |  | 104 |     When I press "Save and return to course"
 | 
        
           |  |  | 105 |     Then I should see "Not available unless: You belong to a group in Grouping A"
 | 
        
           |  |  | 106 |   | 
        
           |  |  | 107 |   @javascript
 | 
        
           |  |  | 108 |   Scenario: Condition display with filters
 | 
        
           |  |  | 109 |     # Teacher sets up a restriction on group G1, using multilang filter.
 | 
        
           |  |  | 110 |     Given the following "groupings" exist:
 | 
        
           |  |  | 111 |       | name                                                                                          | course | idnumber |
 | 
        
           |  |  | 112 |       | <span lang="en" class="multilang">Gr-One</span><span lang="fr" class="multilang">Gr-Un</span> | C1     | GA       |
 | 
        
           |  |  | 113 |     And the following "activities" exist:
 | 
        
           |  |  | 114 |       | activity  | name        | intro              | course | idnumber | groupmode | grouping |
 | 
        
           |  |  | 115 |       | assign    | Test assign | Assign description | C1     | assign1  | 1         | GA       |
 | 
        
           |  |  | 116 |     And the "multilang" filter is "on"
 | 
        
           |  |  | 117 |     And the "multilang" filter applies to "content and headings"
 | 
        
           |  |  | 118 |     # The activity names filter is enabled because it triggered a bug in older versions.
 | 
        
           |  |  | 119 |     And the "activitynames" filter is "on"
 | 
        
           |  |  | 120 |     And the "activitynames" filter applies to "content and headings"
 | 
        
           |  |  | 121 |     And I am on the "Test assign" "assign activity editing" page logged in as "teacher1"
 | 
        
           |  |  | 122 |     And I expand all fieldsets
 | 
        
           |  |  | 123 |     And I press "Add group/grouping access restriction"
 | 
        
           |  |  | 124 |     And I press "Save and return to course"
 | 
        
           |  |  | 125 |   | 
        
           |  |  | 126 |     # Student sees information about no access to group, with group name in correct language.
 | 
        
           |  |  | 127 |     When I am on the "C1" "Course" page logged in as "student1"
 | 
        
           |  |  | 128 |     Then I should see "Not available unless: You belong to a group in Gr-One"
 | 
        
           |  |  | 129 |     And I should not see "Gr-Un"
 |