From 555837c5d4a844436826eb24af06d8dc07877e6c Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Thu, 23 Oct 2014 08:43:29 +0800 Subject: [PATCH] MDL-47808 mod_forum: Correct maxeditingtime for unit tests The maxeditingtime needs to be a negative value for unit tests to ensure that the messages are actually sent out. Whilst fixing this I also discovered that the create_discussion part of the generator also creates the first post. --- mod/forum/tests/mail_test.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/mod/forum/tests/mail_test.php b/mod/forum/tests/mail_test.php index fc5eb634273..29239ecf430 100644 --- a/mod/forum/tests/mail_test.php +++ b/mod/forum/tests/mail_test.php @@ -55,9 +55,9 @@ class mod_forum_mail_testcase extends advanced_testcase { $messages = $helper->mailsink->get_messages(); $this->assertEquals(0, count($messages)); - // Forcibly reduce the maxeditingtime to a one second to ensure that - // messages are sent out. - $CFG->maxeditingtime = 1; + // Forcibly reduce the maxeditingtime to a second in the past to + // ensure that messages are sent out. + $CFG->maxeditingtime = -1; // Ensure that we don't prevent e-mail as this will cause unit test failures. $CFG->noemailever = false; @@ -107,6 +107,7 @@ class mod_forum_mail_testcase extends advanced_testcase { * @param array An array containing the discussion object, and the post object */ protected function helper_post_to_forum($forum, $author) { + global $DB; $generator = $this->getDataGenerator()->get_plugin_generator('mod_forum'); // Create a discussion in the forum, and then add a post to that discussion. @@ -116,13 +117,8 @@ class mod_forum_mail_testcase extends advanced_testcase { $record->forum = $forum->id; $discussion = $generator->create_discussion($record); - $record = new stdClass(); - $record->course = $forum->course; - $record->userid = $author->id; - $record->forum = $forum->id; - $record->discussion = $discussion->id; - $record->mailnow = 1; - $post = $generator->create_post($record); + // Retrieve the post which was created by create_discussion. + $post = $DB->get_record('forum_posts', array('discussion' => $discussion->id)); return array($discussion, $post); }