Skip to content

Commit

Permalink
MDL-45229 event: Validate sectionnum in course_section_updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederic Massart committed Apr 28, 2014
1 parent 566fd05 commit be9fb21
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion course/tests/courselib_test.php
Expand Up @@ -1759,7 +1759,10 @@ public function test_course_section_updated_event() {
array(
'objectid' => $section->id,
'courseid' => $course->id,
'context' => context_course::instance($course->id)
'context' => context_course::instance($course->id),
'other' => array(
'sectionnum' => $section->section
)
)
);
$event->add_record_snapshot('course_sections', $section);
Expand All @@ -1776,6 +1779,7 @@ public function test_course_section_updated_event() {
$this->assertEquals($section->id, $event->objectid);
$this->assertEquals($course->id, $event->courseid);
$this->assertEquals($coursecontext->id, $event->contextid);
$this->assertEquals($section->section, $event->other['sectionnum']);
$expecteddesc = 'Course ' . $event->courseid . ' section ' . $event->other['sectionnum'] . ' updated by user ' . $event->userid;
$this->assertEquals($expecteddesc, $event->get_description());
$url = new moodle_url('/course/editsection.php', array('id' => $event->objectid));
Expand Down
13 changes: 13 additions & 0 deletions lib/classes/event/course_section_updated.php
Expand Up @@ -89,4 +89,17 @@ protected function get_legacy_logdata() {
$sectiondata = $this->get_record_snapshot('course_sections', $this->objectid);
return array($this->courseid, 'course', 'editsection', 'editsection.php?id=' . $this->objectid, $sectiondata->section);
}

/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->other['sectionnum'])) {
throw new \coding_exception('The sectionnum must be set in $other');
}
}
}

0 comments on commit be9fb21

Please sign in to comment.