Skip to content

Commit

Permalink
MDL-70916 Essay/Moodle XML: min and max word limits not imported
Browse files Browse the repository at this point in the history
  • Loading branch information
timhunt committed Feb 17, 2021
1 parent 41037ef commit 1d552ec
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
2 changes: 2 additions & 0 deletions question/format/xml/format.php
Expand Up @@ -772,8 +772,10 @@ public function import_essay($question) {
array('#', 'responserequired', 0, '#'), 1);
$qo->minwordlimit = $this->getpath($question,
array('#', 'minwordlimit', 0, '#'), null);
$qo->minwordenabled = !empty($qo->minwordlimit);
$qo->maxwordlimit = $this->getpath($question,
array('#', 'maxwordlimit', 0, '#'), null);
$qo->maxwordenabled = !empty($qo->maxwordlimit);
$qo->attachments = $this->getpath($question,
array('#', 'attachments', 0, '#'), 0);
$qo->attachmentsrequired = $this->getpath($question,
Expand Down
6 changes: 6 additions & 0 deletions question/format/xml/tests/xmlformat_test.php
Expand Up @@ -407,7 +407,9 @@ public function test_import_essay_20() {
$expectedq->responserequired = 1;
$expectedq->responsefieldlines = 15;
$expectedq->minwordlimit = null;
$expectedq->minwordenabled = false;
$expectedq->maxwordlimit = null;
$expectedq->maxwordenabled = false;
$expectedq->attachments = 0;
$expectedq->attachmentsrequired = 0;
$expectedq->maxbytes = 0;
Expand Down Expand Up @@ -470,7 +472,9 @@ public function test_import_essay_21() {
$expectedq->responserequired = 0;
$expectedq->responsefieldlines = 42;
$expectedq->minwordlimit = null;
$expectedq->minwordenabled = false;
$expectedq->maxwordlimit = null;
$expectedq->maxwordenabled = false;
$expectedq->attachments = -1;
$expectedq->attachmentsrequired = 1;
$expectedq->maxbytes = 0;
Expand Down Expand Up @@ -537,7 +541,9 @@ public function test_import_essay_311() {
$expectedq->responserequired = 0;
$expectedq->responsefieldlines = 42;
$expectedq->minwordlimit = 10;
$expectedq->minwordenabled = true;
$expectedq->maxwordlimit = 20;
$expectedq->maxwordenabled = true;
$expectedq->attachments = -1;
$expectedq->attachmentsrequired = 1;
$expectedq->maxbytes = 52428800; // 50MB.
Expand Down
26 changes: 25 additions & 1 deletion question/type/essay/tests/behat/edit_min_max_fields.feature
Expand Up @@ -18,7 +18,7 @@ I need to choose the appropriate minimum and/or maximum number of words for inpu
| Course | C1 | Test questions |
And the following "questions" exist:
| questioncategory | qtype | name | template | minwordlimit | maxwordlimit |
| Test questions | essay | essay-min-max | editor | null | null |
| Test questions | essay | essay-min-max | editor | 0 | 0 |
Given I log in as "teacher1"
And I am on "Course 1" course homepage
And I navigate to "Question bank" in current page administration
Expand Down Expand Up @@ -56,3 +56,27 @@ I need to choose the appropriate minimum and/or maximum number of words for inpu
When I set the field "Require text" to "Text input is optional"
Then I should not see "Minimum word limit"
And I should not see "Minimum word limit"

@javascript
Scenario: Minimum/Maximum word limit can be unset after being set.
Given I choose "Edit question" action for "essay-min-max" in the question bank
When I set the following fields to these values:
| minwordenabled | 1 |
| id_minwordlimit | 100 |
| maxwordenabled | 1 |
| id_maxwordlimit | 200 |
And I click on "Save changes and continue editing" "button"
Then the following fields match these values:
| minwordenabled | 1 |
| id_minwordlimit | 100 |
| maxwordenabled | 1 |
| id_maxwordlimit | 200 |
And I set the following fields to these values:
| minwordenabled | 0 |
| maxwordenabled | 0 |
And I click on "Save changes and continue editing" "button"
And the following fields match these values:
| minwordenabled | 0 |
| id_minwordlimit | |
| maxwordenabled | 0 |
| id_maxwordlimit | |
2 changes: 2 additions & 0 deletions question/type/essay/tests/behat/import.feature
Expand Up @@ -28,3 +28,5 @@ Feature: Test importing Essay questions
And I should see "Write an essay with 500 words."
And I press "Continue"
And I should see "essay-001"
And I choose "Edit question" action for "essay-001" in the question bank
And the field "id_maxwordlimit" matches value "20"
2 changes: 1 addition & 1 deletion question/type/essay/tests/fixtures/testquestion.moodle.xml
Expand Up @@ -26,7 +26,7 @@
<responserequired>1</responserequired>
<responsefieldlines>15</responsefieldlines>
<minwordlimit></minwordlimit>
<maxwordlimit></maxwordlimit>
<maxwordlimit>20</maxwordlimit>
<attachments>0</attachments>
<attachmentsrequired>0</attachmentsrequired>
<maxbytes>0</maxbytes>
Expand Down

0 comments on commit 1d552ec

Please sign in to comment.