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 assignfeedback_comments;
|
|
|
18 |
|
|
|
19 |
use mod_assign_test_generator;
|
|
|
20 |
|
|
|
21 |
defined('MOODLE_INTERNAL') || die();
|
|
|
22 |
|
|
|
23 |
global $CFG;
|
|
|
24 |
require_once($CFG->dirroot . '/mod/assign/tests/generator.php');
|
|
|
25 |
|
|
|
26 |
/**
|
|
|
27 |
* Unit tests for assignfeedback_comments
|
|
|
28 |
*
|
|
|
29 |
* @package assignfeedback_comments
|
|
|
30 |
* @copyright 2016 Adrian Greeve <adrian@moodle.com>
|
|
|
31 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
32 |
*/
|
|
|
33 |
class feedback_test extends \advanced_testcase {
|
|
|
34 |
|
|
|
35 |
// Use the generator helper.
|
|
|
36 |
use mod_assign_test_generator;
|
|
|
37 |
|
|
|
38 |
/**
|
|
|
39 |
* Test the is_feedback_modified() method for the comments feedback.
|
|
|
40 |
*/
|
11 |
efrain |
41 |
public function test_is_feedback_modified(): void {
|
1 |
efrain |
42 |
$this->resetAfterTest();
|
|
|
43 |
$course = $this->getDataGenerator()->create_course();
|
|
|
44 |
$teacher = $this->getDataGenerator()->create_and_enrol($course, 'teacher');
|
|
|
45 |
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
|
|
|
46 |
|
|
|
47 |
$assign = $this->create_instance($course, [
|
|
|
48 |
'assignsubmission_onlinetext_enabled' => 1,
|
|
|
49 |
'assignfeedback_comments_enabled' => 1,
|
|
|
50 |
]);
|
|
|
51 |
|
|
|
52 |
// Create an online text submission.
|
|
|
53 |
$this->add_submission($student, $assign);
|
|
|
54 |
|
|
|
55 |
$this->setUser($teacher);
|
|
|
56 |
|
|
|
57 |
// Create formdata.
|
|
|
58 |
$grade = $assign->get_user_grade($student->id, true);
|
|
|
59 |
$data = (object) [
|
|
|
60 |
'assignfeedbackcomments_editor' => [
|
|
|
61 |
'text' => '<p>first comment for this test</p>',
|
|
|
62 |
'format' => 1,
|
|
|
63 |
]
|
|
|
64 |
];
|
|
|
65 |
|
|
|
66 |
// This is the first time that we are submitting feedback, so it is modified.
|
|
|
67 |
$plugin = $assign->get_feedback_plugin_by_type('comments');
|
|
|
68 |
$this->assertTrue($plugin->is_feedback_modified($grade, $data));
|
|
|
69 |
|
|
|
70 |
// Save the feedback.
|
|
|
71 |
$plugin->save($grade, $data);
|
|
|
72 |
|
|
|
73 |
// Try again with the same data.
|
|
|
74 |
$this->assertFalse($plugin->is_feedback_modified($grade, $data));
|
|
|
75 |
|
|
|
76 |
// Change the data.
|
|
|
77 |
$data->assignfeedbackcomments_editor = [
|
|
|
78 |
'text' => '<p>Altered comment for this test</p>',
|
|
|
79 |
'format' => 1,
|
|
|
80 |
];
|
|
|
81 |
$this->assertTrue($plugin->is_feedback_modified($grade, $data));
|
|
|
82 |
}
|
|
|
83 |
}
|