/** * 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_quora\subscriptions::reset_quora_cache(); \mod_quora\subscriptions::reset_discussion_cache(); }
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_quora\subscriptions::reset_quora_cache(); $this->helper->messagesink->clear(); $this->helper->messagesink->close(); $this->helper->mailsink->clear(); $this->helper->mailsink->close(); }
/** * 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 quora. $course = $this->getDataGenerator()->create_course(); $options = array('course' => $course->id, 'forcesubscribe' => FORUM_INITIALSUBSCRIBE); $quora = $this->getDataGenerator()->create_module('quora', $options); // Create some users. $users = $this->helper_create_users($course, 20); // Post some discussions to the quora. $discussions = array(); $author = $users[0]; for ($i = 0; $i < 20; $i++) { list($discussion, $post) = $this->helper_post_to_quora($quora, $author); $discussions[] = $discussion; } // Unsubscribe half the users from the half the discussions. $quoracount = 0; $usercount = 0; foreach ($discussions as $data) { if ($quoracount % 2) { continue; } foreach ($users as $user) { if ($usercount % 2) { continue; } \mod_quora\subscriptions::unsubscribe_user_from_discussion($user->id, $discussion); $usercount++; } $quoracount++; } // Reset the subscription caches. \mod_quora\subscriptions::reset_quora_cache(); \mod_quora\subscriptions::reset_discussion_cache(); $startcount = $DB->perf_get_reads(); // Now fetch some subscriptions from that quora - these should use // the cache and not perform additional queries. foreach ($users as $user) { $result = \mod_quora\subscriptions::fetch_discussion_subscription($quora->id, $user->id); $this->assertInternalType('array', $result); } $finalcount = $DB->perf_get_reads(); $this->assertEquals(20, $finalcount - $startcount); }
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_quora\subscriptions::reset_quora_cache(); }