|
25 | 25 | defined('MOODLE_INTERNAL') || die();
|
26 | 26 |
|
27 | 27 | global $CFG;
|
28 |
| -require_once($CFG->dirroot . '/mod/assign/tests/base_test.php'); |
| 28 | +require_once($CFG->dirroot . '/mod/assign/tests/generator.php'); |
29 | 29 |
|
30 | 30 | /**
|
31 | 31 | * Unit tests for assignfeedback_comments
|
32 | 32 | *
|
33 | 33 | * @copyright 2016 Adrian Greeve <adrian@moodle.com>
|
34 | 34 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
35 | 35 | */
|
36 |
| -class assignfeedback_comments_testcase extends mod_assign_base_testcase { |
| 36 | +class assignfeedback_comments_testcase extends advanced_testcase { |
37 | 37 |
|
38 |
| - /** |
39 |
| - * Create an assign object and submit an online text submission. |
40 |
| - */ |
41 |
| - protected function create_assign_and_submit_text() { |
42 |
| - $assign = $this->create_instance(array('assignsubmission_onlinetext_enabled' => 1, |
43 |
| - 'assignfeedback_comments_enabled' => 1)); |
44 |
| - |
45 |
| - $user = $this->students[0]; |
46 |
| - $this->setUser($user); |
47 |
| - |
48 |
| - // Create an online text submission. |
49 |
| - $submission = $assign->get_user_submission($user->id, true); |
50 |
| - |
51 |
| - $data = new stdClass(); |
52 |
| - $data->onlinetext_editor = array( |
53 |
| - 'text' => '<p>This is some text.</p>', |
54 |
| - 'format' => 1, |
55 |
| - 'itemid' => file_get_unused_draft_itemid()); |
56 |
| - $plugin = $assign->get_submission_plugin_by_type('onlinetext'); |
57 |
| - $plugin->save($submission, $data); |
58 |
| - |
59 |
| - return $assign; |
60 |
| - } |
| 38 | + // Use the generator helper. |
| 39 | + use mod_assign_test_generator; |
61 | 40 |
|
62 | 41 | /**
|
63 | 42 | * Test the is_feedback_modified() method for the comments feedback.
|
64 | 43 | */
|
65 | 44 | public function test_is_feedback_modified() {
|
66 |
| - $assign = $this->create_assign_and_submit_text(); |
| 45 | + $this->resetAfterTest(); |
| 46 | + $course = $this->getDataGenerator()->create_course(); |
| 47 | + $teacher = $this->getDataGenerator()->create_and_enrol($course, 'teacher'); |
| 48 | + $student = $this->getDataGenerator()->create_and_enrol($course, 'student'); |
67 | 49 |
|
68 |
| - $this->setUser($this->teachers[0]); |
| 50 | + $assign = $this->create_instance($course, [ |
| 51 | + 'assignsubmission_onlinetext_enabled' => 1, |
| 52 | + 'assignfeedback_comments_enabled' => 1, |
| 53 | + ]); |
| 54 | + |
| 55 | + // Create an online text submission. |
| 56 | + $this->add_submission($student, $assign); |
| 57 | + |
| 58 | + $this->setUser($teacher); |
69 | 59 |
|
70 | 60 | // Create formdata.
|
71 |
| - $data = new stdClass(); |
72 |
| - $data->assignfeedbackcomments_editor = array( |
| 61 | + $grade = $assign->get_user_grade($student->id, true); |
| 62 | + $data = (object) [ |
| 63 | + 'assignfeedbackcomments_editor' => [ |
73 | 64 | 'text' => '<p>first comment for this test</p>',
|
74 |
| - 'format' => 1 |
75 |
| - ); |
76 |
| - $grade = $assign->get_user_grade($this->students[0]->id, true); |
| 65 | + 'format' => 1, |
| 66 | + ] |
| 67 | + ]; |
77 | 68 |
|
78 | 69 | // This is the first time that we are submitting feedback, so it is modified.
|
79 | 70 | $plugin = $assign->get_feedback_plugin_by_type('comments');
|
80 | 71 | $this->assertTrue($plugin->is_feedback_modified($grade, $data));
|
| 72 | + |
81 | 73 | // Save the feedback.
|
82 | 74 | $plugin->save($grade, $data);
|
| 75 | + |
83 | 76 | // Try again with the same data.
|
84 | 77 | $this->assertFalse($plugin->is_feedback_modified($grade, $data));
|
| 78 | + |
85 | 79 | // Change the data.
|
86 |
| - $data->assignfeedbackcomments_editor = array( |
| 80 | + $data->assignfeedbackcomments_editor = [ |
87 | 81 | 'text' => '<p>Altered comment for this test</p>',
|
88 |
| - 'format' => 1 |
89 |
| - ); |
| 82 | + 'format' => 1, |
| 83 | + ]; |
90 | 84 | $this->assertTrue($plugin->is_feedback_modified($grade, $data));
|
91 | 85 | }
|
92 | 86 | }
|
0 commit comments