MDL-58650 core_message: always use 'popup' processor for messages
[moodle.git] / lib / tests / messagelib_test.php
index 1e51f3e..051f61c 100644 (file)
@@ -400,6 +400,7 @@ class core_messagelib_testcase extends advanced_testcase {
 
         $eventsink = $this->redirectEvents();
 
+        // Will always use the pop-up processor.
         set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'none', $user2);
 
         $message = new \core\message\message();
@@ -484,6 +485,7 @@ class core_messagelib_testcase extends advanced_testcase {
         $this->assertInstanceOf('\core\event\message_viewed', $events[1]);
         $eventsink->clear();
 
+        // Will always use the pop-up processor.
         set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'email', $user2);
 
         $message = new \core\message\message();
@@ -515,6 +517,7 @@ class core_messagelib_testcase extends advanced_testcase {
         $eventsink->clear();
         $user2->emailstop = '0';
 
+        // Will always use the pop-up processor.
         set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'email', $user2);
 
         $message = new \core\message\message();
@@ -534,19 +537,18 @@ class core_messagelib_testcase extends advanced_testcase {
         $emails = $sink->get_messages();
         $this->assertCount(1, $emails);
         $email = reset($emails);
-        $savedmessage = $DB->get_record('message_read', array('id' => $messageid), '*', MUST_EXIST);
+        $savedmessage = $DB->get_record('message', array('id' => $messageid), '*', MUST_EXIST);
         $this->assertSame($user1->email, $email->from);
         $this->assertSame($user2->email, $email->to);
         $this->assertSame($message->subject, $email->subject);
         $this->assertNotEmpty($email->header);
         $this->assertNotEmpty($email->body);
         $sink->clear();
-        $this->assertFalse($DB->record_exists('message', array()));
+        $this->assertFalse($DB->record_exists('message_read', array()));
         $DB->delete_records('message_read', array());
         $events = $eventsink->get_events();
-        $this->assertCount(2, $events);
+        $this->assertCount(1, $events);
         $this->assertInstanceOf('\core\event\message_sent', $events[0]);
-        $this->assertInstanceOf('\core\event\message_viewed', $events[1]);
         $eventsink->clear();
 
         set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'email,popup', $user2);
@@ -618,6 +620,7 @@ class core_messagelib_testcase extends advanced_testcase {
         }
         $transaction->allow_commit();
 
+        // Will always use the pop-up processor.
         set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'none', $user2);
 
         $message = new \core\message\message();
@@ -643,13 +646,14 @@ class core_messagelib_testcase extends advanced_testcase {
         $this->assertFalse($DB->record_exists('message_read', array()));
         $DB->delete_records('message', array());
         $events = $eventsink->get_events();
-        $this->assertCount(1, $events);
-        $this->assertInstanceOf('\core\event\message_sent', $events[0]);
+        $this->assertCount(0, $events);
         $eventsink->clear();
         $transaction->allow_commit();
         $events = $eventsink->get_events();
-        $this->assertCount(0, $events);
+        $this->assertCount(1, $events);
+        $this->assertInstanceOf('\core\event\message_sent', $events[0]);
 
+        // Will always use the pop-up processor.
         set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'email', $user2);
 
         $message = new \core\message\message();
@@ -674,28 +678,26 @@ class core_messagelib_testcase extends advanced_testcase {
         $sink->clear();
         $this->assertFalse($DB->record_exists('message_read', array()));
         $events = $eventsink->get_events();
-        $this->assertCount(0, $events);
+        $this->assertCount(1, $events);
+        $this->assertInstanceOf('\core\event\message_sent', $events[0]);
         $transaction->allow_commit();
         $events = $eventsink->get_events();
         $this->assertCount(2, $events);
-        $this->assertInstanceOf('\core\event\message_sent', $events[0]);
-        $this->assertInstanceOf('\core\event\message_viewed', $events[1]);
+        $this->assertInstanceOf('\core\event\message_sent', $events[1]);
         $eventsink->clear();
 
         $transaction = $DB->start_delegated_transaction();
         message_send($message);
         message_send($message);
-        $this->assertCount(2, $DB->get_records('message'));
-        $this->assertCount(1, $DB->get_records('message_read'));
+        $this->assertCount(3, $DB->get_records('message'));
+        $this->assertFalse($DB->record_exists('message_read', array()));
         $events = $eventsink->get_events();
         $this->assertCount(0, $events);
         $transaction->allow_commit();
         $events = $eventsink->get_events();
-        $this->assertCount(4, $events);
+        $this->assertCount(2, $events);
         $this->assertInstanceOf('\core\event\message_sent', $events[0]);
-        $this->assertInstanceOf('\core\event\message_viewed', $events[1]);
-        $this->assertInstanceOf('\core\event\message_sent', $events[2]);
-        $this->assertInstanceOf('\core\event\message_viewed', $events[3]);
+        $this->assertInstanceOf('\core\event\message_sent', $events[1]);
         $eventsink->clear();
         $DB->delete_records('message', array());
         $DB->delete_records('message_read', array());
@@ -717,10 +719,11 @@ class core_messagelib_testcase extends advanced_testcase {
         $this->assertCount(0, $DB->get_records('message'));
         $this->assertCount(0, $DB->get_records('message_read'));
         message_send($message);
-        $this->assertCount(0, $DB->get_records('message'));
-        $this->assertCount(1, $DB->get_records('message_read'));
+        $this->assertCount(1, $DB->get_records('message'));
+        $this->assertCount(0, $DB->get_records('message_read'));
         $events = $eventsink->get_events();
-        $this->assertCount(2, $events);
+        $this->assertCount(1, $events);
+        $this->assertInstanceOf('\core\event\message_sent', $events[0]);
         $sink->clear();
         $DB->delete_records('message_read', array());
     }