/** * Test that the discussion subscription cache can filled course-at-a-time. */ public function test_discussion_subscription_cache_fill_for_course() { global $DB; $this->resetAfterTest(true); // Create a course, with a twf. $course = $this->getDataGenerator()->create_course(); // Create the twfs. $options = array('course' => $course->id, 'forcesubscribe' => FORUM_DISALLOWSUBSCRIBE); $disallowtwf = $this->getDataGenerator()->create_module('twf', $options); $options = array('course' => $course->id, 'forcesubscribe' => FORUM_CHOOSESUBSCRIBE); $choosetwf = $this->getDataGenerator()->create_module('twf', $options); $options = array('course' => $course->id, 'forcesubscribe' => FORUM_INITIALSUBSCRIBE); $initialtwf = $this->getDataGenerator()->create_module('twf', $options); // Create some users and keep a reference to the first user. $users = $this->helper_create_users($course, 20); $user = reset($users); // Reset the subscription caches. \mod_twf\subscriptions::reset_twf_cache(); $startcount = $DB->perf_get_reads(); $result = \mod_twf\subscriptions::fill_subscription_cache_for_course($course->id, $user->id); $this->assertNull($result); $postfillcount = $DB->perf_get_reads(); $this->assertEquals(1, $postfillcount - $startcount); $this->assertFalse(\mod_twf\subscriptions::fetch_subscription_cache($disallowtwf->id, $user->id)); $this->assertFalse(\mod_twf\subscriptions::fetch_subscription_cache($choosetwf->id, $user->id)); $this->assertTrue(\mod_twf\subscriptions::fetch_subscription_cache($initialtwf->id, $user->id)); $finalcount = $DB->perf_get_reads(); $this->assertEquals(0, $finalcount - $postfillcount); // Test for all users. foreach ($users as $user) { $result = \mod_twf\subscriptions::fill_subscription_cache_for_course($course->id, $user->id); $this->assertFalse(\mod_twf\subscriptions::fetch_subscription_cache($disallowtwf->id, $user->id)); $this->assertFalse(\mod_twf\subscriptions::fetch_subscription_cache($choosetwf->id, $user->id)); $this->assertTrue(\mod_twf\subscriptions::fetch_subscription_cache($initialtwf->id, $user->id)); } $finalcount = $DB->perf_get_reads(); $this->assertEquals(count($users), $finalcount - $postfillcount); }
$digestoptions = twf_get_user_digest_options(); $digestoptions_selector = new single_select(new moodle_url('/mod/twf/maildigest.php', array('backtoindex' => 1)), 'maildigest', $digestoptions, null, ''); $digestoptions_selector->method = 'post'; // Start of the table for General Forums $generaltable = new html_table(); $generaltable->head = array($strtwf, $strdescription, $strdiscussions); $generaltable->align = array('left', 'left', 'center'); if ($usetracking = twf_tp_can_track_twfs()) { $untracked = twf_tp_get_untracked_twfs($USER->id, $course->id); $generaltable->head[] = $strunreadposts; $generaltable->align[] = 'center'; $generaltable->head[] = $strtracking; $generaltable->align[] = 'center'; } // Fill the subscription cache for this course and user combination. \mod_twf\subscriptions::fill_subscription_cache_for_course($course->id, $USER->id); $can_subscribe = is_enrolled($coursecontext); if ($can_subscribe) { $generaltable->head[] = $strsubscribed; $generaltable->align[] = 'center'; $generaltable->head[] = $stremaildigest . ' ' . $OUTPUT->help_icon('emaildigesttype', 'mod_twf'); $generaltable->align[] = 'center'; } if ($show_rss = ($can_subscribe || $course->id == SITEID) && isset($CFG->enablerssfeeds) && isset($CFG->twf_enablerssfeeds) && $CFG->enablerssfeeds && $CFG->twf_enablerssfeeds) { $generaltable->head[] = $strrss; $generaltable->align[] = 'center'; } $usesections = course_format_uses_sections($course->format); $table = new html_table(); // Parse and organise all the twfs. Most twfs are course modules but // some special ones are not. These get placed in the general twfs