Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
rdebleu committed Mar 28, 2024
1 parent 76673fb commit 6061210
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 24 deletions.
1 change: 0 additions & 1 deletion classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {

/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
Expand Down
7 changes: 4 additions & 3 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class enrol_auto_plugin extends enrol_plugin {

/**
* Returns optional enrolment information icons.
*
Expand Down Expand Up @@ -151,9 +150,11 @@ public function try_autoenrol(stdClass $instance) {
}

// Plugin is enabled?
if (!enrol_is_enabled('auto') ||
if (
!enrol_is_enabled('auto') ||
$instance->status != ENROL_INSTANCE_ENABLED ||
($instance->enrolenddate > 0 && time() > $instance->enrolenddate)) {
($instance->enrolenddate > 0 && time() > $instance->enrolenddate)
) {
return false;
}

Expand Down
36 changes: 26 additions & 10 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,40 @@
defined('MOODLE_INTERNAL') || die();

if ($ADMIN->fulltree) {
require_once($CFG->dirroot . '/enrol/auto/lib.php');

require_once($CFG->dirroot.'/enrol/auto/lib.php');
$settings->add(new admin_setting_heading(
'enrol_auto_defaults',
get_string('enrolinstancedefaults', 'admin'),
get_string('enrolinstancedefaults_desc', 'admin')
));

$settings->add(new admin_setting_heading('enrol_auto_defaults',
get_string('enrolinstancedefaults', 'admin'), get_string('enrolinstancedefaults_desc', 'admin')));

$settings->add(new admin_setting_configcheckbox('enrol_auto/defaultenrol',
get_string('defaultenrol', 'enrol'), get_string('defaultenrol_desc', 'enrol'), 1));
$settings->add(new admin_setting_configcheckbox(
'enrol_auto/defaultenrol',
get_string('defaultenrol', 'enrol'),
get_string('defaultenrol_desc', 'enrol'),
1
));

$options = [ENROL_INSTANCE_ENABLED => get_string('yes'), ENROL_INSTANCE_DISABLED => get_string('no')];
$settings->add(new admin_setting_configselect('enrol_auto/status',
get_string('status', 'enrol_auto'), get_string('status_desc', 'enrol_auto'), ENROL_INSTANCE_DISABLED, $options));
$settings->add(new admin_setting_configselect(
'enrol_auto/status',
get_string('status', 'enrol_auto'),
get_string('status_desc', 'enrol_auto'),
ENROL_INSTANCE_DISABLED,
$options
));

if (!during_initial_install()) {
$options = get_default_enrol_roles(context_system::instance());
$student = get_archetype_roles('student');
$student = reset($student);
$settings->add(new admin_setting_configselect('enrol_auto/roleid',
get_string('defaultrole', 'enrol_auto'), get_string('defaultrole_desc', 'enrol_auto'), $student->id, $options));
$settings->add(new admin_setting_configselect(
'enrol_auto/roleid',
get_string('defaultrole', 'enrol_auto'),
get_string('defaultrole_desc', 'enrol_auto'),
$student->id,
$options
));
}
}
41 changes: 32 additions & 9 deletions tests/auto_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
* @coversDefaultClass \enrol_auto
*/
final class auto_test extends \advanced_testcase {

/** @var stdClass Instance. */
private $instance;

Expand Down Expand Up @@ -201,17 +200,29 @@ public function test_backup(): void {
$generator = $this->getDataGenerator();
$user = $generator->create_user();
$this->plugin->enrol_user($this->instance, $user->id, 5);
$bc = new \backup_controller(\backup::TYPE_1COURSE, $this->course->id, \backup::FORMAT_MOODLE, \backup::INTERACTIVE_NO,
\backup::MODE_GENERAL, 2);
$bc = new \backup_controller(
\backup::TYPE_1COURSE,
$this->course->id,
\backup::FORMAT_MOODLE,
\backup::INTERACTIVE_NO,
\backup::MODE_GENERAL,
2
);
$bc->execute_plan();
$results = $bc->get_results();
$file = $results['backup_destination'];
$fp = get_file_packer('application/vnd.moodle.backup');
$filepath = $CFG->dataroot . '/temp/backup/test-restore-course-event';
$file->extract_to_pathname($fp, $filepath);
$bc->destroy();
$rc = new \restore_controller('test-restore-course-event', $this->course->id, \backup::INTERACTIVE_NO,
\backup::MODE_GENERAL, 2, \backup::TARGET_NEW_COURSE);
$rc = new \restore_controller(
'test-restore-course-event',
$this->course->id,
\backup::INTERACTIVE_NO,
\backup::MODE_GENERAL,
2,
\backup::TARGET_NEW_COURSE
);
$rc->execute_precheck();
$rc->execute_plan();
$newid = $rc->get_courseid();
Expand All @@ -225,17 +236,29 @@ public function test_backup(): void {
$enrolments = $manager->get_user_enrolments($user->id);
$this->assertCount(2, $enrolments);
$this->assertCount(5, $manager->get_enrolment_instance_names());
$bc = new \backup_controller(\backup::TYPE_1COURSE, $this->course->id, \backup::FORMAT_MOODLE, \backup::INTERACTIVE_NO,
\backup::MODE_GENERAL, 2);
$bc = new \backup_controller(
\backup::TYPE_1COURSE,
$this->course->id,
\backup::FORMAT_MOODLE,
\backup::INTERACTIVE_NO,
\backup::MODE_GENERAL,
2
);
$bc->execute_plan();
$results = $bc->get_results();
$file = $results['backup_destination'];
$fp = get_file_packer('application/vnd.moodle.backup');
$filepath = $CFG->dataroot . '/temp/backup/test-restore-course-event';
$file->extract_to_pathname($fp, $filepath);
$bc->destroy();
$rc = new \restore_controller('test-restore-course-event', $newid, \backup::INTERACTIVE_NO,
\backup::MODE_GENERAL, 2, \backup::TARGET_EXISTING_ADDING);
$rc = new \restore_controller(
'test-restore-course-event',
$newid,
\backup::INTERACTIVE_NO,
\backup::MODE_GENERAL,
2,
\backup::TARGET_EXISTING_ADDING
);
$rc->execute_precheck();
$rc->execute_plan();
$rc->destroy();
Expand Down
1 change: 0 additions & 1 deletion tests/privacy/privacy_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
* @coversDefaultClass \enrol_auto\privacy\provider
*/
final class privacy_test extends provider_testcase {

/**
* Test returning metadata.
* @covers \enrol_auto\privacy\provider
Expand Down

0 comments on commit 6061210

Please sign in to comment.