This commit is contained in:
Jun Pataleta 2024-02-05 16:07:03 +08:00
commit 326c5ab3b1
No known key found for this signature in database
GPG Key ID: F83510526D99E2C7
2 changed files with 19 additions and 8 deletions

View File

@ -111,9 +111,9 @@ class enrol_manual_external extends external_api {
}
}
if (empty($instance)) {
$errorparams = new stdClass();
$errorparams->courseid = $enrolment['courseid'];
throw new moodle_exception('wsnoinstance', 'enrol_manual', $errorparams);
$errorparams = new stdClass();
$errorparams->courseid = $enrolment['courseid'];
throw new moodle_exception('wsnoinstance', 'enrol_manual', '', $errorparams);
}
// Check that the plugin accept enrolment (it should always the case, it's hard coded in the plugin).
@ -195,7 +195,7 @@ class enrol_manual_external extends external_api {
require_capability('enrol/manual:unenrol', $context);
$instance = $DB->get_record('enrol', array('courseid' => $enrolment['courseid'], 'enrol' => 'manual'));
if (!$instance) {
throw new moodle_exception('wsnoinstance', 'enrol_manual', $enrolment);
throw new moodle_exception('wsnoinstance', 'enrol_manual', '', $enrolment);
}
$user = $DB->get_record('user', array('id' => $enrolment['userid']));
if (!$user) {

View File

@ -116,6 +116,10 @@ class externallib_test extends externallib_advanced_testcase {
$this->fail('Exception expected if course does not have manual instance');
} catch (\moodle_exception $e) {
$this->assertSame('wsnoinstance', $e->errorcode);
$this->assertSame(
"Manual enrolment plugin instance doesn't exist or is disabled for the course (id = {$course2->id})",
$e->getMessage()
);
}
}
@ -274,14 +278,21 @@ class externallib_test extends externallib_advanced_testcase {
} catch (\Exception $ex) {
$this->assertTrue($ex instanceof \invalid_parameter_exception);
}
$DB->delete_records('enrol', array('id' => $enrolinstance->id));
// Call for course without manual instance.
$DB->delete_records('user_enrolments');
$DB->delete_records('enrol', ['courseid' => $course->id]);
try {
enrol_manual_external::unenrol_users(array(
array('userid' => $student->id + 1, 'courseid' => $course->id),
));
$this->fail('Exception expected: invalid student id');
} catch (\Exception $ex) {
$this->assertTrue($ex instanceof \moodle_exception);
$this->fail('Exception expected if course does not have manual instance');
} catch (\moodle_exception $e) {
$this->assertSame('wsnoinstance', $e->errorcode);
$this->assertSame(
"Manual enrolment plugin instance doesn't exist or is disabled for the course (id = {$course->id})",
$e->getMessage()
);
}
}
}