2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Unit tests for grade/report/lib.php.
20 * @package core_grades
22 * @copyright Andrew Nicols <andrew@nicols.co.uk>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
26 defined('MOODLE_INTERNAL') ||
die();
29 require_once($CFG->dirroot
.'/grade/lib.php');
30 require_once($CFG->dirroot
.'/grade/export/lib.php');
33 * A test class used to test grade_report, the abstract grade report parent class
35 class core_grade_export_test
extends advanced_testcase
{
38 * Ensure that feedback is correct formatted. Test the default implementation of format_feedback
40 * @dataProvider format_feedback_provider
41 * @param string $input The input string to test
42 * @param int $inputformat The format of the input string
43 * @param string $expected The expected result of the format.
45 public function test_format_feedback($input, $inputformat, $expected) {
46 $feedback = $this->getMockForAbstractClass(
55 $feedback->format_feedback((object) [
57 'feedbackformat' => $inputformat,
63 * Ensure that feedback is correctly formatted. Test augmented functionality to handle file links
65 public function test_format_feedback_with_grade() {
66 $this->resetAfterTest();
67 $dg = $this->getDataGenerator();
68 $c1 = $dg->create_course();
69 $u1 = $dg->create_user();
70 $gi1a = new grade_item($dg->create_grade_item(['courseid' => $c1->id
]), false);
71 $gi1a->update_final_grade($u1->id
, 1, 'test');
72 $contextid = $gi1a->get_context()->id
;
76 'Has server based image (HTML)' => [
77 '<p>See this reference: <img src="@@PLUGINFILE@@/test.img"></p>',
79 "See this reference: "
81 'Has server based image and more (HTML)' => [
82 '<p>See <img src="@@PLUGINFILE@@/test.img"> for <em>reference</em></p>',
86 'Has server based video and more (HTML)' => [
87 '<p>See <video src="@@PLUGINFILE@@/test.img">video of a duck</video> for <em>reference</em></p>',
89 'See video of a duck for reference'
91 'Has server based video with text and more (HTML)' => [
92 '<p>See <video src="@@PLUGINFILE@@/test.img">@@PLUGINFILE@@/test.img</video> for <em>reference</em></p>',
94 "See https://www.example.com/moodle/pluginfile.php/$contextid/grade/feedback/$gradeid/test.img for reference"
96 'Multiple videos (HTML)' => [
97 '<p>See <video src="@@PLUGINFILE@@/test.img">video of a duck</video> and '.
98 '<video src="http://example.com/myimage.jpg">video of a cat</video> for <em>reference</em></p>',
100 'See video of a duck and video of a cat for reference'
104 $feedback = $this->getMockForAbstractClass(
105 \grade_export
::class,
111 foreach ($tests as $key => $testdetails) {
112 $expected = $testdetails[2];
113 $input = $testdetails[0];
114 $inputformat = $testdetails[1];
118 $feedback->format_feedback((object) [
119 'feedback' => $input,
120 'feedbackformat' => $inputformat,
128 * Data provider for the format_feedback tests.
132 public function format_feedback_provider() : array {
134 'Basic string (PLAIN)' => [
135 'This is an example string',
137 'This is an example string',
139 'Basic string (HTML)' => [
140 '<p>This is an example string</p>',
142 'This is an example string',
144 'Has image (HTML)' => [
145 '<p>See this reference: <img src="http://example.com/myimage.jpg"></p>',
147 'See this reference: ',
149 'Has image and more (HTML)' => [
150 '<p>See <img src="http://example.com/myimage.jpg"> for <em>reference</em></p>',
154 'Has video and more (HTML)' => [
155 '<p>See <video src="http://example.com/myimage.jpg">video of a duck</video> for <em>reference</em></p>',
157 'See video of a duck for reference',
159 'Multiple videos (HTML)' => [
160 '<p>See <video src="http://example.com/myimage.jpg">video of a duck</video> and '.
161 '<video src="http://example.com/myimage.jpg">video of a cat</video> for <em>reference</em></p>',
163 'See video of a duck and video of a cat for reference'
165 'HTML Looking tags in PLAIN' => [
166 'The way you have written the <img thing looks pretty fun >',
168 'The way you have written the <img thing looks pretty fun >',