Skip to content

Commit

Permalink
MDL-77230 mod_feedback: Coding style violation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Feb 23, 2023
1 parent 42fcac2 commit baae0cd
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions mod/feedback/tests/external/external_test.php
Expand Up @@ -31,7 +31,6 @@
use feedback_item_multichoice;
use mod_feedback_external;
use moodle_exception;
use required_capability_exception;

defined('MOODLE_INTERNAL') || die();

Expand All @@ -52,6 +51,17 @@
*/
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
*/
Expand Down Expand Up @@ -123,12 +133,14 @@ public function test_mod_feedback_get_feedbacks_by_courses() {
// 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);
Expand Down Expand Up @@ -274,7 +286,7 @@ public function test_get_feedback_access_information_teacher() {
*/
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);
}
/**
Expand All @@ -283,7 +295,7 @@ public function test_view_feedback_invalid_id() {
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);
}
/**
Expand All @@ -294,7 +306,7 @@ public function test_view_feedback_no_capabilities() {
// 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);
}
/**
Expand Down Expand Up @@ -965,7 +977,7 @@ public function test_get_finished_responses() {
*/
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);
}

Expand All @@ -974,7 +986,7 @@ public function test_get_non_respondents_no_permissions() {
*/
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);
}
Expand Down Expand Up @@ -1157,7 +1169,7 @@ public function test_get_last_completed_anonymous_not_completed() {
$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);
}

Expand All @@ -1184,7 +1196,7 @@ public function test_get_last_completed_anonymous_completed() {
$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);
}

Expand Down Expand Up @@ -1227,7 +1239,7 @@ public function test_get_last_completed_not_anonymous_not_completed() {
$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);
}

Expand All @@ -1253,7 +1265,7 @@ public function test_get_feedback_access_information_for_site_feedback() {
// 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);
}

Expand All @@ -1277,7 +1289,7 @@ public function test_get_feedback_access_information_for_site_feedback_mapped()
$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);
}
Expand Down

0 comments on commit baae0cd

Please sign in to comment.