Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
rdebleu committed Apr 2, 2024
1 parent acc63c0 commit b381c67
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 31 deletions.
12 changes: 6 additions & 6 deletions lang/en/enrol_coursecompleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@

$string['aftercourse'] = 'After completing course: {$a}';
$string['cachedef_compcourses'] = 'Enrolment on course completion cache';
$string['coursecompleted:config'] = 'Configure enrol coursecompletion instances';
$string['coursecompleted:manage'] = 'Manage enrolled users';
$string['coursecompleted:enrolpast'] = 'Enrol users who completed courses in the past';
$string['coursecompleted:unenrol'] = 'Unenrol users from course';
$string['coursecompleted:unenrolself'] = 'Unenrol self from the course';
$string['compcourse'] = 'Completed course';
$string['compcourse_help'] = 'Which course have to be completed.';
$string['confirmbulkdeleteenrolment'] = 'Are you sure you want to delete these user enrolments?';
$string['confirmbulkediteenrolment'] = 'Are you sure you want to change these user enrolments?';
$string['coursecompleted:config'] = 'Configure enrol coursecompletion instances';
$string['coursecompleted:enrolpast'] = 'Enrol users who completed courses in the past';
$string['coursecompleted:manage'] = 'Manage enrolled users';
$string['coursecompleted:unenrol'] = 'Unenrol users from course';
$string['coursecompleted:unenrolself'] = 'Unenrol self from the course';
$string['customwelcome'] = 'Custom welcome message';
$string['customwelcome_help'] = 'A custom welcome message may be added as plain text or Moodle-auto format, including HTML tags and multi-lang tags.
Expand Down Expand Up @@ -63,9 +63,9 @@
$string['status_link'] = 'enrol/coursecompleted';
$string['svglearnpath'] = 'Display learning path';
$string['svglearnpath_help'] = 'Display (possible) learning path using svg icons.';
$string['unenrolusers'] = 'Unenrol users';
$string['uponcompleting'] = 'Upon completing course {$a}';
$string['usersenrolled'] = '{$a} Users enrolled';
$string['unenrolusers'] = 'Unenrol users';
$string['welcome'] = 'Send course welcome message';
$string['welcome_help'] = 'When a user is enrolled in a course by completing another course, a welcome message email may be sent.';
$string['welcometocourse'] = 'Welcome to {$a->coursename}!
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
<file>renderer.php</file>
<file>rsslib.php</file>
</include>
<exclude>
<directory suffix=".php">classes/form</directory>
</exclude>
</coverage>

</phpunit>
12 changes: 12 additions & 0 deletions tests/coverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,19 @@

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

/**
* Unit tests for the coursecompleted enrolment.
*
* @package enrol_coursecompleted
* @copyright 2017 eWallah (www.eWallah.net)
* @author Renaat Debleu <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
return new class extends phpunit_coverage_info {
/** @var array The list of folders relative to the plugin root to include in coverage generation. */
protected $includelistfolders = ['classes'];
/** @var array The list of folders relative to the plugin root to exclude in coverage generation. */
protected $excludelistfolders = ['classes/form'];
/** @var array The list of files relative to the plugin root to exclude in coverage generation. */
protected $excludelistfiles = ['lib.php'];
};
52 changes: 27 additions & 25 deletions tests/enrol_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
defined('MOODLE_INTERNAL') || die();

global $CFG;
require_once($CFG->libdir . '/formslib.php');
require_once($CFG->dirroot . '/enrol/locallib.php');
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
Expand Down Expand Up @@ -367,7 +366,7 @@ public function test_form(): void {
$page->set_pagelayout('standard');
$page->set_pagetype('course-view');
$page->set_url('/enrol/coursecompleted/manage.php?enrolid=' . $this->instance->id);
$form = new temp_coursecompleted_form();
$form = $this->tempform();
$mform = $form->getform();
$this->plugin->edit_instance_form($this->instance, $mform, $context);
$this->assertStringContainsString('Required field', $mform->getReqHTML());
Expand Down Expand Up @@ -505,31 +504,34 @@ public function test_deletedcourse(): void {
$observer = new \enrol_coursecompleted_observer();
$observer->coursedeleted($event);
}
}

/**
* Form object to be used in test case.
*
* @package enrol_coursecompleted
* @copyright 2017 eWallah (www.eWallah.net)
* @author Renaat Debleu <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class temp_coursecompleted_form extends \moodleform {
/**
* Form definition.
*/
public function definition() {
// No definition required.
}
/**
* Returns form reference
* @return MoodleQuickForm
* Test form.
* @covers \enrol_coursecompleted_plugin
* @return \moodleform
*/
public function getform() {
$mform = $this->_form;
// Set submitted flag, to simulate submission.
$mform->_flagSubmitted = true;
return $mform;
public function tempform() {
global $CFG;
require_once($CFG->libdir . '/formslib.php');

// Test form.
return new class tempform extends \moodleform {
/**
* Form definition.
*/
public function definition() {
// No definition required.
}
/**
* Returns form reference
* @return MoodleQuickForm
*/
public function getform() {
$mform = $this->_form;
// Set submitted flag, to simulate submission.
$mform->_flagSubmitted = true;
return $mform;
}
};
}
}

0 comments on commit b381c67

Please sign in to comment.