Пример #1
0
 /**
  * Set up message and mail sinks, and set up other requirements for the
  * cron to be tested here.
  */
 public function setUp()
 {
     global $CFG;
     $this->helper = new stdClass();
     // Messaging is not compatible with transactions...
     $this->preventResetByRollback();
     // Catch all messages
     $this->helper->messagesink = $this->redirectMessages();
     $this->helper->mailsink = $this->redirectEmails();
     // Confirm that we have an empty message sink so far.
     $messages = $this->helper->messagesink->get_messages();
     $this->assertEquals(0, count($messages));
     $messages = $this->helper->mailsink->get_messages();
     $this->assertEquals(0, count($messages));
     // Tell Moodle that we've not sent any digest messages out recently.
     $CFG->digestmailtimelast = 0;
     // And set the digest sending time to a negative number - this has
     // the effect of making it 11pm the previous day.
     $CFG->digestmailtime = -1;
     // Forcibly reduce the maxeditingtime to a one second to ensure that
     // messages are sent out.
     $CFG->maxeditingtime = 1;
     // We must clear the subscription caches. This has to be done both before each test, and after in case of other
     // tests using these functions.
     \mod_twf\subscriptions::reset_twf_cache();
     \mod_twf\subscriptions::reset_discussion_cache();
 }
Пример #2
0
 public function tearDown()
 {
     // We must clear the subscription caches. This has to be done both before each test, and after in case of other
     // tests using these functions.
     \mod_twf\subscriptions::reset_twf_cache();
     $this->helper->messagesink->clear();
     $this->helper->messagesink->close();
     $this->helper->mailsink->clear();
     $this->helper->mailsink->close();
 }
Пример #3
0
 /**
  * Test that the discussion subscription cache can filled user-at-a-time.
  */
 public function test_discussion_subscription_cache_fill()
 {
     global $DB;
     $this->resetAfterTest(true);
     // Create a course, with a twf.
     $course = $this->getDataGenerator()->create_course();
     $options = array('course' => $course->id, 'forcesubscribe' => FORUM_INITIALSUBSCRIBE);
     $twf = $this->getDataGenerator()->create_module('twf', $options);
     // Create some users.
     $users = $this->helper_create_users($course, 20);
     // Post some discussions to the twf.
     $discussions = array();
     $author = $users[0];
     for ($i = 0; $i < 20; $i++) {
         list($discussion, $post) = $this->helper_post_to_twf($twf, $author);
         $discussions[] = $discussion;
     }
     // Unsubscribe half the users from the half the discussions.
     $twfcount = 0;
     $usercount = 0;
     foreach ($discussions as $data) {
         if ($twfcount % 2) {
             continue;
         }
         foreach ($users as $user) {
             if ($usercount % 2) {
                 continue;
             }
             \mod_twf\subscriptions::unsubscribe_user_from_discussion($user->id, $discussion);
             $usercount++;
         }
         $twfcount++;
     }
     // Reset the subscription caches.
     \mod_twf\subscriptions::reset_twf_cache();
     \mod_twf\subscriptions::reset_discussion_cache();
     $startcount = $DB->perf_get_reads();
     // Now fetch some subscriptions from that twf - these should use
     // the cache and not perform additional queries.
     foreach ($users as $user) {
         $result = \mod_twf\subscriptions::fetch_discussion_subscription($twf->id, $user->id);
         $this->assertInternalType('array', $result);
     }
     $finalcount = $DB->perf_get_reads();
     $this->assertEquals(20, $finalcount - $startcount);
 }
Пример #4
0
 public function tearDown()
 {
     // We must clear the subscription caches. This has to be done both before each test, and after in case of other
     // tests using these functions.
     \mod_twf\subscriptions::reset_twf_cache();
 }