1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
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.
|
|
|
8 |
//
|
|
|
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.
|
|
|
13 |
//
|
|
|
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/>.
|
|
|
16 |
|
|
|
17 |
namespace core_grades;
|
|
|
18 |
|
|
|
19 |
defined('MOODLE_INTERNAL') || die();
|
|
|
20 |
|
|
|
21 |
global $CFG;
|
|
|
22 |
require_once($CFG->dirroot.'/grade/lib.php');
|
|
|
23 |
require_once($CFG->dirroot.'/grade/export/lib.php');
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* A test class used to test grade_report, the abstract grade report parent class
|
|
|
27 |
*
|
|
|
28 |
* @package core_grades
|
|
|
29 |
* @category test
|
|
|
30 |
* @copyright Andrew Nicols <andrew@nicols.co.uk>
|
|
|
31 |
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
|
|
32 |
*/
|
|
|
33 |
class export_test extends \advanced_testcase {
|
|
|
34 |
|
|
|
35 |
/**
|
|
|
36 |
* Ensure that feedback is correct formatted. Test the default implementation of format_feedback
|
|
|
37 |
*
|
|
|
38 |
* @dataProvider format_feedback_provider
|
|
|
39 |
* @param string $input The input string to test
|
|
|
40 |
* @param int $inputformat The format of the input string
|
|
|
41 |
* @param string $expected The expected result of the format.
|
|
|
42 |
*/
|
11 |
efrain |
43 |
public function test_format_feedback($input, $inputformat, $expected): void {
|
1 |
efrain |
44 |
$feedback = $this->getMockForAbstractClass(
|
|
|
45 |
\grade_export::class,
|
|
|
46 |
[],
|
|
|
47 |
'',
|
|
|
48 |
false
|
|
|
49 |
);
|
|
|
50 |
|
|
|
51 |
$this->assertEquals(
|
|
|
52 |
$expected,
|
|
|
53 |
$feedback->format_feedback((object) [
|
|
|
54 |
'feedback' => $input,
|
|
|
55 |
'feedbackformat' => $inputformat,
|
|
|
56 |
])
|
|
|
57 |
);
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
/**
|
|
|
61 |
* Ensure that feedback is correctly formatted. Test augmented functionality to handle file links
|
|
|
62 |
*/
|
11 |
efrain |
63 |
public function test_format_feedback_with_grade(): void {
|
1 |
efrain |
64 |
$this->resetAfterTest();
|
|
|
65 |
$dg = $this->getDataGenerator();
|
|
|
66 |
$c1 = $dg->create_course();
|
|
|
67 |
$u1 = $dg->create_user();
|
|
|
68 |
$gi1a = new \grade_item($dg->create_grade_item(['courseid' => $c1->id]), false);
|
|
|
69 |
$gi1a->update_final_grade($u1->id, 1, 'test');
|
|
|
70 |
$contextid = $gi1a->get_context()->id;
|
|
|
71 |
$gradeid = $gi1a->id;
|
|
|
72 |
|
|
|
73 |
$tests = [
|
|
|
74 |
'Has server based image (HTML)' => [
|
|
|
75 |
'<p>See this reference: <img src="@@PLUGINFILE@@/test.img"></p>',
|
|
|
76 |
FORMAT_HTML,
|
|
|
77 |
"See this reference: "
|
|
|
78 |
],
|
|
|
79 |
'Has server based image and more (HTML)' => [
|
|
|
80 |
'<p>See <img src="@@PLUGINFILE@@/test.img"> for <em>reference</em></p>',
|
|
|
81 |
FORMAT_HTML,
|
|
|
82 |
"See for reference"
|
|
|
83 |
],
|
|
|
84 |
'Has server based video and more (HTML)' => [
|
|
|
85 |
'<p>See <video src="@@PLUGINFILE@@/test.img">video of a duck</video> for <em>reference</em></p>',
|
|
|
86 |
FORMAT_HTML,
|
|
|
87 |
'See video of a duck for reference'
|
|
|
88 |
],
|
|
|
89 |
'Has server based video with text and more (HTML)' => [
|
|
|
90 |
'<p>See <video src="@@PLUGINFILE@@/test.img">@@PLUGINFILE@@/test.img</video> for <em>reference</em></p>',
|
|
|
91 |
FORMAT_HTML,
|
|
|
92 |
"See https://www.example.com/moodle/pluginfile.php/$contextid/grade/feedback/$gradeid/test.img for reference"
|
|
|
93 |
],
|
|
|
94 |
'Multiple videos (HTML)' => [
|
|
|
95 |
'<p>See <video src="@@PLUGINFILE@@/test.img">video of a duck</video> and '.
|
|
|
96 |
'<video src="http://example.com/myimage.jpg">video of a cat</video> for <em>reference</em></p>',
|
|
|
97 |
FORMAT_HTML,
|
|
|
98 |
'See video of a duck and video of a cat for reference'
|
|
|
99 |
],
|
|
|
100 |
];
|
|
|
101 |
|
|
|
102 |
$feedback = $this->getMockForAbstractClass(
|
|
|
103 |
\grade_export::class,
|
|
|
104 |
[],
|
|
|
105 |
'',
|
|
|
106 |
false
|
|
|
107 |
);
|
|
|
108 |
|
|
|
109 |
foreach ($tests as $key => $testdetails) {
|
|
|
110 |
$expected = $testdetails[2];
|
|
|
111 |
$input = $testdetails[0];
|
|
|
112 |
$inputformat = $testdetails[1];
|
|
|
113 |
|
|
|
114 |
$this->assertEquals(
|
|
|
115 |
$expected,
|
|
|
116 |
$feedback->format_feedback((object) [
|
|
|
117 |
'feedback' => $input,
|
|
|
118 |
'feedbackformat' => $inputformat,
|
|
|
119 |
], $gi1a),
|
|
|
120 |
$key
|
|
|
121 |
);
|
|
|
122 |
}
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
/**
|
|
|
126 |
* Data provider for the format_feedback tests.
|
|
|
127 |
*
|
|
|
128 |
* @return array
|
|
|
129 |
*/
|
|
|
130 |
public function format_feedback_provider(): array {
|
|
|
131 |
return [
|
|
|
132 |
'Basic string (PLAIN)' => [
|
|
|
133 |
'This is an example string',
|
|
|
134 |
FORMAT_PLAIN,
|
|
|
135 |
'This is an example string',
|
|
|
136 |
],
|
|
|
137 |
'Basic string (HTML)' => [
|
|
|
138 |
'<p>This is an example string</p>',
|
|
|
139 |
FORMAT_HTML,
|
|
|
140 |
'This is an example string',
|
|
|
141 |
],
|
|
|
142 |
'Has image (HTML)' => [
|
|
|
143 |
'<p>See this reference: <img src="http://example.com/myimage.jpg"></p>',
|
|
|
144 |
FORMAT_HTML,
|
|
|
145 |
'See this reference: ',
|
|
|
146 |
],
|
|
|
147 |
'Has image and more (HTML)' => [
|
|
|
148 |
'<p>See <img src="http://example.com/myimage.jpg"> for <em>reference</em></p>',
|
|
|
149 |
FORMAT_HTML,
|
|
|
150 |
'See for reference',
|
|
|
151 |
],
|
|
|
152 |
'Has video and more (HTML)' => [
|
|
|
153 |
'<p>See <video src="http://example.com/myimage.jpg">video of a duck</video> for <em>reference</em></p>',
|
|
|
154 |
FORMAT_HTML,
|
|
|
155 |
'See video of a duck for reference',
|
|
|
156 |
],
|
|
|
157 |
'Multiple videos (HTML)' => [
|
|
|
158 |
'<p>See <video src="http://example.com/myimage.jpg">video of a duck</video> and '.
|
|
|
159 |
'<video src="http://example.com/myimage.jpg">video of a cat</video> for <em>reference</em></p>',
|
|
|
160 |
FORMAT_HTML,
|
|
|
161 |
'See video of a duck and video of a cat for reference'
|
|
|
162 |
],
|
|
|
163 |
'HTML Looking tags in PLAIN' => [
|
|
|
164 |
'The way you have written the <img thing looks pretty fun >',
|
|
|
165 |
FORMAT_PLAIN,
|
|
|
166 |
'The way you have written the <img thing looks pretty fun >',
|
|
|
167 |
],
|
|
|
168 |
|
|
|
169 |
];
|
|
|
170 |
}
|
|
|
171 |
}
|