Beispiel #1
0
 /**
  * Test validation of discussion_subscription_deleted event.
  */
 public function test_discussion_subscription_deleted_validation()
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/mod/quora/lib.php';
     // Setup test data.
     $course = $this->getDataGenerator()->create_course();
     $user = $this->getDataGenerator()->create_user();
     $this->getDataGenerator()->enrol_user($user->id, $course->id);
     $options = array('course' => $course->id, 'forcesubscribe' => FORUM_INITIALSUBSCRIBE);
     $quora = $this->getDataGenerator()->create_module('quora', $options);
     // 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);
     // The user is not subscribed to the quora. Insert a new discussion subscription.
     $subscription = new \stdClass();
     $subscription->userid = $user->id;
     $subscription->quora = $quora->id;
     $subscription->discussion = $discussion->id;
     $subscription->preference = \mod_quora\subscriptions::FORUM_DISCUSSION_UNSUBSCRIBED;
     $subscription->id = $DB->insert_record('quora_discussion_subs', $subscription);
     $context = context_module::instance($quora->cmid);
     $params = array('context' => $context, 'objectid' => $subscription->id, 'relateduserid' => $user->id, 'other' => array('quoraid' => $quora->id, 'discussion' => $discussion->id));
     $event = \mod_quora\event\discussion_subscription_deleted::create($params);
     // Trigger and capturing the event.
     $sink = $this->redirectEvents();
     $event->trigger();
     $events = $sink->get_events();
     $this->assertCount(1, $events);
     $event = reset($events);
     // Without an invalid context.
     $params['context'] = \context_course::instance($course->id);
     $this->setExpectedException('coding_exception', 'Context level must be CONTEXT_MODULE.');
     \mod_quora\event\discussion_deleted::create($params);
     // Without the discussion.
     unset($params['discussion']);
     $this->setExpectedException('coding_exception', 'The \'discussion\' value must be set in other.');
     \mod_quora\event\discussion_deleted::create($params);
     // Without the quoraid.
     unset($params['quoraid']);
     $this->setExpectedException('coding_exception', 'The \'quoraid\' value must be set in other.');
     \mod_quora\event\discussion_deleted::create($params);
     // Without the relateduserid.
     unset($params['relateduserid']);
     $this->setExpectedException('coding_exception', 'The \'relateduserid\' value must be set in other.');
     \mod_quora\event\discussion_deleted::create($params);
 }
Beispiel #2
0
     print_error("cannotdeletepost", "quora", quora_go_back_to("discuss.php?d={$post->discussion}"));
 }
 if ($post->totalscore) {
     notice(get_string('couldnotdeleteratings', 'rating'), quora_go_back_to("discuss.php?d={$post->discussion}"));
 } else {
     if ($replycount && !has_capability('mod/quora:deleteanypost', $modcontext)) {
         print_error("couldnotdeletereplies", "quora", quora_go_back_to("discuss.php?d={$post->discussion}"));
     } else {
         if (!$post->parent) {
             // post is a discussion topic as well, so delete discussion
             if ($quora->type == 'single') {
                 notice("Sorry, but you are not allowed to delete that discussion!", quora_go_back_to("discuss.php?d={$post->discussion}"));
             }
             quora_delete_discussion($discussion, false, $course, $cm, $quora);
             $params = array('objectid' => $discussion->id, 'context' => $modcontext, 'other' => array('quoraid' => $quora->id));
             $event = \mod_quora\event\discussion_deleted::create($params);
             $event->add_record_snapshot('quora_discussions', $discussion);
             $event->trigger();
             redirect("view.php?f={$discussion->quora}");
         } else {
             if (quora_delete_post($post, has_capability('mod/quora:deleteanypost', $modcontext), $course, $cm, $quora)) {
                 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={$post->discussion}";
                 }
                 $params = array('context' => $modcontext, 'objectid' => $post->id, 'other' => array('discussionid' => $discussion->id, 'quoraid' => $quora->id, 'quoratype' => $quora->type));
                 if ($post->userid !== $USER->id) {