MDL-77230 mod_feedback: Coding style violation fixes

This commit is contained in:
Andrew Nicols 2023-02-23 10:05:27 +08:00
parent 42fcac25e2
commit baae0cd2d6

View File

@ -31,7 +31,6 @@ use externallib_advanced_testcase;
use feedback_item_multichoice;
use mod_feedback_external;
use moodle_exception;
use required_capability_exception;
defined('MOODLE_INTERNAL') || die();
@ -52,6 +51,17 @@ require_once($CFG->dirroot . '/mod/feedback/lib.php');
*/
class external_test extends externallib_advanced_testcase {
// TODO These should be removed.
// Testcase classes should not have any properties or store state.
protected $course;
protected $feedback;
protected $context;
protected $cm;
protected $student;
protected $teacher;
protected $studentrole;
protected $teacherrole;
/**
* Set up for every test
*/
@ -123,12 +133,14 @@ class external_test extends externallib_advanced_testcase {
// Execute real Moodle enrolment as we'll call unenrol() method on the instance later.
$enrol = enrol_get_plugin('manual');
$enrolinstances = enrol_get_instances($course2->id, true);
$instance2 = (object) [];
foreach ($enrolinstances as $courseenrolinstance) {
if ($courseenrolinstance->enrol == "manual") {
$instance2 = $courseenrolinstance;
break;
}
}
$enrol->enrol_user($instance2, $this->student->id, $this->studentrole->id);
self::setUser($this->student);
@ -274,7 +286,7 @@ class external_test extends externallib_advanced_testcase {
*/
public function test_view_feedback_invalid_id() {
// Test invalid instance id.
$this->expectException('\moodle_exception');
$this->expectException(moodle_exception::class);
mod_feedback_external::view_feedback(0);
}
/**
@ -283,7 +295,7 @@ class external_test extends externallib_advanced_testcase {
public function test_view_feedback_not_enrolled_user() {
$usernotenrolled = self::getDataGenerator()->create_user();
$this->setUser($usernotenrolled);
$this->expectException('\moodle_exception');
$this->expectException(moodle_exception::class);
mod_feedback_external::view_feedback(0);
}
/**
@ -294,7 +306,7 @@ class external_test extends externallib_advanced_testcase {
// We need a explicit prohibit since this capability is allowed for students by default.
assign_capability('mod/feedback:view', CAP_PROHIBIT, $this->studentrole->id, $this->context->id);
accesslib_clear_all_caches_for_unit_testing();
$this->expectException('\moodle_exception');
$this->expectException(moodle_exception::class);
mod_feedback_external::view_feedback(0);
}
/**
@ -965,7 +977,7 @@ class external_test extends externallib_advanced_testcase {
*/
public function test_get_non_respondents_no_permissions() {
$this->setUser($this->student);
$this->expectException('\moodle_exception');
$this->expectException(moodle_exception::class);
mod_feedback_external::get_non_respondents($this->feedback->id);
}
@ -974,7 +986,7 @@ class external_test extends externallib_advanced_testcase {
*/
public function test_get_non_respondents_from_anonymous_feedback() {
$this->setUser($this->student);
$this->expectException('\moodle_exception');
$this->expectException(moodle_exception::class);
$this->expectExceptionMessage(get_string('anonymous', 'feedback'));
mod_feedback_external::get_non_respondents($this->feedback->id);
}
@ -1157,7 +1169,7 @@ class external_test extends externallib_advanced_testcase {
$this->setUser($this->student);
$this->expectExceptionMessage(get_string('anonymous', 'feedback'));
$this->expectException('\moodle_exception');
$this->expectException(moodle_exception::class);
mod_feedback_external::get_last_completed($this->feedback->id);
}
@ -1184,7 +1196,7 @@ class external_test extends externallib_advanced_testcase {
$this->setUser($this->student);
$this->expectExceptionMessage(get_string('anonymous', 'feedback'));
$this->expectException('\moodle_exception');
$this->expectException(moodle_exception::class);
mod_feedback_external::get_last_completed($this->feedback->id);
}
@ -1227,7 +1239,7 @@ class external_test extends externallib_advanced_testcase {
$this->setUser($this->student);
$this->expectExceptionMessage(get_string('not_completed_yet', 'feedback'));
$this->expectException('\moodle_exception');
$this->expectException(moodle_exception::class);
mod_feedback_external::get_last_completed($this->feedback->id);
}
@ -1253,7 +1265,7 @@ class external_test extends externallib_advanced_testcase {
// Access the site feedback via course where I'm not enrolled.
$othercourse = $this->getDataGenerator()->create_course();
$this->expectException('\moodle_exception');
$this->expectException(moodle_exception::class);
mod_feedback_external::get_feedback_access_information($sitefeedback->id, $othercourse->id);
}
@ -1277,7 +1289,7 @@ class external_test extends externallib_advanced_testcase {
$othercourse = $this->getDataGenerator()->create_course();
$this->getDataGenerator()->enrol_user($this->student->id, $othercourse->id, $this->studentrole->id, 'manual');
$this->expectException('\moodle_exception');
$this->expectException(moodle_exception::class);
$this->expectExceptionMessage(get_string('cannotaccess', 'mod_feedback'));
mod_feedback_external::get_feedback_access_information($sitefeedback->id, $othercourse->id);
}