Merge branch 'w42_MDL-42224_m26_msgredir' of https://github.com/skodak/moodle
[moodle.git] / lib / tests / moodlelib_test.php
index 0129df7..48ec5fd 100644 (file)
@@ -2493,6 +2493,8 @@ class core_moodlelib_testcase extends advanced_testcase {
     }
 
     public function test_email_to_user() {
+        global $CFG;
+
         $this->resetAfterTest();
 
         $user1 = $this->getDataGenerator()->create_user();
@@ -2503,8 +2505,15 @@ class core_moodlelib_testcase extends advanced_testcase {
         $subject2 = 'subject 2';
         $messagetext2 = 'message text 2';
 
+        $this->assertNotEmpty($CFG->noemailever);
+        email_to_user($user1, $user2, $subject, $messagetext);
+        $this->assertDebuggingCalled('Not sending email due to $CFG->noemailever config setting');
+
         unset_config('noemailever');
 
+        email_to_user($user1, $user2, $subject, $messagetext);
+        $this->assertDebuggingCalled('Unit tests must not send real emails! Use $this->redirectEmails()');
+
         $sink = $this->redirectEmails();
         email_to_user($user1, $user2, $subject, $messagetext);
         email_to_user($user2, $user1, $subject2, $messagetext2);
@@ -2522,6 +2531,9 @@ class core_moodlelib_testcase extends advanced_testcase {
         $this->assertSame($messagetext2, trim($result[1]->body));
         $this->assertSame($user2->email, $result[1]->to);
         $this->assertSame($user1->email, $result[1]->from);
+
+        email_to_user($user1, $user2, $subject, $messagetext);
+        $this->assertDebuggingCalled('Unit tests must not send real emails! Use $this->redirectEmails()');
     }
 
     /**