From 1d552eca6c540cde028321ce958b38bbde2f730a Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Tue, 16 Feb 2021 14:35:00 +0000 Subject: [PATCH] MDL-70916 Essay/Moodle XML: min and max word limits not imported --- question/format/xml/format.php | 2 ++ question/format/xml/tests/xmlformat_test.php | 6 +++++ .../tests/behat/edit_min_max_fields.feature | 26 ++++++++++++++++++- .../type/essay/tests/behat/import.feature | 2 ++ .../tests/fixtures/testquestion.moodle.xml | 2 +- 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/question/format/xml/format.php b/question/format/xml/format.php index cb6b56cc0ac..e32d1ace76a 100644 --- a/question/format/xml/format.php +++ b/question/format/xml/format.php @@ -772,8 +772,10 @@ class qformat_xml extends qformat_default { 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, diff --git a/question/format/xml/tests/xmlformat_test.php b/question/format/xml/tests/xmlformat_test.php index 740db03d52b..3de9b313c28 100644 --- a/question/format/xml/tests/xmlformat_test.php +++ b/question/format/xml/tests/xmlformat_test.php @@ -407,7 +407,9 @@ END; $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; @@ -470,7 +472,9 @@ END; $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; @@ -537,7 +541,9 @@ END; $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. diff --git a/question/type/essay/tests/behat/edit_min_max_fields.feature b/question/type/essay/tests/behat/edit_min_max_fields.feature index 44105c59a41..e73f93743a8 100644 --- a/question/type/essay/tests/behat/edit_min_max_fields.feature +++ b/question/type/essay/tests/behat/edit_min_max_fields.feature @@ -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 @@ -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 | | diff --git a/question/type/essay/tests/behat/import.feature b/question/type/essay/tests/behat/import.feature index 195b78cb244..e365569e370 100644 --- a/question/type/essay/tests/behat/import.feature +++ b/question/type/essay/tests/behat/import.feature @@ -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" diff --git a/question/type/essay/tests/fixtures/testquestion.moodle.xml b/question/type/essay/tests/fixtures/testquestion.moodle.xml index a6fb84bcbea..811a687759b 100644 --- a/question/type/essay/tests/fixtures/testquestion.moodle.xml +++ b/question/type/essay/tests/fixtures/testquestion.moodle.xml @@ -26,7 +26,7 @@ 1 15 - + 20 0 0 0