/** * Test the folder updated event. * * There is no external API for updating a folder, so the unit test will simply create * and trigger the event and ensure the legacy log data is returned as expected. */ public function test_folder_updated() { $this->setAdminUser(); $course = $this->getDataGenerator()->create_course(); $folder = $this->getDataGenerator()->create_module('folder', array('course' => $course->id)); $params = array('context' => context_module::instance($folder->cmid), 'objectid' => $folder->id, 'courseid' => $course->id); $event = \mod_folder\event\folder_updated::create($params); $event->add_record_snapshot('folder', $folder); // 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_folder\\event\\folder_updated', $event); $this->assertEquals(context_module::instance($folder->cmid), $event->get_context()); $this->assertEquals($folder->id, $event->objectid); $expected = array($course->id, 'folder', 'edit', 'edit.php?id=' . $folder->cmid, $folder->id, $folder->cmid); $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); }
$redirecturl = new moodle_url('/mod/folder/view.php', array('id' => $cm->id)); } if ($mform->is_cancelled()) { redirect($redirecturl); } else if ($formdata = $mform->get_data()) { $formdata = file_postupdate_standard_filemanager($formdata, 'files', $options, $context, 'mod_folder', 'content', 0); $DB->set_field('folder', 'revision', $folder->revision+1, array('id'=>$folder->id)); // Update the variable of the folder revision so we can pass it as an accurate snapshot later. $folder->revision = $folder->revision + 1; $params = array( 'context' => $context, 'objectid' => $folder->id ); $event = \mod_folder\event\folder_updated::create($params); $event->add_record_snapshot('folder', $folder); $event->trigger(); redirect($redirecturl); } echo $OUTPUT->header(); echo $OUTPUT->heading(format_string($folder->name)); echo $OUTPUT->box_start('generalbox foldertree'); $mform->display(); echo $OUTPUT->box_end(); echo $OUTPUT->footer();