/** * Test post_updated event. */ public function test_post_updated_single() { // Setup test data. $course = $this->getDataGenerator()->create_course(); $quora = $this->getDataGenerator()->create_module('quora', array('course' => $course->id, 'type' => 'single')); $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); // Add a post. $record = array(); $record['discussion'] = $discussion->id; $record['userid'] = $user->id; $post = $this->getDataGenerator()->get_plugin_generator('mod_quora')->create_post($record); $context = context_module::instance($quora->cmid); $params = array('context' => $context, 'objectid' => $post->id, 'other' => array('discussionid' => $discussion->id, 'quoraid' => $quora->id, 'quoratype' => $quora->type)); $event = \mod_quora\event\post_updated::create($params); // Trigger and capturing the event. $sink = $this->redirectEvents(); $event->trigger(); $events = $sink->get_events(); $this->assertCount(1, $events); $event = reset($events); // Checking that the event contains the expected values. $this->assertInstanceOf('\\mod_quora\\event\\post_updated', $event); $this->assertEquals($context, $event->get_context()); $expected = array($course->id, 'quora', 'update post', "view.php?f={$quora->id}#p{$post->id}", $post->id, $quora->cmid); $this->assertEventLegacyLogData($expected, $event); $url = new \moodle_url('/mod/quora/view.php', array('f' => $quora->id)); $url->set_anchor('p' . $post->id); $this->assertEquals($url, $event->get_url()); $this->assertEventContextNotUsed($event); $this->assertNotEmpty($event->get_name()); }
if ($subscribemessage = quora_post_subscription($fromform, $quora, $discussion)) { $timemessage = 4; } if ($quora->type == 'single') { // Single discussion quoras are an exception. We show // the quora itself since it only has one discussion // thread. $discussionurl = "view.php?f={$quora->id}"; } else { $discussionurl = "discuss.php?d={$discussion->id}#p{$fromform->id}"; } $params = array('context' => $modcontext, 'objectid' => $fromform->id, 'other' => array('discussionid' => $discussion->id, 'quoraid' => $quora->id, 'quoratype' => $quora->type)); if ($realpost->userid !== $USER->id) { $params['relateduserid'] = $realpost->userid; } $event = \mod_quora\event\post_updated::create($params); $event->add_record_snapshot('quora_discussions', $discussion); $event->trigger(); redirect(quora_go_back_to("{$discussionurl}"), $message . $subscribemessage, $timemessage); exit; } else { if ($fromform->discussion) { // Adding a new post to an existing discussion // Before we add this we must check that the user will not exceed the blocking threshold. quora_check_blocking_threshold($thresholdwarning); unset($fromform->groupid); $message = ''; $addpost = $fromform; $addpost->quora = $quora->id; if ($fromform->id = quora_add_new_post($addpost, $mform_post, $message)) { $timemessage = 2;