MDL-58138 completion: mform wants 0-based indexes for arrays

This commit is contained in:
Marina Glancy 2017-04-20 13:42:07 +08:00
parent 6f9f15d1ad
commit 6c48135896
2 changed files with 8 additions and 4 deletions

View File

@ -100,9 +100,11 @@ class core_completion_bulkedit_form extends core_completion_edit_base_form {
$mform = $this->_form;
$idx = 0;
foreach ($this->cms as $cm) {
$mform->addElement('hidden', 'cmid['.$cm->id.']', $cm->id);
$mform->setType('cmid['.$cm->id.']', PARAM_INT);
$mform->addElement('hidden', 'cmid['.$idx.']', $cm->id);
$mform->setType('cmid['.$idx.']', PARAM_INT);
$idx++;
}
parent::definition();

View File

@ -254,11 +254,13 @@ class core_completion_bulk_update_testcase extends advanced_testcase {
$cmrec = $DB->get_record('course_modules', ['id' => $cm->id]);
$instancerec = $DB->get_record($cm->modname, ['id' => $cm->instance]);
foreach ($cmdata as $key => $value) {
$this->assertEquals($value, $cmrec->$key);
$this->assertEquals($value, $cmrec->$key, 'Error asserting that value for the field ' . $key.' ' .
$cmrec->$key . ' matches expected value ' . $value);
}
if ($instancedata) {
foreach ($instancedata[$cnt] as $key => $value) {
$this->assertEquals($value, $instancerec->$key);
$this->assertEquals($value, $instancerec->$key, 'Error asserting that value for the field ' . $key . ' '.
$instancerec->$key . ' matches expected value ' . $value);
}
}
$cnt++;