MDL-51108 mod_data: Addition to behat test for Lat. and Long.
[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"
23 And I follow "Course 1"
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"
34 And I set the field "newtype" to "Checkbox"
35 And I click on "Go" "button" in the ".fieldadd" "css_element"
36 And I set the following fields to these values:
37 | Field name | Required Two-Option Checkbox |
38 | Field description | Required Two-Option Checkbox |
39 | Required | yes |
40 And I set the field "Options" to multiline
41 """
42 RTOC Option 1
43 RTOC Option 2
44 """
45 And I press "Add"
b89cca19
DW
46 And I add a "Latlong" field to "Test database name" database and I fill the form with:
47 | Field name | Required Latlong |
48 | Field description | Required Latlong |
49 | Required | yes |
50 And I add a "Menu" field to "Test database name" database and I fill the form with:
51 | Field name | Required Menu |
52 | Field description | Required Menu |
53 | Required | yes |
54 | Options | Option 1 |
55 And I add a "Number" field to "Test database name" database and I fill the form with:
56 | Field name | Required Number |
57 | Field description | Required Number |
58 | Required | yes |
59 And I add a "Radio button" field to "Test database name" database and I fill the form with:
60 | Field name | Required Radio |
61 | Field description | Required Radio |
62 | Required | yes |
1c3b2058 63 | Options | Required Radio Option 1 |
b89cca19
DW
64 And I add a "Text input" field to "Test database name" database and I fill the form with:
65 | Field name | Required Text input |
66 | Field description | Required Text input |
67 | Required | yes |
68 And I add a "Text area" field to "Test database name" database and I fill the form with:
69 | Field name | Required Text area |
70 | Field description | Required Text area |
71 | Required | yes |
72 And I add a "URL" field to "Test database name" database and I fill the form with:
73 | Field name | Required URL |
74 | Field description | Required URL |
75 | Required | yes |
1c3b2058
JO
76 And I add a "Multimenu" field to "Test database name" database and I fill the form with:
77 | Field name | Required Multimenu |
78 | Field description | Required Multimenu |
79 | Required | yes |
80 | Options | Option 1 |
81 And I follow "Fields"
82 And I set the field "newtype" to "Multimenu"
83 And I click on "Go" "button" in the ".fieldadd" "css_element"
84 And I set the following fields to these values:
85 | Field name | Required Two-Option Multimenu |
86 | Field description | Required Two-Option Multimenu |
87 | Required | yes |
88 And I set the field "Options" to multiline
89 """
90 Option 1
91 Option 2
92 """
93 And I press "Add"
b89cca19
DW
94 And I add a "Checkbox" field to "Test database name" database and I fill the form with:
95 | Field name | Not required Checkbox |
96 | Field description | Not required Checkbox |
1c3b2058 97 | Options | Not required Checkbox Option 1 |
b89cca19
DW
98 And I add a "Latlong" field to "Test database name" database and I fill the form with:
99 | Field name | Not required Latlong |
100 | Field description | Not required Latlong |
101 And I add a "Menu" field to "Test database name" database and I fill the form with:
102 | Field name | Not required Menu |
103 | Field description | Not required Menu |
104 | Options | Option 1 |
105 And I add a "Number" field to "Test database name" database and I fill the form with:
106 | Field name | Not required Number |
107 | Field description | Not required Number |
108 And I add a "Radio button" field to "Test database name" database and I fill the form with:
109 | Field name | Not required Radio |
110 | Field description | Not required Radio |
1c3b2058 111 | Options | Not required Radio Option 1 |
b89cca19
DW
112 And I add a "Text input" field to "Test database name" database and I fill the form with:
113 | Field name | Not required Text input |
114 | Field description | Not required Text input |
115 And I add a "Text area" field to "Test database name" database and I fill the form with:
116 | Field name | Not required Text area |
117 | Field description | Not required Text area |
118 And I add a "URL" field to "Test database name" database and I fill the form with:
119 | Field name | Not required URL |
120 | Field description | Not required URL |
1c3b2058
JO
121 And I add a "Multimenu" field to "Test database name" database and I fill the form with:
122 | Field name | Not required Multimenu |
123 | Field description | Not required Multimenu |
124 | Options | Option 1 |
b89cca19
DW
125 And I follow "Templates"
126 And I log out
1c3b2058
JO
127
128 Scenario: Students receive errors for empty required fields but not for optional fields
b89cca19
DW
129 When I log in as "student1"
130 And I follow "Course 1"
131 And I add an entry to "Test database name" database with:
1c3b2058 132 | Base Text input | Some input to allow us to submit the otherwise empty form |
b89cca19
DW
133 And I press "Save and view"
134 Then ".alert.alert-error" "css_element" should exist in the "Required Checkbox" "table_row"
1c3b2058
JO
135 And ".alert.alert-error" "css_element" should exist in the "Required Two-Option Checkbox" "table_row"
136 And ".alert.alert-error" "css_element" should exist in the "Required Latlong" "table_row"
137 And ".alert.alert-error" "css_element" should exist in the "Required Menu" "table_row"
138 And ".alert.alert-error" "css_element" should exist in the "Required Number" "table_row"
139 And ".alert.alert-error" "css_element" should exist in the "Required Radio" "table_row"
140 And ".alert.alert-error" "css_element" should exist in the "Required Text input" "table_row"
141 And ".alert.alert-error" "css_element" should exist in the "Required Text area" "table_row"
142 And ".alert.alert-error" "css_element" should exist in the "Required URL" "table_row"
143 And ".alert.alert-error" "css_element" should exist in the "Required Multimenu" "table_row"
144 And ".alert.alert-error" "css_element" should exist in the "Required Two-Option Multimenu" "table_row"
145 And ".alert.alert-error" "css_element" should not exist in the "Not required Checkbox" "table_row"
146 And ".alert.alert-error" "css_element" should not exist in the "Not required Latlong" "table_row"
147 And ".alert.alert-error" "css_element" should not exist in the "Not required Menu" "table_row"
148 And ".alert.alert-error" "css_element" should not exist in the "Not required Number" "table_row"
149 And ".alert.alert-error" "css_element" should not exist in the "Not required Radio" "table_row"
150 And ".alert.alert-error" "css_element" should not exist in the "Not required Text input" "table_row"
151 And ".alert.alert-error" "css_element" should not exist in the "Not required Text area" "table_row"
152 And ".alert.alert-error" "css_element" should not exist in the "Not required URL" "table_row"
153 And ".alert.alert-error" "css_element" should not exist in the "Not required Multimenu" "table_row"
b89cca19
DW
154 And I follow "View list"
155 And I should see "No entries in database"
1c3b2058
JO
156
157 Scenario: Students recieve no error for filled in required fields
158 When I log in as "student1"
159 And I follow "Course 1"
160 And I add an entry to "Test database name" database with:
161 | Base Text input | Some input to allow us to submit the otherwise empty form |
162 | Required Checkbox Option 1 | 1 |
163 | RTOC Option 1 | 1 |
164 | Latitude | 0 |
165 | Longitude | 0 |
166 | Required Menu | 1 |
167 | Required Number | 1 |
168 | Required Radio Option 1 | 1 |
169 | Required Text input | New entry text |
170 | Required Text area | More text |
171 | Required URL | http://example.com/ |
172 | Required Multimenu | 1 |
173 | Required Two-Option Multimenu | 1 |
174 And I press "Save and view"
175 And I follow "View list"
176 Then I should not see "No entries in database"
177 And I should see "New entry text"
178
179 Scenario: Fields refill with data after having an error
180 When I log in as "student1"
181 And I follow "Course 1"
182 And I add an entry to "Test database name" database with:
183 | RTOC Option 1 | 1 |
184 | Latitude | 0 |
185 | Longitude | 0 |
186 | Required Menu | 1 |
187 | Required Number | 1 |
188 | Required Radio Option 1 | 1 |
189 | Required Text input | New entry text |
190 | Required Text area | More text |
191 | Required URL | http://example.com/ |
192 | Required Multimenu | 1 |
193 | Required Two-Option Multimenu | 1 |
194 And I press "Save and view"
195 Then the following fields match these values:
196 | Base Text input | |
197 | Latitude | 0 |
198 | Longitude | 0 |
199 | Required Menu | Option 1 |
200 | Required Number | 1 |
201 | Required Radio Option 1 | 1 |
202 | Required Text input | New entry text |
203 | Required Text area | More text |
204 | Required URL | http://example.com/ |
205 | Required Multimenu | Option 1 |
206 | Required Two-Option Multimenu | Option 1 |
453adb1a
AG
207
208 Scenario: A student fills in Latitude but not Longitude will see an error
209 Given I log in as "student1"
210 And I follow "Course 1"
211 When I add an entry to "Test database name" database with:
212 | Base Text input | Some input to allow us to submit the otherwise empty form |
213 | Required Checkbox Option 1 | 1 |
214 | RTOC Option 1 | 1 |
215 | Latitude | 24 |
216 | Required Menu | 1 |
217 | Required Number | 1 |
218 | Required Radio Option 1 | 1 |
219 | Required Text input | New entry text |
220 | Required Text area | More text |
221 | Required URL | http://example.com/ |
222 | Required Multimenu | 1 |
223 | Required Two-Option Multimenu | 1 |
224 And I set the field with xpath "//div[@title='Not required Latlong']//tr[td/label[normalize-space(.)='Latitude']]/td/input" to "20"
225 And I press "Save and view"
226 Then ".alert.alert-error" "css_element" should exist in the "Required Latlong" "table_row"
227 And ".alert.alert-error" "css_element" should exist in the "Not required Latlong" "table_row"