Skip to content

Commit 3ddb448

Browse files
committed
Fix the import xml behat test
1 parent f7bf28d commit 3ddb448

File tree

4 files changed

+64
-26
lines changed

4 files changed

+64
-26
lines changed

edit_aitext_form.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
* @copyright 2023 Marcus Green
2323
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2424
*/
25-
use moodle_url;
26-
/**
27-
* aitext question type editing form.
28-
*
29-
* @author 2023 Marcus Green
30-
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31-
*/
25+
26+
/**
27+
* aitext question type editing form.
28+
*
29+
* @author 2023 Marcus Green
30+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31+
*/
3232
class qtype_aitext_edit_form extends question_edit_form {
3333
/**
3434
* Add aitext specific form fields for editing
@@ -85,7 +85,7 @@ protected function definition_inner($mform) {
8585

8686
// Add repeated sample answer options along with the field for returned responses.
8787
$mform->addElement('header', 'responsetest', get_string('responsetester', 'qtype_aitext'));
88-
$mform->addHelpButton('responsetester', 'responsetesthelp', 'qtype_aitext');
88+
$mform->addHelpButton('responsetest', 'responsetesthelp', 'qtype_aitext');
8989

9090
$answeroptions = ['maxlen' => 50, 'rows' => 6, 'size' => 30];
9191
$evaloptions = ['cols' => 50, 'rows' => 5, 'disabled' => 'disabled' ];

questiontype.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ public function save_question_options($formdata) {
132132

133133
$options->maxbytes = $formdata->maxbytes ?? 0;
134134
if (is_array($formdata->graderinfo)) {
135-
// TODO find out what it should save and ensure it is available as text not arrays.
136135
$formdata->graderinfo = [
137136
'text' => '',
138137
'format' => FORMAT_HTML,
@@ -258,7 +257,7 @@ public function response_sizes() {
258257

259258
/**
260259
* The choices that should be offered for the number of attachments.
261-
* @todo remove method and calls to it as file is no longer a submit option
260+
* Note: remove method and calls to it as file is no longer a submit option
262261
*
263262
* @return array
264263
*/
@@ -274,7 +273,7 @@ public function attachment_options() {
274273

275274
/**
276275
* The choices that should be offered for the number of required attachments.
277-
* @todo remove as file has been removed as a submission type
276+
* Note: remove as file has been removed as a submission type
278277
*
279278
* @return array
280279
*/
@@ -336,7 +335,7 @@ public function import_from_xml($data, $question, qformat_xml $format, $extra=nu
336335
foreach ($extraquestionfields as $field) {
337336
$qo->$field = $format->getpath($data, ['#', $field, 0, '#'], '');
338337
}
339-
// TODO add in other text fields.
338+
// Note: add in other text fields.
340339
$textfields = ['responsetemplate'];
341340
foreach ($textfields as $field) {
342341
$fmt = $format->get_format($format->getpath($data, ['#', $field.'format', 0, '#'], 0));
@@ -356,7 +355,7 @@ public function import_from_xml($data, $question, qformat_xml $format, $extra=nu
356355
if (isset($data['#']['sampleresponse'])) {
357356
$sampleresponses = $data['#']['sampleresponse'];
358357
foreach ($sampleresponses as $key => $srxml) {
359-
$qo->sampleresponses[$key] = $format->getpath($srxml, ['#','response',0,'#'],0);
358+
$qo->sampleresponses[$key] = $format->getpath($srxml, ['#', 'response', 0, '#'], 0);
360359
}
361360
}
362361
return $qo;
@@ -395,14 +394,12 @@ public function export_to_xml($question, qformat_xml $format, $extra = null) {
395394
$output .= " <$field>".$format->xml_escape($value)."</$field>\n";
396395
}
397396
}
398-
//$output .= " <sampleresponses>\n";
399397
foreach ($question->options->sampleresponses as $sampleresponse) {
400398
$output .= " <sampleresponse>\n";
401399
$output .= ' <question>' . $sampleresponse->question . "</question>\n";
402400
$output .= ' <response>' . $sampleresponse->response . "</response>\n";
403401
$output .= " </sampleresponse>\n";
404402
}
405-
//$output .= " </sampleresponses>\n";
406403
return $output;
407404
}
408405
/**

tests/behat/import.feature

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,24 @@ Feature: Test importing aitext questions
66

77
Background:
88
Given the following "users" exist:
9-
| username |
10-
| teacher |
9+
| username |
10+
| teacher |
1111
And the following "courses" exist:
12-
| fullname | shortname | category |
13-
| Course 1 | C1 | 0 |
12+
| fullname | shortname | category |
13+
| Course 1 | C1 | 0 |
1414
And the following "course enrolments" exist:
15-
| user | course | role |
16-
| teacher | C1 | editingteacher |
15+
| user | course | role |
16+
| teacher | C1 | editingteacher |
1717

1818
@javascript @_file_upload
1919
Scenario: import aitext question.
2020
When I am on the "Course 1" "core_question > course question import" page logged in as teacher
2121
And I set the field "id_format_xml" to "1"
22-
And I upload "question/type/aitext/tests/fixtures/testquestion.moodle.xml" file to "Import" filemanager
22+
And I upload "question/type/aitext/tests/fixtures/aitext_past_tense.xml" file to "Import" filemanager
2323
And I press "id_submitbutton"
2424
Then I should see "Parsing questions from import file."
2525
And I should see "Importing 1 questions from file"
26-
And I should see "Write an aitext with 500 words."
26+
And I should see "Write a sentence in the past tense"
2727
And I press "Continue"
28-
And I should see "aitext-001"
29-
And I choose "Edit question" action for "aitext-001" in the question bank
30-
And the field "id_maxwordlimit" matches value "20"
28+
And I should see "English past tense"
29+
And I choose "Edit question" action for "English past tense" in the question bank
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<quiz>
3+
<!-- question: 14966 -->
4+
<question type="aitext">
5+
<name>
6+
<text>English past tense</text>
7+
</name>
8+
<questiontext format="html">
9+
<text><![CDATA[<p>Write a sentence in the past tense</p>]]></text>
10+
</questiontext>
11+
<generalfeedback format="html">
12+
<text></text>
13+
</generalfeedback>
14+
<defaultgrade>1</defaultgrade>
15+
<penalty>0</penalty>
16+
<hidden>0</hidden>
17+
<idnumber></idnumber>
18+
<responseformat>plain</responseformat>
19+
<responsefieldlines>10</responsefieldlines>
20+
<minwordlimit></minwordlimit>
21+
<maxwordlimit></maxwordlimit>
22+
<graderinfo format="html">
23+
<text></text>
24+
</graderinfo>
25+
<responsetemplate format="html">
26+
<text></text>
27+
</responsetemplate>
28+
<aiprompt>Explain if there is anything wrong with the grammar and spelling in the text.</aiprompt>
29+
<markscheme>Deduct a point from the total score for each grammar or spelling mistake.</markscheme>
30+
<model>gpt-4o</model>
31+
<spellcheck>0</spellcheck>
32+
<sampleresponse>
33+
<question>14966</question>
34+
<response>response1</response>
35+
</sampleresponse>
36+
<sampleresponse>
37+
<question>14966</question>
38+
<response>response2</response>
39+
</sampleresponse>
40+
</question>
41+
42+
</quiz>

0 commit comments

Comments
 (0)