/** * There is no api involved so the best we can do is test legacy data by triggering event manually. */ public function test_submission_updated_event() { $this->resetAfterTest(); $this->setAdminUser(); $user = $this->getDataGenerator()->create_user(); $submissionid = 48; $event = \mod_teamwork\event\submission_updated::create(array('objectid' => $submissionid, 'context' => $this->context, 'courseid' => $this->course->id, 'relateduserid' => $user->id, 'other' => array('submissiontitle' => 'The submission title'))); // Trigger and capture the event. $sink = $this->redirectEvents(); $event->trigger(); $events = $sink->get_events(); $event = reset($events); // Check that the legacy log data is valid. $expected = array($this->course->id, 'teamwork', 'update submission', 'submission.php?cmid=' . $this->cm->id . '&id=' . $submissionid, $submissionid, $this->cm->id); $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); $sink->close(); }
} else { if (empty($formdata->id) or empty($submission->id) or $formdata->id != $submission->id) { throw new moodle_exception('err_submissionid', 'teamwork'); } } $params['objectid'] = $submission->id; // save and relink embedded images and save attachments $formdata = file_postupdate_standard_editor($formdata, 'content', $contentopts, $teamwork->context, 'mod_teamwork', 'submission_content', $submission->id); $formdata = file_postupdate_standard_filemanager($formdata, 'attachment', $attachmentopts, $teamwork->context, 'mod_teamwork', 'submission_attachment', $submission->id); if (empty($formdata->attachment)) { // explicit cast to zero integer $formdata->attachment = 0; } // store the updated values or re-save the new submission (re-saving needed because URLs are now rewritten) $DB->update_record('teamwork_submissions', $formdata); $event = \mod_teamwork\event\submission_updated::create($params); $event->add_record_snapshot('teamwork', $teamworkrecord); $event->trigger(); // send submitted content for plagiarism detection $fs = get_file_storage(); $files = $fs->get_area_files($teamwork->context->id, 'mod_teamwork', 'submission_attachment', $submission->id); $params['other']['content'] = $formdata->content; $params['other']['pathnamehashes'] = array_keys($files); $event = \mod_teamwork\event\assessable_uploaded::create($params); $event->set_legacy_logdata($logdata); $event->trigger(); $rtn_url = new moodle_url("project.php", array('w' => $formdata->teamworkid, 'instance' => $formdata->instance)); redirect($rtn_url); } } else { echo $output->render($teamwork->prepare_submission($submission, true));