Skip to content

Commit eeb94aa

Browse files
author
Mike Churchward
committed
CONTRIB-8165 Allowing zero as an answer for text and essay.
1 parent f0c6393 commit eeb94aa

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

classes/responsetype/text.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static public function response_table() {
5151
*/
5252
static public function answers_from_webform($responsedata, $question) {
5353
$answers = [];
54-
if (isset($responsedata->{'q'.$question->id}) && !empty($responsedata->{'q'.$question->id})) {
54+
if (isset($responsedata->{'q'.$question->id}) && (strlen($responsedata->{'q'.$question->id}) > 0)) {
5555
$val = $responsedata->{'q' . $question->id};
5656
$record = new \stdClass();
5757
$record->responseid = $responsedata->rid;

tests/behat/numeric_question_zero.feature

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ Feature: Numeric questions can have zero as a valid response
2424
| Question Name | Q1 |
2525
| Yes | y |
2626
| Question Text | Enter a number |
27-
Then I should see "position 1"
28-
And I should see "[Numeric] (Q1)"
29-
And I should see "Enter a number"
30-
And I log out
27+
Then I log out
3128

3229
@javascript
3330
Scenario: Student must enter no more than six digits and decimal points.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
@mod @mod_questionnaire
2+
Feature: Text questions can have zero as a valid response
3+
4+
Background: Add a text question to a questionnaire and accept zero
5+
Given the following "users" exist:
6+
| username | firstname | lastname | email |
7+
| teacher1 | Teacher | 1 | teacher1@example.com |
8+
| student1 | Student | 1 | student1@example.com |
9+
And the following "courses" exist:
10+
| fullname | shortname | category |
11+
| Course 1 | C1 | 0 |
12+
And the following "course enrolments" exist:
13+
| user | course | role |
14+
| teacher1 | C1 | editingteacher |
15+
| student1 | C1 | student |
16+
And the following "activities" exist:
17+
| activity | name | description | course | idnumber |
18+
| questionnaire | Test questionnaire | Test questionnaire description | C1 | questionnaire0 |
19+
And I log in as "teacher1"
20+
And I am on "Course 1" course homepage
21+
And I follow "Test questionnaire"
22+
And I navigate to "Questions" in current page administration
23+
And I add a "Text Box" question and I fill the form with:
24+
| Question Name | Q1 |
25+
| Yes | y |
26+
| Question Text | Enter zero |
27+
Then I log out
28+
29+
@javascript
30+
Scenario: Student must enter no more than six digits and decimal points.
31+
And I log in as "student1"
32+
And I am on "Course 1" course homepage
33+
And I follow "Test questionnaire"
34+
And I navigate to "Answer the questions..." in current page administration
35+
Then I should see "Enter zero"
36+
And I set the field "Enter zero" to "0"
37+
And I press "Submit questionnaire"
38+
Then I should see "Thank you for completing this Questionnaire."
39+
And I press "Continue"
40+
Then I should see "Your response"
41+
And I should see "Test questionnaire"
42+
And I should see "Enter zero"
43+
And "//div[contains(@class,'questionnaire_text') and contains(@class,'questionnaire_response')]//span[@class='selected' and text()='0']" "xpath_element" should exist

0 commit comments

Comments
 (0)