on-demand release 4.0dev+
[moodle.git] / mod / data / tests / behat / required_entries.feature
CommitLineData
b89cca19
DW
1@mod @mod_data
2Feature: Users can be required to specify certain fields when adding entries to database activities
1c3b2058
JO
3 In order to constrain user input
4 As a teacher
5 I need to specify certain fields as required when I add entries to databases
b89cca19 6
1c3b2058 7 Background:
b89cca19
DW
8 Given the following "users" exist:
9 | username | firstname | lastname | email |
0fe86bbd
RT
10 | student1 | Student | 1 | student1@example.com |
11 | teacher1 | Teacher | 1 | teacher1@example.com |
b89cca19
DW
12 And the following "courses" exist:
13 | fullname | shortname | category |
14 | Course 1 | C1 | 0 |
15 And the following "course enrolments" exist:
16 | user | course | role |
17 | teacher1 | C1 | editingteacher |
18 | student1 | C1 | student |
19 And the following "activities" exist:
20 | activity | name | intro | course | idnumber |
21 | data | Test database name | n | C1 | data1 |
22 And I log in as "teacher1"
fdeeaff9 23 And I am on "Course 1" course homepage
b89cca19
DW
24 And I add a "Text input" field to "Test database name" database and I fill the form with:
25 | Field name | Base Text input |
1c3b2058 26 | Required | yes |
b89cca19
DW
27 | Field description | Base Text input |
28 And I add a "Checkbox" field to "Test database name" database and I fill the form with:
29 | Field name | Required Checkbox |
30 | Field description | Required Checkbox |
31 | Required | yes |
1c3b2058
JO
32 | Options | Required Checkbox Option 1 |
33 And I follow "Fields"
e01012e9 34 And I select "Checkbox" from the "newtype" singleselect
1c3b2058
JO
35 And I set the following fields to these values:
36 | Field name | Required Two-Option Checkbox |
37 | Field description | Required Two-Option Checkbox |
38 | Required | yes |
e259795c 39 And I set the field "Options" to multiline:
1c3b2058
JO
40 """
41 RTOC Option 1
42 RTOC Option 2
43 """
44 And I press "Add"
b89cca19
DW
45 And I add a "Latlong" field to "Test database name" database and I fill the form with:
46 | Field name | Required Latlong |
47 | Field description | Required Latlong |
48 | Required | yes |
49 And I add a "Menu" field to "Test database name" database and I fill the form with:
50 | Field name | Required Menu |
51 | Field description | Required Menu |
52 | Required | yes |
53 | Options | Option 1 |
54 And I add a "Number" field to "Test database name" database and I fill the form with:
55 | Field name | Required Number |
56 | Field description | Required Number |
57 | Required | yes |
58 And I add a "Radio button" field to "Test database name" database and I fill the form with:
59 | Field name | Required Radio |
60 | Field description | Required Radio |
61 | Required | yes |
1c3b2058 62 | Options | Required Radio Option 1 |
b89cca19
DW
63 And I add a "Text input" field to "Test database name" database and I fill the form with:
64 | Field name | Required Text input |
65 | Field description | Required Text input |
66 | Required | yes |
67 And I add a "Text area" field to "Test database name" database and I fill the form with:
68 | Field name | Required Text area |
69 | Field description | Required Text area |
70 | Required | yes |
71 And I add a "URL" field to "Test database name" database and I fill the form with:
72 | Field name | Required URL |
73 | Field description | Required URL |
74 | Required | yes |
1c3b2058
JO
75 And I add a "Multimenu" field to "Test database name" database and I fill the form with:
76 | Field name | Required Multimenu |
77 | Field description | Required Multimenu |
78 | Required | yes |
79 | Options | Option 1 |
80 And I follow "Fields"
e01012e9 81 And I select "Multimenu" from the "newtype" singleselect
1c3b2058
JO
82 And I set the following fields to these values:
83 | Field name | Required Two-Option Multimenu |
84 | Field description | Required Two-Option Multimenu |
85 | Required | yes |
e259795c 86 And I set the field "Options" to multiline:
1c3b2058
JO
87 """
88 Option 1
89 Option 2
90 """
91 And I press "Add"
b89cca19
DW
92 And I add a "Checkbox" field to "Test database name" database and I fill the form with:
93 | Field name | Not required Checkbox |
94 | Field description | Not required Checkbox |
1c3b2058 95 | Options | Not required Checkbox Option 1 |
b89cca19
DW
96 And I add a "Latlong" field to "Test database name" database and I fill the form with:
97 | Field name | Not required Latlong |
98 | Field description | Not required Latlong |
99 And I add a "Menu" field to "Test database name" database and I fill the form with:
100 | Field name | Not required Menu |
101 | Field description | Not required Menu |
102 | Options | Option 1 |
103 And I add a "Number" field to "Test database name" database and I fill the form with:
104 | Field name | Not required Number |
105 | Field description | Not required Number |
106 And I add a "Radio button" field to "Test database name" database and I fill the form with:
107 | Field name | Not required Radio |
108 | Field description | Not required Radio |
1c3b2058 109 | Options | Not required Radio Option 1 |
b89cca19
DW
110 And I add a "Text input" field to "Test database name" database and I fill the form with:
111 | Field name | Not required Text input |
112 | Field description | Not required Text input |
113 And I add a "Text area" field to "Test database name" database and I fill the form with:
114 | Field name | Not required Text area |
115 | Field description | Not required Text area |
116 And I add a "URL" field to "Test database name" database and I fill the form with:
117 | Field name | Not required URL |
118 | Field description | Not required URL |
1c3b2058
JO
119 And I add a "Multimenu" field to "Test database name" database and I fill the form with:
120 | Field name | Not required Multimenu |
121 | Field description | Not required Multimenu |
122 | Options | Option 1 |
6c0e1eee 123 And I navigate to "Templates" in current page administration
b89cca19 124 And I log out
1c3b2058
JO
125
126 Scenario: Students receive errors for empty required fields but not for optional fields
b89cca19 127 When I log in as "student1"
fdeeaff9 128 And I am on "Course 1" course homepage
b89cca19 129 And I add an entry to "Test database name" database with:
1c3b2058 130 | Base Text input | Some input to allow us to submit the otherwise empty form |
6c0e1eee 131 And I press "Save"
63e4df60
DW
132 Then ".alert" "css_element" should exist in the "Required Checkbox" "table_row"
133 And ".alert" "css_element" should exist in the "Required Two-Option Checkbox" "table_row"
134 And ".alert" "css_element" should exist in the "Required Latlong" "table_row"
135 And ".alert" "css_element" should exist in the "Required Menu" "table_row"
136 And ".alert" "css_element" should exist in the "Required Number" "table_row"
137 And ".alert" "css_element" should exist in the "Required Radio" "table_row"
138 And ".alert" "css_element" should exist in the "Required Text input" "table_row"
139 And ".alert" "css_element" should exist in the "Required Text area" "table_row"
140 And ".alert" "css_element" should exist in the "Required URL" "table_row"
141 And ".alert" "css_element" should exist in the "Required Multimenu" "table_row"
142 And ".alert" "css_element" should exist in the "Required Two-Option Multimenu" "table_row"
143 And ".alert" "css_element" should not exist in the "Not required Checkbox" "table_row"
144 And ".alert" "css_element" should not exist in the "Not required Latlong" "table_row"
145 And ".alert" "css_element" should not exist in the "Not required Menu" "table_row"
146 And ".alert" "css_element" should not exist in the "Not required Number" "table_row"
147 And ".alert" "css_element" should not exist in the "Not required Radio" "table_row"
148 And ".alert" "css_element" should not exist in the "Not required Text input" "table_row"
149 And ".alert" "css_element" should not exist in the "Not required Text area" "table_row"
150 And ".alert" "css_element" should not exist in the "Not required URL" "table_row"
151 And ".alert" "css_element" should not exist in the "Not required Multimenu" "table_row"
6c0e1eee
MG
152 And I am on "Course 1" course homepage
153 And I follow "Test database name"
b89cca19 154 And I should see "No entries in database"
1c3b2058
JO
155
156 Scenario: Students recieve no error for filled in required fields
157 When I log in as "student1"
fdeeaff9 158 And I am on "Course 1" course homepage
1c3b2058
JO
159 And I add an entry to "Test database name" database with:
160 | Base Text input | Some input to allow us to submit the otherwise empty form |
161 | Required Checkbox Option 1 | 1 |
162 | RTOC Option 1 | 1 |
163 | Latitude | 0 |
164 | Longitude | 0 |
165 | Required Menu | 1 |
166 | Required Number | 1 |
167 | Required Radio Option 1 | 1 |
168 | Required Text input | New entry text |
169 | Required Text area | More text |
170 | Required URL | http://example.com/ |
171 | Required Multimenu | 1 |
172 | Required Two-Option Multimenu | 1 |
6c0e1eee
MG
173 And I press "Save"
174 And I select "List view" from the "jump" singleselect
1c3b2058
JO
175 Then I should not see "No entries in database"
176 And I should see "New entry text"
177
178 Scenario: Fields refill with data after having an error
179 When I log in as "student1"
fdeeaff9 180 And I am on "Course 1" course homepage
1c3b2058
JO
181 And I add an entry to "Test database name" database with:
182 | RTOC Option 1 | 1 |
183 | Latitude | 0 |
184 | Longitude | 0 |
185 | Required Menu | 1 |
186 | Required Number | 1 |
187 | Required Radio Option 1 | 1 |
188 | Required Text input | New entry text |
189 | Required Text area | More text |
190 | Required URL | http://example.com/ |
191 | Required Multimenu | 1 |
192 | Required Two-Option Multimenu | 1 |
6c0e1eee 193 And I press "Save"
1c3b2058
JO
194 Then the following fields match these values:
195 | Base Text input | |
196 | Latitude | 0 |
197 | Longitude | 0 |
198 | Required Menu | Option 1 |
199 | Required Number | 1 |
200 | Required Radio Option 1 | 1 |
201 | Required Text input | New entry text |
202 | Required Text area | More text |
203 | Required URL | http://example.com/ |
204 | Required Multimenu | Option 1 |
205 | Required Two-Option Multimenu | Option 1 |
453adb1a
AG
206
207 Scenario: A student fills in Latitude but not Longitude will see an error
208 Given I log in as "student1"
fdeeaff9 209 And I am on "Course 1" course homepage
453adb1a
AG
210 When I add an entry to "Test database name" database with:
211 | Base Text input | Some input to allow us to submit the otherwise empty form |
212 | Required Checkbox Option 1 | 1 |
213 | RTOC Option 1 | 1 |
214 | Latitude | 24 |
215 | Required Menu | 1 |
216 | Required Number | 1 |
217 | Required Radio Option 1 | 1 |
218 | Required Text input | New entry text |
219 | Required Text area | More text |
220 | Required URL | http://example.com/ |
221 | Required Multimenu | 1 |
222 | Required Two-Option Multimenu | 1 |
223 And I set the field with xpath "//div[@title='Not required Latlong']//tr[td/label[normalize-space(.)='Latitude']]/td/input" to "20"
6c0e1eee 224 And I press "Save"
63e4df60
DW
225 Then ".alert" "css_element" should exist in the "Required Latlong" "table_row"
226 And ".alert" "css_element" should exist in the "Not required Latlong" "table_row"
3829d1e2 227
57bee542
RT
228 Scenario: A student filling in number and text fields with zero will not see an error.
229 Given I log in as "student1"
fdeeaff9 230 And I am on "Course 1" course homepage
57bee542
RT
231 When I add an entry to "Test database name" database with:
232 | Base Text input | Some input to allow us to submit the otherwise empty form |
233 | Required Checkbox Option 1 | 1 |
234 | RTOC Option 1 | 1 |
235 | Latitude | 0 |
236 | Longitude | 0 |
237 | Required Menu | 1 |
238 | Required Number | 0 |
239 | Required Radio Option 1 | 1 |
240 | Required Text input | 0 |
241 | Required Text area | 0 |
242 | Required URL | http://example.com/ |
243 | Required Multimenu | 1 |
244 | Required Two-Option Multimenu | 1 |
6c0e1eee
MG
245 And I press "Save"
246 And I select "List view" from the "jump" singleselect
57bee542
RT
247 Then I should not see "No entries in database"
248 And I should see "Some input to allow us to submit the otherwise empty form"