mirror of
https://github.com/moodle/moodle.git
synced 2025-08-07 01:46:45 +02:00
MDL-40051 core_lib: replaced add_to_log call when failing to send email with an event
This commit is contained in:
parent
0b7422f366
commit
362b9a0465
4 changed files with 126 additions and 1 deletions
|
@ -140,4 +140,35 @@ class core_events_testcase extends advanced_testcase {
|
|||
$expected = array(SITEID, 'category', 'show', 'editcategory.php?id=' . $category2->id, $category2->id);
|
||||
$this->assertEventLegacyLogData($expected, $event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the email failed event.
|
||||
*
|
||||
* It's not possible to use the moodle API to simulate the failure of sending
|
||||
* an email, so here we simply create the event and trigger it.
|
||||
*/
|
||||
public function test_email_failed() {
|
||||
// Trigger event for failing to send email.
|
||||
$event = \core\event\email_failed::create(array(
|
||||
'context' => context_system::instance(),
|
||||
'userid' => 1,
|
||||
'relateduserid' => 2,
|
||||
'other' => array(
|
||||
'subject' => 'This is a subject',
|
||||
'message' => 'This is a message',
|
||||
'errorinfo' => 'The email failed to send!'
|
||||
)
|
||||
));
|
||||
|
||||
// Trigger and capture the event.
|
||||
$sink = $this->redirectEvents();
|
||||
$event->trigger();
|
||||
$events = $sink->get_events();
|
||||
$event = reset($events);
|
||||
|
||||
$this->assertInstanceOf('\core\event\email_failed', $event);
|
||||
$this->assertEquals(context_system::instance(), $event->get_context());
|
||||
$expected = array(SITEID, 'library', 'mailer', qualified_me(), 'ERROR: The email failed to send!');
|
||||
$this->assertEventLegacyLogData($expected, $event);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue