Merge branch 'MDL-85802-500' of https://github.com/mihailges/moodle into MOODLE_500_STABLE
This commit is contained in:
@@ -153,8 +153,10 @@ class notification_helper {
|
||||
|
||||
$stringparams = [
|
||||
'firstname' => $user->firstname,
|
||||
'quizname' => $quiz->name,
|
||||
'coursename' => $quizobj->get_course()->fullname,
|
||||
'quizname' => format_string($quiz->name,
|
||||
options: ['context' => $quizobj->get_context(), 'escape' => false]),
|
||||
'coursename' => format_string($quizobj->get_course()->fullname,
|
||||
options: ['context' => \context_course::instance($quizobj->get_course()->id), 'escape' => false]),
|
||||
'timeopen' => userdate($user->timeopen),
|
||||
'timeclose' => !empty($user->timeclose) ? userdate($user->timeclose) : get_string('statusna'),
|
||||
'url' => $url,
|
||||
@@ -164,7 +166,7 @@ class notification_helper {
|
||||
'user' => \core_user::get_user($user->id),
|
||||
'url' => $url->out(false),
|
||||
'subject' => get_string('quizopendatesoonsubject', 'mod_quiz', $stringparams),
|
||||
'quizname' => $quiz->name,
|
||||
'quizname' => $stringparams['quizname'],
|
||||
'html' => get_string('quizopendatesoonhtml', 'mod_quiz', $stringparams),
|
||||
];
|
||||
|
||||
|
||||
@@ -300,4 +300,64 @@ final class notification_helper_test extends \advanced_testcase {
|
||||
// Clear sink.
|
||||
$sink->clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test content filtering in the quiz open soon notification.
|
||||
*/
|
||||
public function test_send_notification_to_user_filter_content(): void {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$generator = $this->getDataGenerator();
|
||||
$clock = $this->mock_clock_with_frozen();
|
||||
$sink = $this->redirectMessages();
|
||||
|
||||
filter_set_global_state('multilang', TEXTFILTER_ON);
|
||||
filter_set_applies_to_strings('multilang', true);
|
||||
|
||||
// Create a course and enrol a student.
|
||||
$course = $generator->create_course([
|
||||
'fullname' => '<span class="multilang" lang="en">A&B (en)</span><span class="multilang" lang="es">A&B (es)</span>'
|
||||
]);
|
||||
$student = $generator->create_user();
|
||||
$generator->enrol_user($student->id, $course->id, 'student');
|
||||
|
||||
$quizgenerator = $generator->get_plugin_generator('mod_quiz');
|
||||
|
||||
// Create a quiz with an open date < 48 hours.
|
||||
$quiz = $quizgenerator->create_instance([
|
||||
'name' => '<span class="multilang" lang="en">C&D (en)</span><span class="multilang" lang="es">C&D (es)</span>',
|
||||
'course' => $course->id,
|
||||
'timeopen' => $clock->time() + DAYSECS,
|
||||
]);
|
||||
$clock->bump(5);
|
||||
|
||||
// Run the tasks.
|
||||
$this->run_notification_helper_tasks();
|
||||
|
||||
// Get the notifications that should have been created during the adhoc task.
|
||||
$messages = $sink->get_messages_by_component('mod_quiz');
|
||||
|
||||
$message = reset($messages);
|
||||
|
||||
$subjectstringparams = [
|
||||
'timeopen' => userdate($quiz->timeopen),
|
||||
'quizname' => 'C&D (en)'
|
||||
];
|
||||
$expectedsubject = get_string('quizopendatesoonsubject', 'mod_quiz', $subjectstringparams);
|
||||
|
||||
$fullmessagestringparams = array_merge($subjectstringparams, [
|
||||
'firstname' => $student->firstname,
|
||||
'coursename' => 'A&B (en)',
|
||||
'timeclose' => !empty($quiz->timeclose) ? userdate($quiz->timeclose) : get_string('statusna'),
|
||||
'url' => new \moodle_url('/mod/quiz/view.php', ['id' => $quiz->cmid])
|
||||
]);
|
||||
$expectedfullmessage = get_string('quizopendatesoonhtml', 'mod_quiz', $fullmessagestringparams);
|
||||
|
||||
// Validate
|
||||
$this->assertEquals($expectedsubject, $message->subject);
|
||||
$this->assertEquals($expectedfullmessage, $message->fullmessagehtml);
|
||||
|
||||
// Clear sink.
|
||||
$sink->clear();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user