Skip to content

Commit c1f3810

Browse files
author
David Monllao
committed
Merge branch 'MDL-55609-34' of git://github.com/andrewnicols/moodle into MOODLE_34_STABLE
2 parents 1568720 + 572c939 commit c1f3810

File tree

20 files changed

+3738
-2694
lines changed

20 files changed

+3738
-2694
lines changed

lib/testing/generator/data_generator.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,4 +1163,24 @@ public function create_event($data = []) {
11631163

11641164
return $event->properties();
11651165
}
1166+
1167+
/**
1168+
* Create a new user, and enrol them in the specified course as the supplied role.
1169+
*
1170+
* @param \stdClass $course The course to enrol in
1171+
* @param string $role The role to give within the course
1172+
* @param \stdClass $userparams User parameters
1173+
* @return \stdClass The created user
1174+
*/
1175+
public function create_and_enrol($course, $role = 'student', $userparams = null, $enrol = 'manual',
1176+
$timestart = 0, $timeend = 0, $status = null) {
1177+
global $DB;
1178+
1179+
$user = $this->create_user($userparams);
1180+
$roleid = $DB->get_field('role', 'id', ['shortname' => $role ]);
1181+
1182+
$this->enrol_user($user->id, $course->id, $roleid, $enrol, $timestart, $timeend, $status);
1183+
1184+
return $user;
1185+
}
11661186
}

mod/assign/feedback/comments/tests/comments_test.php

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,68 +25,62 @@
2525
defined('MOODLE_INTERNAL') || die();
2626

2727
global $CFG;
28-
require_once($CFG->dirroot . '/mod/assign/tests/base_test.php');
28+
require_once($CFG->dirroot . '/mod/assign/tests/generator.php');
2929

3030
/**
3131
* Unit tests for assignfeedback_comments
3232
*
3333
* @copyright 2016 Adrian Greeve <adrian@moodle.com>
3434
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3535
*/
36-
class assignfeedback_comments_testcase extends mod_assign_base_testcase {
36+
class assignfeedback_comments_testcase extends advanced_testcase {
3737

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;
6140

6241
/**
6342
* Test the is_feedback_modified() method for the comments feedback.
6443
*/
6544
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');
6749

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);
6959

7060
// 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' => [
7364
'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+
];
7768

7869
// This is the first time that we are submitting feedback, so it is modified.
7970
$plugin = $assign->get_feedback_plugin_by_type('comments');
8071
$this->assertTrue($plugin->is_feedback_modified($grade, $data));
72+
8173
// Save the feedback.
8274
$plugin->save($grade, $data);
75+
8376
// Try again with the same data.
8477
$this->assertFalse($plugin->is_feedback_modified($grade, $data));
78+
8579
// Change the data.
86-
$data->assignfeedbackcomments_editor = array(
80+
$data->assignfeedbackcomments_editor = [
8781
'text' => '<p>Altered comment for this test</p>',
88-
'format' => 1
89-
);
82+
'format' => 1,
83+
];
9084
$this->assertTrue($plugin->is_feedback_modified($grade, $data));
9185
}
9286
}

0 commit comments

Comments
 (0)