1 @core @core_availability
2 Feature: edit_availability
3 In order to control which students can see activities
5 I need to set up availability options for activities and sections
7 # PURPOSE OF THIS TEST FEATURE:
9 # This test covers the user interface around editing availability conditions,
10 # especially the JavaScript code which is not tested elsewhere (e.g. does the
11 # 'Add restriction' dialog work). It tests both forms and also the admin
14 # This test does not check the detailed behaviour of the availability system,
15 # which is mainly covered in PHPUnit (and, from the user interface
16 # perspective, in the other Behat tests for each type of condition).
19 Given the following "courses" exist:
20 | fullname | shortname | format |
21 | Course 1 | C1 | topics |
22 And the following "users" exist:
26 And the following "course enrolments" exist:
27 | user | course | role |
28 | teacher1 | C1 | editingteacher |
29 | student1 | C1 | student |
30 And the following "activity" exists:
35 Scenario: Confirm the 'enable availability' option is working
36 Given the following config values are set as admin:
37 | enableavailability | 0 |
38 When I log in as "teacher1"
39 And the following "activity" exists:
46 And I am on "Course 1" course homepage with editing mode on
48 And I navigate to "Settings" in current page administration
49 Then "Restrict access" "fieldset" should not exist
51 Given I am on "Course 1" course homepage
52 When I edit the section "1"
53 Then "Restrict access" "fieldset" should not exist
55 And the following config values are set as admin:
56 | enableavailability | 1 |
58 And the following "activity" exists:
63 And I am on the "Page2" "page activity editing" page
64 Then "Restrict access" "fieldset" should exist
66 Given I am on "Course 1" course homepage
67 When I edit the section "1"
68 Then "Restrict access" "fieldset" should exist
71 Scenario: Edit availability using settings in activity form
73 Given the following "activity" exists:
78 And I am on the "P1" "page activity editing" page logged in as "teacher1"
79 And I expand all fieldsets
80 Then I should see "None" in the "Restrict access" "fieldset"
82 # Add a Date restriction and check it appears.
83 When I click on "Add restriction..." "button"
84 Then "Add restriction..." "dialogue" should be visible
85 When I click on "Date" "button" in the "Add restriction..." "dialogue"
86 Then "Add restriction..." "dialogue" should not exist
87 And I should not see "None" in the "Restrict access" "fieldset"
88 And "Restriction type" "select" should be visible
89 And I should see "Date" in the "Restrict access" "fieldset"
90 And ".availability-item .availability-eye img" "css_element" should be visible
91 And ".availability-item .availability-delete img" "css_element" should be visible
92 And the "alt" attribute of ".availability-item .availability-eye img" "css_element" should contain "Displayed if student"
94 # Toggle the eye icon.
95 When I click on ".availability-item .availability-eye img" "css_element"
96 Then the "alt" attribute of ".availability-item .availability-eye img" "css_element" should contain "Hidden entirely"
97 When I click on ".availability-item .availability-eye img" "css_element"
98 Then the "alt" attribute of ".availability-item .availability-eye img" "css_element" should contain "Displayed if student"
100 # Click the delete button.
101 When I click on ".availability-item .availability-delete img" "css_element"
102 Then I should not see "Date" in the "Restrict access" "fieldset"
104 # Add a nested restriction set and check it appears.
105 When I click on "Add restriction..." "button"
106 And I click on "Restriction set" "button" in the "Add restriction..." "dialogue"
107 Then ".availability-children .availability-list" "css_element" should be visible
108 And I should see "None" in the ".availability-children .availability-list" "css_element"
109 And I should see "Please set" in the ".availability-children .availability-list" "css_element"
110 And I should see "Add restriction" in the ".availability-children .availability-list" "css_element"
112 # Click on the button to add a restriction inside the nested set.
113 When I click on "Add restriction..." "button" in the ".availability-children .availability-list" "css_element"
114 And I click on "Date" "button" in the "Add restriction..." "dialogue"
115 Then I should not see "None" in the ".availability-children .availability-list" "css_element"
116 And I should not see "Please set" in the ".availability-children .availability-list" "css_element"
117 And I should see "Date" in the ".availability-children .availability-list" "css_element"
119 # OK, let's delete the date inside the nested set...
120 When I click on ".availability-item .availability-delete img" "css_element" in the ".availability-item" "css_element"
121 Then I should not see "Date" in the ".availability-children .availability-list" "css_element"
122 And I should see "None" in the ".availability-children .availability-list" "css_element"
124 # ...and the nested set itself.
125 When I click on ".availability-none .availability-delete img" "css_element"
126 Then ".availability-children .availability-list" "css_element" should not exist
128 # Add two dates so we can check the connectors.
129 When I click on "Add restriction..." "button"
130 And I click on "Date" "button" in the "Add restriction..." "dialogue"
131 And I click on "Add restriction..." "button"
132 And I click on "Date" "button" in the "Add restriction..." "dialogue"
133 Then I should see "and" in the "Restrict access" "fieldset"
134 And "Required restrictions" "select" should be visible
136 # Try changing the connector type.
137 When I set the field "Required restrictions" to "any"
138 Then I should not see "and" in the "Restrict access" "fieldset"
139 And I should see "or" in the "Restrict access" "fieldset"
141 # Now delete one of the dates and check the connector goes away.
142 When I click on ".availability-item .availability-delete img" "css_element"
143 Then I should not see "or" in the "Restrict access" "fieldset"
145 # Add a nested restriction set with two dates so there will be inner connector.
146 When I click on "Add restriction..." "button"
147 And I click on "Restriction set" "button" in the "Add restriction..." "dialogue"
148 And I click on "Add restriction..." "button" in the ".availability-children .availability-list" "css_element"
149 And I click on "Date" "button" in the "Add restriction..." "dialogue"
150 And I click on "Add restriction..." "button" in the ".availability-children .availability-list" "css_element"
151 And I click on "Date" "button" in the "Add restriction..." "dialogue"
152 Then I should see "and" in the ".availability-children .availability-list .availability-connector" "css_element"
154 # Check changing the outer one does not affect the inner one.
155 When I set the field "Required restrictions" to "all"
156 Then I should not see "or" in the "Restrict access" "fieldset"
157 When I set the field "Required restrictions" to "any"
158 Then I should see "or" in the "Restrict access" "fieldset"
159 And I should not see "or" in the ".availability-children .availability-list .availability-connector" "css_element"
162 Scenario: Edit availability using settings in section form
164 Given I log in as "teacher1"
165 And I am on "Course 1" course homepage with editing mode on
168 When I edit the section "1"
169 And I expand all fieldsets
170 Then I should see "None" in the "Restrict access" "fieldset"
172 # Add a Date restriction and check it appears.
173 When I click on "Add restriction..." "button"
174 When I click on "Date" "button" in the "Add restriction..." "dialogue"
175 And I should not see "None" in the "Restrict access" "fieldset"
176 And "Restriction type" "select" should be visible
177 And I should see "Date" in the "Restrict access" "fieldset"
180 Scenario: 'Add group/grouping access restriction' button unavailable
181 # Button does not exist when conditional access restrictions are turned off.
182 Given the following config values are set as admin:
183 | enableavailability | 0 |
184 And I am on the "MyForum" "forum activity editing" page logged in as admin
185 When I expand all fieldsets
186 Then "Add group/grouping access restriction" "button" should not exist
189 Scenario: Use the 'Add group/grouping access restriction' button
190 # Button should initially be disabled.
191 Given the following "groupings" exist:
192 | name | course | idnumber |
194 And I am on the "MyForum" "forum activity editing" page logged in as admin
195 When I expand all fieldsets
196 Then the "Add group/grouping access restriction" "button" should be disabled
198 # Turn on separate groups.
199 And I set the field "Group mode" to "Separate groups"
200 And the "Add group/grouping access restriction" "button" should be enabled
202 # Press the button and check it adds a restriction and disables itself.
203 And I should see "None" in the "Restrict access" "fieldset"
204 And I press "Add group/grouping access restriction"
205 And I should see "Group" in the "Restrict access" "fieldset"
206 And the "Add group/grouping access restriction" "button" should be disabled
208 # Delete the restriction and check it is enabled again.
209 And I click on "Delete" "link" in the "Restrict access" "fieldset"
210 And the "Add group/grouping access restriction" "button" should be enabled
212 # Try a grouping instead.
213 And I set the field "Grouping" to "GX1"
214 And I press "Add group/grouping access restriction"
215 And I should see "Grouping" in the "Restrict access" "fieldset"
217 # Check the button still works after saving and editing.
218 And I press "Save and display"
219 And I navigate to "Settings" in current page administration
220 And I expand all fieldsets
221 And the "Add group/grouping access restriction" "button" should be disabled
222 And I should see "Grouping" in the "Restrict access" "fieldset"
224 # And check it's still active if I delete the condition.
225 And I click on "Delete" "link" in the "Restrict access" "fieldset"
226 And the "Add group/grouping access restriction" "button" should be enabled
229 Scenario: Edit section availability using course page link
230 # Setting a restriction up
231 Given I log in as "teacher1"
232 And I am on "Course 1" course homepage with editing mode on
233 And I edit the section "1"
234 And I expand all fieldsets
235 And I press "Add restriction..."
236 And I click on "Date" "button" in the "Add restriction..." "dialogue"
237 And I press "Save changes"
238 # Testing edit restrictions link
239 And "Edit restrictions" "link" should exist in the "section-1" "core_availability > Section availability"
240 When I click on "Edit restrictions" "link" in the "section-1" "core_availability > Section availability"
241 Then I should see "Restrict access"
242 And I should not see "Summary of General"
243 And I should see "Collapse all"
244 And I should not see "Expand all"
245 And I click on "Cancel" "button"
246 And I am on "Course 1" course homepage with editing mode off
247 And I should not see "Edit restrictions"
250 Scenario: Edit activity availability using course page link
251 # Setting a restriction up
252 Given I am on the "MyForum" "forum activity editing" page logged in as teacher1
253 And I expand all fieldsets
254 And I press "Add restriction..."
255 And I click on "Date" "button" in the "Add restriction..." "dialogue"
256 When I press "Save and return to course"
257 # Edit restrictions link not displayed when editing mode is off.
258 Then "Edit restrictions" "link" should not exist in the "MyForum" "core_availability > Activity availability"
259 # Testing edit restrictions link
260 But I am on "Course 1" course homepage with editing mode on
261 And "Edit restrictions" "link" should exist in the "MyForum" "core_availability > Activity availability"
262 And I click on "Edit restrictions" "link" in the "MyForum" "core_availability > Activity availability"
263 And I should see "Restrict access"
264 And I should not see "Content"
265 And I should see "Collapse all"
266 And I should not see "Expand all"
269 Scenario: Edit activity availability button is shown after duplicating an activity
270 # Setting a restriction up
271 Given I am on the "MyForum" "forum activity editing" page logged in as teacher1
272 And I expand all fieldsets
273 And I press "Add restriction..."
274 And I click on "Date" "button" in the "Add restriction..." "dialogue"
275 When I press "Save and return to course"
276 And I turn editing mode on
277 And I duplicate "MyForum" activity
278 # Testing edit restrictions link
279 Then "Edit restrictions" "link" should exist in the "MyForum (copy)" "core_availability > Activity availability"