diff --git a/mod/quiz/classes/notification_helper.php b/mod/quiz/classes/notification_helper.php
index b977ddb2a61..07ef8a37172 100644
--- a/mod/quiz/classes/notification_helper.php
+++ b/mod/quiz/classes/notification_helper.php
@@ -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),
];
diff --git a/mod/quiz/tests/notification_helper_test.php b/mod/quiz/tests/notification_helper_test.php
index 77aa80ea5e4..4b9082bd920 100644
--- a/mod/quiz/tests/notification_helper_test.php
+++ b/mod/quiz/tests/notification_helper_test.php
@@ -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' => 'A&B (en)A&B (es)'
+ ]);
+ $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' => 'C&D (en)C&D (es)',
+ '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();
+ }
}