diff --git a/backup/moodle2/backup_qtype_aitext_plugin.class.php b/backup/moodle2/backup_qtype_aitext_plugin.class.php index 2c33cd1..827a3e1 100755 --- a/backup/moodle2/backup_qtype_aitext_plugin.class.php +++ b/backup/moodle2/backup_qtype_aitext_plugin.class.php @@ -57,7 +57,7 @@ protected function define_question_plugin_structure() { // Set source to populate the data. $aitext->set_source_table('qtype_aitext', - array('questionid' => backup::VAR_PARENTID)); + ['questionid' => backup::VAR_PARENTID]); // Don't need to annotate ids nor files. @@ -71,8 +71,8 @@ protected function define_question_plugin_structure() { * files to be processed both in backup and restore. */ public static function get_qtype_fileareas() { - return array( + return [ 'graderinfo' => 'question_created', - ); + ]; } } diff --git a/backup/moodle2/restore_qtype_aitext_plugin.class.php b/backup/moodle2/restore_qtype_aitext_plugin.class.php index 59ce5ac..7d2a319 100755 --- a/backup/moodle2/restore_qtype_aitext_plugin.class.php +++ b/backup/moodle2/restore_qtype_aitext_plugin.class.php @@ -91,9 +91,9 @@ public function process_aitext($data) { * Return the contents of this qtype to be processed by the links decoder */ public static function define_decode_contents() { - return array( + return [ new restore_decode_content('qtype_aitext', 'graderinfo', 'qtype_aitext'), - ); + ]; } /** @@ -112,7 +112,7 @@ protected function after_execute_question() { AND qeo.id IS NULL AND bi.backupid = ? AND bi.itemname = ? - ", array('aitext', $this->get_restoreid(), 'question_created')); + ", ['aitext', $this->get_restoreid(), 'question_created']); foreach ($aitextswithoutoptions as $q) { $defaultoptions = new stdClass(); diff --git a/classes/external.php b/classes/external.php index e1b110e..b551998 100644 --- a/classes/external.php +++ b/classes/external.php @@ -46,7 +46,7 @@ public static function fetch_ai_grade_parameters(): external_function_parameters ['response' => new external_value(PARAM_TEXT, 'The students response to question'), 'defaultmark' => new external_value(PARAM_INT, 'The total possible score'), 'prompt' => new external_value(PARAM_TEXT, 'The AI Prompt'), - 'marksscheme' => new external_value(PARAM_TEXT, 'The marks scheme') + 'marksscheme' => new external_value(PARAM_TEXT, 'The marks scheme'), ] ); diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index 7e059f9..b3998fe 100755 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -24,8 +24,8 @@ namespace qtype_aitext\privacy; -use \core_privacy\local\metadata\collection; -use \core_privacy\local\request\writer; +use core_privacy\local\metadata\collection; +use core_privacy\local\request\writer; /** * Privacy Subsystem for qtype_aitext implementing user_preference_provider. @@ -45,7 +45,7 @@ class provider implements * @param collection $collection The initialised collection to add items to. * @return collection A listing of user data stored through this system. */ - public static function get_metadata(collection $collection) : collection { + public static function get_metadata(collection $collection): collection { $collection->add_user_preference('qtype_aitext_defaultmark', 'privacy:preference:defaultmark'); $collection->add_user_preference('qtype_aitext_responseformat', 'privacy:preference:responseformat'); $collection->add_user_preference('qtype_aitext_responsefieldlines', 'privacy:preference:responsefieldlines'); diff --git a/db/caches.php b/db/caches.php index f94acb5..b61a8e8 100644 --- a/db/caches.php +++ b/db/caches.php @@ -30,5 +30,5 @@ $definitions = [ 'stringdata' => [ 'mode' => cache_store::MODE_SESSION, - ] + ], ]; diff --git a/db/services.php b/db/services.php index 80f9702..e3747bd 100644 --- a/db/services.php +++ b/db/services.php @@ -30,13 +30,13 @@ */ defined('MOODLE_INTERNAL') || die(); -$functions = array( - 'qtype_aitext_fetch_ai_grade' => array( +$functions = [ + 'qtype_aitext_fetch_ai_grade' => [ 'classname' => 'qtype_aitext_external', 'methodname' => 'fetch_ai_grade', 'description' => 'checks a response with the AI grader' , 'capabilities' => 'mod/quiz:grade', 'type' => 'read', 'ajax' => true, - ), -); + ], +]; diff --git a/db/tasks.php b/db/tasks.php index 77985f3..6cf1f4a 100644 --- a/db/tasks.php +++ b/db/tasks.php @@ -35,6 +35,6 @@ 'hour' => '*', 'day' => '*', 'dayofweek' => '*', - 'month' => '*' + 'month' => '*', ], ]; diff --git a/edit_aitext_form.php b/edit_aitext_form.php index 989776c..47fff2f 100755 --- a/edit_aitext_form.php +++ b/edit_aitext_form.php @@ -122,7 +122,7 @@ protected function definition_inner($mform) { $mform->addElement('header', 'graderinfoheader', get_string('graderinfoheader', 'qtype_aitext')); $mform->setExpanded('graderinfoheader'); $mform->addElement('editor', 'graderinfo', get_string('graderinfo', 'qtype_aitext'), - array('rows' => 10), $this->editoroptions); + ['rows' => 10], $this->editoroptions); // Load any JS that we need to make things happen, specifically the prompt tester. $PAGE->requires->js_call_amd('qtype_aitext/editformhelper', 'init', []); @@ -149,10 +149,10 @@ protected function data_preprocessing($question) { $question->maxwordlimit = $question->options->maxwordlimit; $question->aiprompt = $question->options->aiprompt; - $question->responsetemplate = array( + $question->responsetemplate = [ 'text' => $question->options->responsetemplate, 'format' => $question->options->responsetemplateformat, - ); + ]; return $question; } diff --git a/lang/en/qtype_aitext.php b/lang/en/qtype_aitext.php index 377d96a..3f4be9b 100755 --- a/lang/en/qtype_aitext.php +++ b/lang/en/qtype_aitext.php @@ -33,10 +33,8 @@ $string['cachedef_stringdata'] = 'Cachedef stringdata'; $string['defaultmarksscheme'] = 'Marks scheme'; $string['defaultmarksscheme_setting'] = 'This will be the default marks scheme for new questions. Questions authors should alter this to suit the question.'; -$string['thedefaultmarksscheme'] = 'Deduct a point from the total score for each grammar or spelling mistake.'; $string['defaultprompt'] = 'AI Prompt'; $string['defaultprompt_setting'] = 'This will be the default AI prompt for new questions. It tells the AI grader how to analyse the student response. It is the guideline that AI uses to give feedback on the student response. Question authors should alter this to suit the question.'; -$string['thedefaultprompt'] = 'Explain if there is anything wrong with the grammar and spelling in the text.'; $string['disclaimer'] = 'Disclaimer'; $string['disclaimer_setting'] = 'Text appended to each response indicating feedback is from a Large Language Model and not a human'; $string['err_maxminmismatch'] = 'Maximum word limit must be greater than minimum word limit'; @@ -49,9 +47,11 @@ $string['formatmonospaced'] = 'Plain text, monospaced font'; $string['formatnoinline'] = 'No online text'; $string['formatplain'] = 'Plain text'; -$string['graderinfo'] = 'Information for graders'; $string['get_llmmfeedback'] = 'Get LLM feedback'; +$string['graderinfo'] = 'Information for graders'; $string['graderinfoheader'] = 'Grader information'; +$string['jsonprompt'] = 'JSon prompt'; +$string['jsonprompt_setting'] = 'Instructions sent to convert the returned value into json'; $string['markscheme'] = 'Mark scheme'; $string['markscheme_help'] = 'This will tell the AI grader how to give a numerical grade to the student response. The total possible score is this question\'s \'Default mark\''; $string['maxwordlimit'] = 'Maximum word limit'; @@ -62,38 +62,38 @@ $string['minwordlimitboundary'] = 'This question requires a response of at least {$a->limit} words and you are attempting to submit {$a->count} words. Please expand your response and try again.'; $string['model'] = 'Model'; $string['nlines'] = '{$a} lines'; -$string['prompt'] = 'Prompt'; -$string['prompt_setting'] = 'Wrapper text for the prompt set to the AI System, [responsetext] is whatever the student typed as an answer. The ai prompt value from the question will be appended to this'; -$string['jsonprompt'] = 'JSon prompt'; -$string['jsonprompt_setting'] = 'Instructions sent to convert the returned value into json'; $string['pluginname'] = 'AI Text'; $string['pluginname_help'] = 'In response to a question, the respondent enters text. A response template may be provided. Responses are given a preliminary grade by an AI system (e.g. ChatGPT) then can be graded manually.'; $string['pluginname_link'] = 'question/type/AI Text'; $string['pluginnameadding'] = 'Adding an AI Text question'; $string['pluginnameediting'] = 'Editing an AI Text question'; $string['pluginnamesummary'] = 'Allows a response of a file upload and/or online text. The student response is processed by the configured AI/Large language model which returns feedback and optionally a grade..'; -$string['privacy:metadata'] = 'AI Text question type plugin allows question authors to set default options as user preferences.'; -$string['privacy:preference:defaultmark'] = 'The default mark set for a given question.'; -$string['privacy:preference:disclaimer'] = 'Text to indicate the feedback and/or marking is from a LLM'; -$string['privacy:preference:responseformat'] = 'What is the response format (HTML editor, plain text, etc.)?'; $string['privacy::responsefieldlines'] = 'Number of lines indicating the size of the input box (textarea).'; +$string['privacy:metadata'] = 'AI Text question type plugin allows question authors to set default options as user preferences.'; $string['privacy:preference:attachments'] = 'Number of allowed attachments.'; $string['privacy:preference:attachmentsrequired'] = 'Number of required attachments.'; +$string['privacy:preference:defaultmark'] = 'The default mark set for a given question.'; +$string['privacy:preference:disclaimer'] = 'Text to indicate the feedback and/or marking is from a LLM'; $string['privacy:preference:maxbytes'] = 'Maximum file size.'; +$string['privacy:preference:responseformat'] = 'What is the response format (HTML editor, plain text, etc.)?'; +$string['prompt'] = 'Prompt'; +$string['prompt_setting'] = 'Wrapper text for the prompt set to the AI System, [responsetext] is whatever the student typed as an answer. The ai prompt value from the question will be appended to this'; $string['prompttester'] = 'Prompt Tester'; $string['responsefieldlines'] = 'Input box size'; $string['responseformat'] = 'Response format'; -$string['responseoptions'] = 'Response options'; -$string['responsenotrequired'] = 'Text input is optional'; $string['responseisrequired'] = 'Require the student to enter text'; +$string['responsenotrequired'] = 'Text input is optional'; +$string['responseoptions'] = 'Response options'; $string['responsetemplate'] = 'Response template'; -$string['responsetemplateheader'] = 'Response template'; $string['responsetemplate_help'] = 'Any text entered here will be displayed in the response input box when a new attempt at the question starts.'; -$string['showprompt'] = 'Show prompt'; +$string['responsetemplateheader'] = 'Response template'; $string['sampleanswer'] = 'Sample Answer'; $string['sampleanswer_help'] = 'The sample answer can be used to test how the AI grader will respond to a given response.'; $string['sampleanswerempty'] = 'Make sure that you have an AI prompt and sample answer before testing.'; $string['sampleanswerevaluate'] = 'Evaluate Sample Answer'; +$string['showprompt'] = 'Show prompt'; +$string['thedefaultmarksscheme'] = 'Deduct a point from the total score for each grammar or spelling mistake.'; +$string['thedefaultprompt'] = 'Explain if there is anything wrong with the grammar and spelling in the text.'; $string['untestedquestionbehaviour'] = 'Untested question behaviour'; $string['wordcount'] = 'Word count: {$a}'; $string['wordcounttoofew'] = 'Word count: {$a->count}, less than the required {$a->limit} words.'; diff --git a/lib.php b/lib.php index dc3db87..3986c01 100755 --- a/lib.php +++ b/lib.php @@ -36,7 +36,7 @@ * @param array $options additional options affecting the file serving * @return bool */ -function qtype_aitext_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) { +function qtype_aitext_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=[]) { global $CFG; require_once($CFG->libdir . '/questionlib.php'); question_pluginfile($course, $context, 'qtype_aitext', $filearea, $args, $forcedownload, $options); diff --git a/question.php b/question.php index 0b88a0c..98b0c8a 100755 --- a/question.php +++ b/question.php @@ -147,7 +147,7 @@ public function apply_attempt_state(question_attempt_step $step) { * @param array $response * @return void */ - public function grade_response(array $response) : array { + public function grade_response(array $response): array { if (!$this->is_complete_response($response)) { $grade = [0 => 0, question_state::$needsgrading]; return $grade; @@ -224,7 +224,7 @@ public function process_feedback(string $feedback) { $contentobject = json_decode($feedback); if (json_last_error() === JSON_ERROR_NONE) { $contentobject->feedback = trim($contentobject->feedback); - $contentobject->feedback = preg_replace(array('/\[\[/', '/\]\]/'), '"', $contentobject->feedback); + $contentobject->feedback = preg_replace(['/\[\[/', '/\]\]/'], '"', $contentobject->feedback); $disclaimer = get_config('qtype_aitext', 'disclaimer'); $disclaimer = str_replace("[[model]]", $this->model, $disclaimer); $contentobject->feedback .= ' '.$this->llm_translate($disclaimer); @@ -244,7 +244,7 @@ public function process_feedback(string $feedback) { * @param string $text * @return string */ - protected function llm_translate(string $text) :string { + protected function llm_translate(string $text): string { if (current_language() == 'en') { return $text; } @@ -266,12 +266,12 @@ protected function llm_translate(string $text) :string { * @param string $value * @return void */ - protected function insert_attempt_step_data(string $name, string $value ) :void { + protected function insert_attempt_step_data(string $name, string $value ): void { global $DB; $data = [ 'attemptstepid' => $this->step->get_id(), 'name' => $name, - 'value' => $value + 'value' => $value, ]; $DB->insert_record('question_attempt_step_data', $data); } diff --git a/renderer.php b/renderer.php index a924d27..95537d0 100755 --- a/renderer.php +++ b/renderer.php @@ -57,7 +57,7 @@ public function formulation_and_controls(question_attempt $qa, if (!$step->has_qt_var('answer') && empty($options->readonly)) { // Question has never been answered, fill it with response template. - $step = new question_attempt_step(array('answer' => $question->responsetemplate)); + $step = new question_attempt_step(['answer' => $question->responsetemplate]); } if (empty($options->readonly)) { @@ -94,17 +94,17 @@ public function formulation_and_controls(question_attempt $qa, $result = ''; $result .= html_writer::tag('div', $question->format_questiontext($qa), - array('class' => 'qtext')); + ['class' => 'qtext']); - $result .= html_writer::start_tag('div', array('class' => 'ablock')); - $result .= html_writer::tag('div', $answer, array('class' => 'answer')); + $result .= html_writer::start_tag('div', ['class' => 'ablock']); + $result .= html_writer::tag('div', $answer, ['class' => 'answer']); // If there is a response and min/max word limit is set in the form then check the response word count. if ($qa->get_state() == question_state::$invalid) { $result .= html_writer::nonempty_tag('div', $question->get_validation_error($step->get_qt_data()), ['class' => 'validationerror']); } - $result .= html_writer::tag('div', $files, array('class' => 'attachments')); + $result .= html_writer::tag('div', $files, ['class' => 'attachments']); $result .= html_writer::end_tag('div'); return $result; @@ -152,7 +152,7 @@ public function files_read_only(question_attempt $qa, question_display_options $ foreach ($files as $file) { $out = html_writer::link($qa->get_response_file_url($file), $this->output->pix_icon(file_file_icon($file), get_mimetype_description($file), - 'moodle', array('class' => 'icon')) . ' ' . s($file->get_filename())); + 'moodle', ['class' => 'icon']) . ' ' . s($file->get_filename())); if (!empty($CFG->enableplagiarism)) { require_once($CFG->libdir . '/plagiarismlib.php'); @@ -373,16 +373,16 @@ public function response_area_input($name, $qa, $step, $lines, $context) { 'class' => 'sr-only', 'for' => $id, ]); - $output .= html_writer::start_tag('div', array('class' => - $this->class_name() . ' qtype_aitext_response')); + $output .= html_writer::start_tag('div', ['class' => + $this->class_name() . ' qtype_aitext_response']); $output .= html_writer::tag('div', html_writer::tag('textarea', s($response), - array('id' => $id, 'name' => $inputname, 'rows' => $lines, 'cols' => 60, 'class' => 'form-control'))); + ['id' => $id, 'name' => $inputname, 'rows' => $lines, 'cols' => 60, 'class' => 'form-control'])); $output .= html_writer::start_tag('div'); if (count($formats) == 1) { reset($formats); - $output .= html_writer::empty_tag('input', array('type' => 'hidden', - 'name' => $inputname . 'format', 'value' => key($formats))); + $output .= html_writer::empty_tag('input', ['type' => 'hidden', + 'name' => $inputname . 'format', 'value' => key($formats)]); } else { $output .= html_writer::label(get_string('format'), 'menu' . $inputname . 'format', false); @@ -438,7 +438,7 @@ protected function prepare_response_for_editing($name, */ protected function get_editor_options($context) { // Disable the text-editor autosave because quiz has it's own auto save function. - return array('context' => $context, 'autosave' => false); + return ['context' => $context, 'autosave' => false]; } /** @@ -451,7 +451,7 @@ protected function get_editor_options($context) { * @return array filepicker options for the editor. */ protected function get_filepicker_options($context, $draftitemid) { - return array('return_types' => FILE_INTERNAL | FILE_EXTERNAL); + return ['return_types' => FILE_INTERNAL | FILE_EXTERNAL]; } /** @@ -580,21 +580,21 @@ protected function get_filepicker_options($context, $draftitemid) { * @return string */ protected function filepicker_html($inputname, $draftitemid) { - $nonjspickerurl = new moodle_url('/repository/draftfiles_manager.php', array( + $nonjspickerurl = new moodle_url('/repository/draftfiles_manager.php', [ 'action' => 'browse', 'env' => 'editor', 'itemid' => $draftitemid, 'subdirs' => false, 'maxfiles' => -1, 'sesskey' => sesskey(), - )); + ]); - return html_writer::empty_tag('input', array('type' => 'hidden', - 'name' => $inputname . ':itemid', 'value' => $draftitemid)) . + return html_writer::empty_tag('input', ['type' => 'hidden', + 'name' => $inputname . ':itemid', 'value' => $draftitemid]) . html_writer::tag('noscript', html_writer::tag('div', - html_writer::tag('object', '', array('type' => 'text/html', + html_writer::tag('object', '', ['type' => 'text/html', 'data' => $nonjspickerurl, 'height' => 160, 'width' => 600, - 'style' => 'border: 1px solid #000;')))); + 'style' => 'border: 1px solid #000;']))); } } diff --git a/tests/helper.php b/tests/helper.php index a70ef05..8fd159d 100755 --- a/tests/helper.php +++ b/tests/helper.php @@ -36,7 +36,7 @@ class qtype_aitext_test_helper extends question_test_helper { * @return array */ public function get_test_questions() { - return array('editor', 'plain', 'monospaced', 'responsetemplate', 'noinline'); + return ['editor', 'plain', 'monospaced', 'responsetemplate', 'noinline']; } /** * Make an aitext question for testing @@ -99,15 +99,15 @@ public function get_aitext_question_form_data_editor() { $fromform = new stdClass(); $fromform->name = 'aitext question (HTML editor)'; - $fromform->questiontext = array('text' => 'Please write a story about a frog.', 'format' => FORMAT_HTML); + $fromform->questiontext = ['text' => 'Please write a story about a frog.', 'format' => FORMAT_HTML]; $fromform->defaultmark = 1.0; - $fromform->generalfeedback = array('text' => 'I hope your story had a beginning, a middle and an end.', - 'format' => FORMAT_HTML); + $fromform->generalfeedback = ['text' => 'I hope your story had a beginning, a middle and an end.', + 'format' => FORMAT_HTML]; $fromform->responseformat = 'editor'; $fromform->responsefieldlines = 10; $fromform->attachments = 0; - $fromform->graderinfo = array('text' => '', 'format' => FORMAT_HTML); - $fromform->responsetemplate = array('text' => '', 'format' => FORMAT_HTML); + $fromform->graderinfo = ['text' => '', 'format' => FORMAT_HTML]; + $fromform->responsetemplate = ['text' => '', 'format' => FORMAT_HTML]; $fromform->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY; $fromform->aiprompt = 'A prompt for the LLM'; $fromform->markscheme = 'Give one mark if the answer is correct'; @@ -137,17 +137,17 @@ public function get_aitext_question_form_data_plain() { $fromform = new stdClass(); $fromform->name = 'aitext question with filepicker and attachments'; - $fromform->questiontext = array('text' => 'Please write a story about a frog.', 'format' => FORMAT_HTML); + $fromform->questiontext = ['text' => 'Please write a story about a frog.', 'format' => FORMAT_HTML]; $fromform->defaultmark = 1.0; - $fromform->generalfeedback = array('text' => 'I hope your story had a beginning, a middle and an end.', - 'format' => FORMAT_HTML); + $fromform->generalfeedback = ['text' => 'I hope your story had a beginning, a middle and an end.', + 'format' => FORMAT_HTML]; $fromform->responseformat = 'plain'; $fromform->responsefieldlines = 10; $fromform->aiprompt = 'Evaluate this'; $fromform->markscheme = 'One mark if correct'; $fromform->maxbytes = 0; - $fromform->graderinfo = array('text' => '', 'format' => FORMAT_HTML); - $fromform->responsetemplate = array('text' => '', 'format' => FORMAT_HTML); + $fromform->graderinfo = ['text' => '', 'format' => FORMAT_HTML]; + $fromform->responsetemplate = ['text' => '', 'format' => FORMAT_HTML]; $fromform->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY; $fromform->sampleanswer = ''; $fromform->model = 'gpt-4'; diff --git a/tests/question_test.php b/tests/question_test.php index 36430bd..3423acb 100755 --- a/tests/question_test.php +++ b/tests/question_test.php @@ -39,7 +39,7 @@ * @author Marcus Green 2024 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class question_test extends \advanced_testcase { +final class question_test extends \advanced_testcase { /** @@ -51,7 +51,7 @@ class question_test extends \advanced_testcase { * @throws InvalidArgumentException * @throws ExpectationFailedException */ - public function test_get_question_summary() { + public function test_get_question_summary(): void { $aitext = qtype_aitext_test_helper::make_aitext_question([]); $aitext->questiontext = 'Hello world'; $this->assertEquals('Hello [world]', $aitext->get_question_summary()); @@ -64,13 +64,13 @@ public function test_get_question_summary() { * * @return void */ - public function test_get_feedback() { + public function test_get_feedback(): void { // Create the aitext question under test. $questiontext = 'AI question text'; $aitext = qtype_aitext_test_helper::make_aitext_question(['questiontext' => $questiontext, 'model' => 'llama3']); $testdata = [ "feedback" => "Feedback text", - "marks" => 0 + "marks" => 0, ]; $goodjson = json_encode($testdata); @@ -109,7 +109,7 @@ public function test_summarise_response(): void { * * @return void */ - public function test_is_same_response() { + public function test_is_same_response(): void { $aitext = qtype_aitext_test_helper::make_aitext_question([]); @@ -118,40 +118,40 @@ public function test_is_same_response() { $aitext->start_attempt(new question_attempt_step(), 1); $this->assertTrue($aitext->is_same_response( - array(), - array('answer' => ''))); + [], + ['answer' => ''])); $this->assertTrue($aitext->is_same_response( - array('answer' => ''), - array('answer' => ''))); + ['answer' => ''], + ['answer' => ''])); $this->assertTrue($aitext->is_same_response( - array('answer' => ''), - array())); + ['answer' => ''], + [])); $this->assertFalse($aitext->is_same_response( - array('answer' => 'Hello'), - array())); + ['answer' => 'Hello'], + [])); $this->assertFalse($aitext->is_same_response( - array('answer' => 'Hello'), - array('answer' => ''))); + ['answer' => 'Hello'], + ['answer' => ''])); $this->assertFalse($aitext->is_same_response( - array('answer' => 0), - array('answer' => ''))); + ['answer' => 0], + ['answer' => ''])); $this->assertFalse($aitext->is_same_response( - array('answer' => ''), - array('answer' => 0))); + ['answer' => ''], + ['answer' => 0])); $this->assertFalse($aitext->is_same_response( - array('answer' => '0'), - array('answer' => ''))); + ['answer' => '0'], + ['answer' => ''])); $this->assertFalse($aitext->is_same_response( - array('answer' => ''), - array('answer' => '0'))); + ['answer' => ''], + ['answer' => '0'])); } @@ -160,7 +160,7 @@ public function test_is_same_response() { * * @covers ::is_same_response_with_template() */ - public function test_is_same_response_with_template() { + public function test_is_same_response_with_template(): void { $aitext = qtype_aitext_test_helper::make_aitext_question([]); $aitext->responsetemplate = 'Once upon a time'; @@ -168,40 +168,40 @@ public function test_is_same_response_with_template() { $aitext->start_attempt(new question_attempt_step(), 1); $this->assertTrue($aitext->is_same_response( - array(), - array('answer' => 'Once upon a time'))); + [], + ['answer' => 'Once upon a time'])); $this->assertTrue($aitext->is_same_response( - array('answer' => ''), - array('answer' => 'Once upon a time'))); + ['answer' => ''], + ['answer' => 'Once upon a time'])); $this->assertTrue($aitext->is_same_response( - array('answer' => 'Once upon a time'), - array('answer' => ''))); + ['answer' => 'Once upon a time'], + ['answer' => ''])); $this->assertTrue($aitext->is_same_response( - array('answer' => ''), - array())); + ['answer' => ''], + [])); $this->assertTrue($aitext->is_same_response( - array('answer' => 'Once upon a time'), - array())); + ['answer' => 'Once upon a time'], + [])); $this->assertFalse($aitext->is_same_response( - array('answer' => 0), - array('answer' => ''))); + ['answer' => 0], + ['answer' => ''])); $this->assertFalse($aitext->is_same_response( - array('answer' => ''), - array('answer' => 0))); + ['answer' => ''], + ['answer' => 0])); $this->assertFalse($aitext->is_same_response( - array('answer' => '0'), - array('answer' => ''))); + ['answer' => '0'], + ['answer' => ''])); $this->assertFalse($aitext->is_same_response( - array('answer' => ''), - array('answer' => '0'))); + ['answer' => ''], + ['answer' => '0'])); } } diff --git a/tests/question_type_test.php b/tests/question_type_test.php index b769a34..d356dfe 100755 --- a/tests/question_type_test.php +++ b/tests/question_type_test.php @@ -30,10 +30,11 @@ * Unit tests for the aitext question type class. * * @package qtype_aitext + * @copyright 2013 The Open University * @author Marcus Green 2023 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class question_type_test extends \advanced_testcase { +final class question_type_test extends \advanced_testcase { /** * Always aitext * @@ -70,7 +71,7 @@ protected function get_test_question_data() { * @throws InvalidArgumentException * @throws ExpectationFailedException */ - public function test_name() { + public function test_name(): void { $this->assertEquals($this->qtype->name(), 'aitext'); } /** @@ -80,7 +81,7 @@ public function test_name() { * * @return void */ - public function test_can_analyse_responses() { + public function test_can_analyse_responses(): void { $this->assertFalse($this->qtype->can_analyse_responses()); } @@ -93,7 +94,7 @@ public function test_can_analyse_responses() { * * @return void */ - public function test_get_random_guess_score() { + public function test_get_random_guess_score(): void { $q = $this->get_test_question_data(); $this->assertEquals(0, $this->qtype->get_random_guess_score($q)); } @@ -104,9 +105,9 @@ public function test_get_random_guess_score() { * @return void * @covers ::get_possible_responses() */ - public function test_get_possible_responses() { + public function test_get_possible_responses(): void { $q = $this->get_test_question_data(); - $this->assertEquals(array(), $this->qtype->get_possible_responses($q)); + $this->assertEquals([], $this->qtype->get_possible_responses($q)); } } diff --git a/tests/restore_test.php b/tests/restore_test.php index ea5de1e..f8ee972 100755 --- a/tests/restore_test.php +++ b/tests/restore_test.php @@ -28,7 +28,7 @@ * @copyright 2019 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class restore_test extends \restore_date_testcase { +final class restore_test extends \restore_date_testcase { /** * Test missing qtype_aitext_options creation. @@ -39,7 +39,7 @@ class restore_test extends \restore_date_testcase { * During restore, we add default options for any questions like that. * That is what is tested in this file. */ - public function test_restore_create_missing_qtype_aitext_options() { + public function test_restore_create_missing_qtype_aitext_options(): void { global $DB; // Create a course with one essay question in its question bank. @@ -48,7 +48,7 @@ public function test_restore_create_missing_qtype_aitext_options() { $contexts = new \core_question\local\bank\question_edit_contexts(\context_course::instance($course->id)); $category = question_make_default_categories($contexts->all()); $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); - $aitext = $questiongenerator->create_question('aitext', null, array('category' => $category->id)); + $aitext = $questiongenerator->create_question('aitext', null, ['category' => $category->id]); // Remove the options record, which means that the backup will look like a backup made in an old Moodle. $DB->delete_records('qtype_aitext', ['questionid' => $aitext->id]);