/**
* Returns formatted grade feedback
* @param object $feedback object with properties feedback and feedbackformat
+ * @param object $grade Grade object with grade properties
* @return string
*/
- public function format_feedback($feedback) {
- return strip_tags(format_text($feedback->feedback, $feedback->feedbackformat));
+ public function format_feedback($feedback, $grade = null) {
+ $string = $feedback->feedback;
+ if (!empty($grade)) {
+ // Rewrite links to get the export working for 36, refer MDL-63488.
+ $string = file_rewrite_pluginfile_urls(
+ $feedback->feedback,
+ 'pluginfile.php',
+ $grade->get_context()->id,
+ GRADE_FILE_COMPONENT,
+ GRADE_FEEDBACK_FILEAREA,
+ $grade->id
+ );
+ }
+
+ return strip_tags(format_text($string, $feedback->feedbackformat));
}
/**
class core_grade_export_test extends advanced_testcase {
/**
- * Ensure that feedback is correct formatted.
+ * Ensure that feedback is correct formatted. Test the default implementation of format_feedback
*
* @dataProvider format_feedback_provider
* @param string $input The input string to test
);
}
+ /**
+ * Ensure that feedback is correctly formatted. Test augmented functionality to handle file links
+ */
+ public function test_format_feedback_with_grade() {
+ $this->resetAfterTest();
+ $dg = $this->getDataGenerator();
+ $c1 = $dg->create_course();
+ $u1 = $dg->create_user();
+ $gi1a = new grade_item($dg->create_grade_item(['courseid' => $c1->id]), false);
+ $gi1a->update_final_grade($u1->id, 1, 'test');
+ $contextid = $gi1a->get_context()->id;
+ $gradeid = $gi1a->id;
+
+ $tests = [
+ 'Has server based image (HTML)' => [
+ '<p>See this reference: <img src="@@PLUGINFILE@@/test.img"></p>',
+ FORMAT_HTML,
+ "See this reference: "
+ ],
+ 'Has server based image and more (HTML)' => [
+ '<p>See <img src="@@PLUGINFILE@@/test.img"> for <em>reference</em></p>',
+ FORMAT_HTML,
+ "See for reference"
+ ],
+ 'Has server based video and more (HTML)' => [
+ '<p>See <video src="@@PLUGINFILE@@/test.img">video of a duck</video> for <em>reference</em></p>',
+ FORMAT_HTML,
+ 'See video of a duck for reference'
+ ],
+ 'Has server based video with text and more (HTML)' => [
+ '<p>See <video src="@@PLUGINFILE@@/test.img">@@PLUGINFILE@@/test.img</video> for <em>reference</em></p>',
+ FORMAT_HTML,
+ "See https://www.example.com/moodle/pluginfile.php/$contextid/grade/feedback/$gradeid/test.img for reference"
+ ],
+ 'Multiple videos (HTML)' => [
+ '<p>See <video src="@@PLUGINFILE@@/test.img">video of a duck</video> and '.
+ '<video src="http://example.com/myimage.jpg">video of a cat</video> for <em>reference</em></p>',
+ FORMAT_HTML,
+ 'See video of a duck and video of a cat for reference'
+ ],
+ ];
+
+ $feedback = $this->getMockForAbstractClass(
+ \grade_export::class,
+ [],
+ '',
+ false
+ );
+
+ foreach ($tests as $key => $testdetails) {
+ $expected = $testdetails[2];
+ $input = $testdetails[0];
+ $inputformat = $testdetails[1];
+
+ $this->assertEquals(
+ $expected,
+ $feedback->format_feedback((object) [
+ 'feedback' => $input,
+ 'feedbackformat' => $inputformat,
+ ], $gi1a),
+ $key
+ );
+ }
+ }
+
/**
* Data provider for the format_feedback tests.
*
'Has image (HTML)' => [
'<p>See this reference: <img src="http://example.com/myimage.jpg"></p>',
FORMAT_HTML,
- 'See this reference: ',
+ 'See this reference: ',
],
'Has image and more (HTML)' => [
'<p>See <img src="http://example.com/myimage.jpg"> for <em>reference</em></p>',
FORMAT_HTML,
- 'See for reference',
+ 'See for reference',
],
'Has video and more (HTML)' => [
'<p>See <video src="http://example.com/myimage.jpg">video of a duck</video> for <em>reference</em></p>',
'See video of a duck for reference',
],
'Multiple videos (HTML)' => [
- '<p>See <video src="http://example.com/myimage.jpg">video of a duck</video> and <video src="http://example.com/myimage.jpg">video of a cat</video> for <em>reference</em></p>',
+ '<p>See <video src="http://example.com/myimage.jpg">video of a duck</video> and '.
+ '<video src="http://example.com/myimage.jpg">video of a cat</video> for <em>reference</em></p>',
FORMAT_HTML,
- 'See video of a duck and video of a cat for reference',
+ 'See video of a duck and video of a cat for reference'
],
'HTML Looking tags in PLAIN' => [
'The way you have written the <img thing looks pretty fun >',
FORMAT_PLAIN,
- 'The way you have written the <img thing looks pretty fun >',
+ 'The way you have written the <img thing looks pretty fun >',
],
+
];
}
}