Beispiel #1
0
 /**
  * Run twf cron.
  */
 public function execute()
 {
     global $CFG;
     require_once $CFG->dirroot . '/mod/twf/lib.php';
     twf_cron();
 }
Beispiel #2
0
 public function test_twf_message_inbound_multiple_posts()
 {
     $this->resetAfterTest(true);
     // Create a course, with a twf.
     $course = $this->getDataGenerator()->create_course();
     $options = array('course' => $course->id, 'forcesubscribe' => FORUM_FORCESUBSCRIBE);
     $twf = $this->getDataGenerator()->create_module('twf', $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 twf.
     list($discussion, $post) = $this->helper_post_to_twf($twf, $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($twf, $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 twf handler.
     $this->helper_spoof_message_inbound_setup();
     $author->emailstop = '0';
     set_user_preference('message_provider_mod_twf_posts_loggedoff', 'email', $author);
     set_user_preference('message_provider_mod_twf_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']}'/");
     }
     twf_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 the twf 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/");
     }
     twf_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;
 }