/** * Test discussion_created event. */ public function test_discussion_created() { // Setup test data. $course = $this->getDataGenerator()->create_course(); $quora = $this->getDataGenerator()->create_module('quora', array('course' => $course->id)); $user = $this->getDataGenerator()->create_user(); // Add a discussion. $record = array(); $record['course'] = $course->id; $record['quora'] = $quora->id; $record['userid'] = $user->id; $discussion = $this->getDataGenerator()->get_plugin_generator('mod_quora')->create_discussion($record); $context = context_module::instance($quora->cmid); $params = array('context' => $context, 'objectid' => $discussion->id, 'other' => array('quoraid' => $quora->id)); // Create the event. $event = \mod_quora\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_quora\\event\\discussion_created', $event); $this->assertEquals($context, $event->get_context()); $expected = array($course->id, 'quora', 'add discussion', "discuss.php?d={$discussion->id}", $discussion->id, $quora->cmid); $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); $this->assertNotEmpty($event->get_name()); }
if (empty($fromform->groupid)) { $fromform->groupid = -1; } $groupstopostto = array($fromform->groupid); } // Before we post this we must check that the user will not exceed the blocking threshold. quora_check_blocking_threshold($thresholdwarning); foreach ($groupstopostto as $group) { if (!quora_user_can_post_discussion($quora, $group, -1, $cm, $modcontext)) { print_error('cannotcreatediscussion', 'quora'); } $discussion->groupid = $group; $message = ''; if ($discussion->id = quora_add_discussion($discussion, $mform_post, $message)) { $params = array('context' => $modcontext, 'objectid' => $discussion->id, 'other' => array('quoraid' => $quora->id)); $event = \mod_quora\event\discussion_created::create($params); $event->add_record_snapshot('quora_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", "quora"); $timemessage = 4; } else { $message .= '<p>' . get_string("postaddedsuccess", "quora") . '</p>'; $message .= '<p>' . get_string("postaddedtimeleft", "quora", format_time($CFG->maxeditingtime)) . '</p>'; } if ($subscribemessage = quora_post_subscription($fromform, $quora, $discussion)) {