From 4d31a0e7b2f68e785ee4635bf9a6529d9ded6cbc Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Wed, 6 Nov 2024 08:25:36 +0000 Subject: [PATCH] MDL-83645 grade: fix text formatting in external grading form method. --- lib/classes/grading_external.php | 15 ++++++++------- lib/tests/grading_external_test.php | 10 +++++++--- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/classes/grading_external.php b/lib/classes/grading_external.php index a5512baa3ea6e..b374e996c7f1f 100644 --- a/lib/classes/grading_external.php +++ b/lib/classes/grading_external.php @@ -364,6 +364,7 @@ public static function get_gradingform_instances($definitionid, $since = 0) { 'warningcode' => '1' ); } + foreach ($activeinstances as $activeinstance) { $instance = array(); $instance['id'] = $activeinstance->get_id(); @@ -371,17 +372,17 @@ public static function get_gradingform_instances($definitionid, $since = 0) { $instance['itemid'] = $activeinstance->get_data('itemid'); $instance['rawgrade'] = $activeinstance->get_data('rawgrade'); $instance['status'] = $activeinstance->get_data('status'); - $instance['feedback'] = $activeinstance->get_data('feedback'); - $instance['feedbackformat'] = $activeinstance->get_data('feedbackformat'); + // Format the feedback text field. - $formattedtext = \core_external\util::format_text($activeinstance->get_data('feedback'), + [$instance['feedback'], $instance['feedbackformat']] = \core_external\util::format_text( + $activeinstance->get_data('feedback'), $activeinstance->get_data('feedbackformat'), - $context->id, + $context, $area->component, 'feedback', - $params['definitionid']); - $instance['feedback'] = $formattedtext[0]; - $instance['feedbackformat'] = $formattedtext[1]; + $params['definitionid'], + ); + $instance['timemodified'] = $activeinstance->get_data('timemodified'); if ($details != null && $getfilling != null) { diff --git a/lib/tests/grading_external_test.php b/lib/tests/grading_external_test.php index be4ee2b267583..c9cd60f1fc684 100644 --- a/lib/tests/grading_external_test.php +++ b/lib/tests/grading_external_test.php @@ -274,7 +274,8 @@ public function test_get_gradingform_instances(): void { 'raterid' => $USER->id, 'itemid' => $gid, 'status' => 1, - 'feedbackformat' => 0, + 'feedback' => 'Fabulous', + 'feedbackformat' => FORMAT_HTML, 'timemodified' => 1 ); $instanceid = $DB->insert_record('grading_instances', $instance); @@ -297,9 +298,12 @@ public function test_get_gradingform_instances(): void { $this->assertEquals($USER->id, $result['instances'][0]['raterid']); $this->assertEquals($gid, $result['instances'][0]['itemid']); $this->assertEquals(1, $result['instances'][0]['status']); + $this->assertEquals('Fabulous', $result['instances'][0]['feedback']); + $this->assertEquals(FORMAT_HTML, $result['instances'][0]['feedbackformat']); $this->assertEquals(1, $result['instances'][0]['timemodified']); - $this->assertEquals(1, count($result['instances'][0]['rubric'])); - $this->assertEquals(1, count($result['instances'][0]['rubric']['criteria'])); + $this->assertCount(1, $result['instances'][0]['rubric']); + $this->assertCount(1, $result['instances'][0]['rubric']['criteria']); + $criteria = $result['instances'][0]['rubric']['criteria']; $this->assertEquals($criterionid, $criteria[0]['criterionid']); $this->assertEquals($levelid, $criteria[0]['levelid']);