$groupstopostto[] = -1; } } } // Before we post this we must check that the user will not exceed the blocking threshold. twf_check_blocking_threshold($thresholdwarning); foreach ($groupstopostto as $group) { if (!twf_user_can_post_discussion($twf, $group, -1, $cm, $modcontext)) { print_error('cannotcreatediscussion', 'twf'); } //var_dump($discussion);die; $discussion->groupid = $group; $message = ''; if ($discussion->id = twf_add_discussion($discussion, $mform_post, $message)) { $params = array('context' => $modcontext, 'objectid' => $discussion->id, 'other' => array('twfid' => $twf->id)); $event = \mod_twf\event\discussion_created::create($params); $event->add_record_snapshot('twf_discussions', $discussion); $event->trigger(); $timemessage = 2; if (!empty($message)) { // If we're printing stuff about the file upload. $timemessage = 4; } if ($fromform->mailnow) { $message .= get_string("postmailnow", "twf"); $timemessage = 4; } else { $message .= '<p>' . get_string("postaddedsuccess", "twf") . '</p>'; $message .= '<p>' . get_string("postaddedtimeleft", "twf", format_time($CFG->maxeditingtime)) . '</p>'; } if ($subscribemessage = twf_post_subscription($fromform, $twf, $discussion)) {
/** * Test discussion_created event. */ public function test_discussion_created() { // Setup test data. $course = $this->getDataGenerator()->create_course(); $twf = $this->getDataGenerator()->create_module('twf', array('course' => $course->id)); $user = $this->getDataGenerator()->create_user(); // Add a discussion. $record = array(); $record['course'] = $course->id; $record['twf'] = $twf->id; $record['userid'] = $user->id; $discussion = $this->getDataGenerator()->get_plugin_generator('mod_twf')->create_discussion($record); $context = context_module::instance($twf->cmid); $params = array('context' => $context, 'objectid' => $discussion->id, 'other' => array('twfid' => $twf->id)); // Create the event. $event = \mod_twf\event\discussion_created::create($params); // Trigger and capturing the event. $sink = $this->redirectEvents(); $event->trigger(); $events = $sink->get_events(); $this->assertCount(1, $events); $event = reset($events); // Check that the event contains the expected values. $this->assertInstanceOf('\\mod_twf\\event\\discussion_created', $event); $this->assertEquals($context, $event->get_context()); $expected = array($course->id, 'twf', 'add discussion', "discuss.php?d={$discussion->id}", $discussion->id, $twf->cmid); $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); $this->assertNotEmpty($event->get_name()); }