MDL-59834 Global Search: Indexing user messages
[moodle.git] / message / tests / search_test_sent.php
index 7e9c887..75a3735 100644 (file)
@@ -226,4 +226,50 @@ class message_sent_search_testcase extends advanced_testcase {
         $this->assertEquals(\core_search\manager::ACCESS_DELETED, $searcharea->check_access($messageid));
 
     }
+
+    /**
+     * Test sent deleted user.
+     * Tests the case where a sent message for a deleted user
+     * is attempted to be added to the index.
+     *
+     * @return void
+     */
+    public function test_message_sent_deleted_user() {
+
+        // Returns the instance as long as the area is supported.
+        $searcharea = \core_search\manager::get_search_area($this->messagesentareaid);
+        $this->assertInstanceOf('\core_message\search\message_sent', $searcharea);
+
+        $user1 = self::getDataGenerator()->create_user();
+        $user2 = self::getDataGenerator()->create_user();
+
+        $this->preventResetByRollback();
+        $sink = $this->redirectMessages();
+
+        $message = new \core\message\message();
+        $message->courseid = SITEID;
+        $message->userfrom = $user1;
+        $message->userto = $user2;
+        $message->subject = "Test Subject";
+        $message->smallmessage = "Test small messsage";
+        $message->fullmessage = "Test full messsage";
+        $message->fullmessageformat = 0;
+        $message->fullmessagehtml = null;
+        $message->notification = 0;
+        $message->component = "moodle";
+        $message->name = "instantmessage";
+
+        message_send($message);
+
+        $messages = $sink->get_messages();
+        $message = $messages[0];
+
+        // Delete user.
+        delete_user($user1);
+
+        $doc = $searcharea->get_document($message);
+
+        $this->assertFalse($doc);
+
+    }
 }
\ No newline at end of file