/** * Run the quora cron, and check that the specified post was sent the * specified number of times. * * @param integer $expected The number of times that the post should have been sent * @return array An array of the messages caught by the message sink */ protected function helper_run_cron_check_count($expected, $messagecount, $mailcount) { if ($expected === 0) { $this->expectOutputRegex('/(Email digests successfully sent to .* users.){0}/'); } else { $this->expectOutputRegex("/Email digests successfully sent to {$expected} users/"); } quora_cron(); // Now check the results in the message sink. $messages = $this->helper->messagesink->get_messages(); // There should be the expected number of messages. $this->assertEquals($messagecount, count($messages)); // Now check the results in the mail sink. $messages = $this->helper->mailsink->get_messages(); // There should be the expected number of messages. $this->assertEquals($mailcount, count($messages)); return $messages; }
public function test_quora_message_inbound_multiple_posts() { $this->resetAfterTest(true); // Create a course, with a quora. $course = $this->getDataGenerator()->create_course(); $options = array('course' => $course->id, 'forcesubscribe' => FORUM_FORCESUBSCRIBE); $quora = $this->getDataGenerator()->create_module('quora', $options); // Create a user enrolled in the course as a student. list($author) = $this->helper_create_users($course, 1); $expectedmessages = array(); // Post a discussion to the quora. list($discussion, $post) = $this->helper_post_to_quora($quora, $author); $this->helper_update_post_time($post, -90); $expectedmessages[] = array('id' => $post->id, 'subject' => $post->subject, 'count' => 0); // Then post a reply to the first discussion. $reply = $this->helper_post_to_discussion($quora, $discussion, $author); $this->helper_update_post_time($reply, -60); $expectedmessages[] = array('id' => $reply->id, 'subject' => $reply->subject, 'count' => 1); $expectedcount = 2; // Ensure that messageinbound is enabled and configured for the quora handler. $this->helper_spoof_message_inbound_setup(); $author->emailstop = '0'; set_user_preference('message_provider_mod_quora_posts_loggedoff', 'email', $author); set_user_preference('message_provider_mod_quora_posts_loggedin', 'email', $author); // Run cron and check that the expected number of users received the notification. // Clear the mailsink, and close the messagesink. $this->helper->mailsink->clear(); $this->helper->messagesink->close(); // Cron daily uses mtrace, turn on buffering to silence output. foreach ($expectedmessages as $post) { $this->expectOutputRegex("/{$post['count']} users were sent post {$post['id']}, '{$post['subject']}'/"); } quora_cron(); $messages = $this->helper->mailsink->get_messages(); // There should be the expected number of messages. $this->assertEquals($expectedcount, count($messages)); foreach ($messages as $message) { $this->assertRegExp('/Reply-To: moodlemoodle123\\+[^@]*@example.com/', $message->header); } }
/** * Run quora cron. */ public function execute() { global $CFG; require_once $CFG->dirroot . '/mod/quora/lib.php'; quora_cron(); }