diff --git a/.github/workflows/moodle-ci.yml b/.github/workflows/moodle-ci.yml index 4836b2c..3198193 100644 --- a/.github/workflows/moodle-ci.yml +++ b/.github/workflows/moodle-ci.yml @@ -31,17 +31,17 @@ jobs: fail-fast: false matrix: include: - - php: '8.0' + - php: '8.1' + moodle-branch: 'MOODLE_401_STABLE' + database: mariadb + - php: '8.1' moodle-branch: 'MOODLE_401_STABLE' database: pgsql - php: '8.0' - moodle-branch: 'MOODLE_311_STABLE' - database: mariadb - - php: '7.4' - moodle-branch: 'MOODLE_310_STABLE' + moodle-branch: 'MOODLE_401_STABLE' database: mariadb - - php: '7.3' - moodle-branch: 'MOODLE_39_STABLE' + - php: '8.0' + moodle-branch: 'MOODLE_401_STABLE' database: pgsql steps: diff --git a/backup/moodle2/backup_subcourse_stepslib.php b/backup/moodle2/backup_subcourse_stepslib.php index a9f1171..193539b 100644 --- a/backup/moodle2/backup_subcourse_stepslib.php +++ b/backup/moodle2/backup_subcourse_stepslib.php @@ -23,8 +23,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -defined('MOODLE_INTERNAL') || die(); - /** * Defines the complete subcourse structure for backup * diff --git a/backup/moodle2/restore_subcourse_stepslib.php b/backup/moodle2/restore_subcourse_stepslib.php index fa00697..dd54bd0 100644 --- a/backup/moodle2/restore_subcourse_stepslib.php +++ b/backup/moodle2/restore_subcourse_stepslib.php @@ -23,8 +23,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -defined('MOODLE_INTERNAL') || die(); - /** * Structure step to restore one subcourse activity * @@ -60,7 +58,7 @@ protected function process_subcourse($data) { $data->timefetched = 0; - if (!$this->task->is_samesite() or !$DB->record_exists('course', ['id' => $data->refcourse])) { + if (!$this->task->is_samesite() || !$DB->record_exists('course', ['id' => $data->refcourse])) { $data->refcourse = 0; } diff --git a/classes/event/course_module_instance_list_viewed.php b/classes/event/course_module_instance_list_viewed.php index 8f29b7f..f371067 100644 --- a/classes/event/course_module_instance_list_viewed.php +++ b/classes/event/course_module_instance_list_viewed.php @@ -25,8 +25,6 @@ namespace mod_subcourse\event; -defined('MOODLE_INTERNAL') || die(); - /** * Represents the "course module instance list viewed" event. * diff --git a/classes/event/course_module_viewed.php b/classes/event/course_module_viewed.php index f77b68d..35cd14b 100644 --- a/classes/event/course_module_viewed.php +++ b/classes/event/course_module_viewed.php @@ -25,8 +25,6 @@ namespace mod_subcourse\event; -defined('MOODLE_INTERNAL') || die(); - /** * Represents the "course module viewed" event. * diff --git a/classes/event/subcourse_grades_fetched.php b/classes/event/subcourse_grades_fetched.php index 775a0b9..6c845a9 100644 --- a/classes/event/subcourse_grades_fetched.php +++ b/classes/event/subcourse_grades_fetched.php @@ -25,8 +25,6 @@ namespace mod_subcourse\event; -defined('MOODLE_INTERNAL') || die(); - /** * Represents the "grades fetched" event. * diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index 1943cc9..3ba9bff 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -25,8 +25,6 @@ namespace mod_subcourse\privacy; -defined('MOODLE_INTERNAL') || die(); - /** * Privacy API implementation for the Subcourse plugin. * diff --git a/db/upgrade.php b/db/upgrade.php index d6e3a11..bd161a3 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -23,8 +23,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -defined('MOODLE_INTERNAL') || die(); - /** * Performs upgrade of the database structure and data * diff --git a/lib.php b/lib.php index de2d2f3..3315043 100644 --- a/lib.php +++ b/lib.php @@ -22,8 +22,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -defined('MOODLE_INTERNAL') || die(); - /** * Returns the information if the module supports a feature * @@ -318,7 +316,7 @@ function mod_subcourse_cm_info_view(cm_info $cm) { $grades = grade_get_grades($cm->course, 'mod', 'subcourse', $cm->instance, $USER->id); $currentgrade = (empty($grades->items[0]->grades)) ? null : reset($grades->items[0]->grades); - if (($currentgrade !== null) and isset($currentgrade->grade) and !($currentgrade->hidden)) { + if (($currentgrade !== null) && isset($currentgrade->grade) && !($currentgrade->hidden)) { $strgrade = $currentgrade->str_grade; $html .= html_writer::tag('div', get_string('currentgrade', 'subcourse', $strgrade), ['class' => 'contentafterlink']); diff --git a/mod_form.php b/mod_form.php index 2a65e01..31edfce 100644 --- a/mod_form.php +++ b/mod_form.php @@ -95,7 +95,7 @@ public function definition() { } } - if (!empty($currentrefcourseid) and !$currentrefcourseavailable) { + if (!empty($currentrefcourseid) && !$currentrefcourseavailable) { // Currently referring to a course that is not available for us. // E.g. the admin has set up this Subcourse for the teacher or the teacher lost his role in the referred course etc. // Give them a chance to just keep such a reference. diff --git a/tests/behat/auto_fetch_grades.feature b/tests/behat/auto_fetch_grades.feature index b45330b..138a959 100644 --- a/tests/behat/auto_fetch_grades.feature +++ b/tests/behat/auto_fetch_grades.feature @@ -62,7 +62,7 @@ Feature: Grades are fetched automatically from the referenced course | Fetch grades from | RefCourse (R) | | Redirect to the referenced course | 0 | And I turn editing mode off - And I follow "Unit course 1" + And I am on the "Unit course 1" "subcourse activity" page logged in as teacher1 # # Upon creation, no grades are fetched yet. # @@ -72,8 +72,9 @@ Feature: Grades are fetched automatically from the referenced course # # After fetching, the grades are copied. # + And I am on "MainCourse" course homepage And I navigate to "View > User report" in the course gradebook - And I set the field "Select all or one user" to "Student 1" + And I click on "Student 1" in the "user" search widget And the following should exist in the "user-grade" table: | Grade item | Grade | Range | | Unit course 1 | 500 | 0–1000 | @@ -89,8 +90,9 @@ Feature: Grades are fetched automatically from the referenced course And I am on "MainCourse" course homepage And I navigate to "View > Grader report" in the course gradebook And I should not see "Student 2" + And I am on "MainCourse" course homepage And I navigate to "View > User report" in the course gradebook - And I set the field "Select all or one user" to "Student 1" + And I click on "Student 1" in the "user" search widget And the following should exist in the "user-grade" table: | Grade item | Grade | Range | | Unit course 1 | 750 | 0–1000 | @@ -102,7 +104,7 @@ Feature: Grades are fetched automatically from the referenced course | student2 | M | student | And I am on "MainCourse" course homepage And I navigate to "View > User report" in the course gradebook - And I set the field "Select all or one user" to "Student 2" + And I click on "Student 2" in the "user" search widget And the following should exist in the "user-grade" table: | Grade item | Grade | Range | | Unit course 1 | 250 | 0–1000 | diff --git a/tests/behat/completion_course.feature b/tests/behat/completion_course.feature index 303cdd9..a5afea5 100644 --- a/tests/behat/completion_course.feature +++ b/tests/behat/completion_course.feature @@ -19,9 +19,9 @@ Feature: Completing the referenced course can lead to completing the subcourse a | student1 | M | student | | teacher1 | R | editingteacher | | student1 | R | student | - And I log in as "teacher1" + And I enable "selfcompletion" "block" plugin # Create the subcourse instance. - And I am on "MainCourse" course homepage + When I am on the "MainCourse" course page logged in as "teacher1" And I turn editing mode on And I add a "Subcourse" to section "1" and I fill the form with: | Subcourse name | Unit course 1 | @@ -32,7 +32,7 @@ Feature: Completing the referenced course can lead to completing the subcourse a | Require course completed | 1 | | id_completionexpected_enabled | 1 | # Add the block to a the referenced course to allow students to manually complete it - And I am on "RefCourse" course homepage + And I am on "RefCourse" course homepage with editing mode on And I add the "Self completion" block And I navigate to "Course completion" in current page administration And I expand all fieldsets @@ -48,8 +48,7 @@ Feature: Completing the referenced course can lead to completing the subcourse a @javascript Scenario: Completing the referenced course leads to completing the subcourse - Given I log in as "student1" - And I am on "RefCourse" course homepage + Given I am on the "RefCourse" course page logged in as "student1" And I follow "Complete course" And I should see "Confirm self completion" And I press "Yes" @@ -57,7 +56,7 @@ Feature: Completing the referenced course can lead to completing the subcourse a And I wait "1" seconds When I run the scheduled task "core\task\completion_regular_task" And I am on "MainCourse" course homepage - Then "//img[contains(@alt, 'Completed: Unit course 1')]" "xpath_element" should exist in the "li.modtype_subcourse" "css_element" + Then the "Complete the activity" completion condition of "Unit course 1" is displayed as "done" And I log out And I log in as "teacher1" And I am on "MainCourse" course homepage diff --git a/tests/behat/course_page_display.feature b/tests/behat/course_page_display.feature index 7530b1c..25501ce 100644 --- a/tests/behat/course_page_display.feature +++ b/tests/behat/course_page_display.feature @@ -24,13 +24,13 @@ Feature: Progress and grade in referenced course can be displayed on the course # And I log in as "teacher1" And I am on "RefCourse" course homepage - And I navigate to "Edit settings" in current page administration + And I navigate to "Settings" in current page administration And I set the following fields to these values: | Enable completion tracking | Yes | And I press "Save and display" And I turn editing mode on - And I add a "Label" to section "1" and I fill the form with: - | Label text | Just a simple module to activate progress tracking | + And I add a "Text and media area" to section "1" and I fill the form with: + | Text | Just a simple module to activate progress tracking | And I turn editing mode off And I navigate to "Setup > Gradebook setup" in the course gradebook And I press "Add grade item" @@ -56,14 +56,14 @@ Feature: Progress and grade in referenced course can be displayed on the course | Display grade from referenced course on course page | 1 | And I turn editing mode off And I am on "MainCourse" course homepage - And I follow "Unit course 1" + And I am on the "Unit course 1" "subcourse activity" page logged in as teacher1 And I follow "Fetch grades now" And I log out When I log in as "student1" And I am on "MainCourse" course homepage - Then I should see "Progress:" in the "Unit course 1" "list_item" - And I should see "Current grade:" in the "Unit course 1" "list_item" - And I follow "Unit course 1" + Then I should see "Progress:" in the "[data-activityname='Unit course 1']" "css_element" + And I should see "Current grade:" in the "[data-activityname='Unit course 1']" "css_element" + And I am on the "Unit course 1" "subcourse activity" page logged in as student1 And I should see "Progress:" in the ".subcourseinfo-progress" "css_element" And I should see "Current grade:" in the ".subcourseinfo-grade" "css_element" @@ -79,13 +79,13 @@ Feature: Progress and grade in referenced course can be displayed on the course | Display grade from referenced course on course page | 0 | And I turn editing mode off And I am on "MainCourse" course homepage - And I follow "Unit course 1" + And I am on the "Unit course 1" "subcourse activity" page logged in as teacher1 And I follow "Fetch grades now" And I log out When I log in as "student1" And I am on "MainCourse" course homepage - Then I should not see "Progress:" in the "Unit course 1" "list_item" - And I should not see "Current grade:" in the "Unit course 1" "list_item" - And I follow "Unit course 1" + Then I should not see "Progress:" in the "[data-activityname='Unit course 1']" "css_element" + And I should not see "Current grade:" in the "[data-activityname='Unit course 1']" "css_element" + And I am on the "Unit course 1" "subcourse activity" page logged in as student1 And I should see "Progress:" in the ".subcourseinfo-progress" "css_element" And I should see "Current grade:" in the ".subcourseinfo-grade" "css_element" diff --git a/tests/behat/fetch_percentage_grades.feature b/tests/behat/fetch_percentage_grades.feature index bfeef78..71f1d9b 100644 --- a/tests/behat/fetch_percentage_grades.feature +++ b/tests/behat/fetch_percentage_grades.feature @@ -57,7 +57,11 @@ Feature: Grades can be fetched either a real values or as percentages And I press "Save changes" And I navigate to "Setup > Course grade settings" in the course gradebook And I set the field "Grade display type" to "Real (percentage)" + # + # Set also Grader report preferences to + # And I press "Save changes" + And I am on the "RefCourse" course page logged in as "teacher1" And I navigate to "View > Grader report" in the course gradebook And I turn editing mode on # @@ -89,16 +93,19 @@ Feature: Grades can be fetched either a real values or as percentages # # Explicitly exclude a grade from Student 3. # - And I follow "Single view for Student 3" - And I set the following fields to these values: - | Exclude for Manual item 3 | 1 | + And I navigate to "View > Single view" in the course gradebook + And I click on "Users" "link" in the ".page-toggler" "css_element" + And I click on "Student 3" in the "user" search widget + And I turn editing mode on + And I set the field "Exclude for Manual item 3" to "1" And I press "Save" And I should see "Grades were set for 1 item" - And I press "Continue" + And I press "Save" # # Check the grades in the referenced course. # And I navigate to "View > Grader report" in the course gradebook + And I turn editing mode off And the following should exist in the "user-grades" table: | Email address | -7- | | student1@example.com | 20.00 (66.67 %) | @@ -109,7 +116,7 @@ Feature: Grades can be fetched either a real values or as percentages @javascript Scenario: Grades are fetched as real values by default - Given I am on "MainCourse" course homepage + Given I am on the "MainCourse" course page logged in as "teacher1" And I turn editing mode on And I add a "Subcourse" to section "1" and I fill the form with: | Subcourse name | Unit course 1 | @@ -125,8 +132,9 @@ Feature: Grades can be fetched either a real values or as percentages | Grade display type | Real (percentage) | And I press "Save changes" And I am on "MainCourse" course homepage - And I follow "Unit course 1" + And I am on the "Unit course 1" "subcourse activity" page logged in as teacher1 When I follow "Fetch grades now" + And I am on "MainCourse" course homepage And I navigate to "View > Grader report" in the course gradebook Then the following should exist in the "user-grades" table: | Email address | -4- | @@ -138,7 +146,7 @@ Feature: Grades can be fetched either a real values or as percentages @javascript Scenario: Grades can be fetched as percentual values - Given I am on "MainCourse" course homepage + Given I am on the "MainCourse" course page logged in as "teacher1" And I turn editing mode on And I add a "Subcourse" to section "1" and I fill the form with: | Subcourse name | Unit course 1 | @@ -155,8 +163,9 @@ Feature: Grades can be fetched either a real values or as percentages | Grade display type | Real (percentage) | And I press "Save changes" And I am on "MainCourse" course homepage - And I follow "Unit course 1" + And I am on the "Unit course 1" "subcourse activity" page logged in as teacher1 When I follow "Fetch grades now" + And I am on the "MainCourse" course page logged in as "teacher1" And I navigate to "View > Grader report" in the course gradebook Then the following should exist in the "user-grades" table: | Email address | -4- | diff --git a/tests/behat/hidden_grades.feature b/tests/behat/hidden_grades.feature index 0c5a2da..431d264 100644 --- a/tests/behat/hidden_grades.feature +++ b/tests/behat/hidden_grades.feature @@ -55,8 +55,9 @@ Feature: Course final grades hidden in the referenced course are hidden in the t | Redirect to the referenced course | 0 | And I turn editing mode off And I am on "MainCourse" course homepage - And I follow "Unit course 1" + And I am on the "Unit course 1" "subcourse activity" page logged in as teacher1 When I follow "Fetch grades now" + And I am on "MainCourse" course homepage And I navigate to "View > Grader report" in the course gradebook Then the following should exist in the "user-grades" table: | Email address | -4- | @@ -97,8 +98,9 @@ Feature: Course final grades hidden in the referenced course are hidden in the t | Redirect to the referenced course | 0 | And I turn editing mode off And I am on "MainCourse" course homepage - And I follow "Unit course 1" + And I am on the "Unit course 1" "subcourse activity" page logged in as teacher1 When I follow "Fetch grades now" + And I am on "MainCourse" course homepage And I navigate to "View > Grader report" in the course gradebook Then the following should exist in the "user-grades" table: | Email address | -4- | diff --git a/tests/behat/instant_redirect.feature b/tests/behat/instant_redirect.feature index d2d7ca9..97e9511 100644 --- a/tests/behat/instant_redirect.feature +++ b/tests/behat/instant_redirect.feature @@ -55,7 +55,7 @@ Feature: Clicking the subcourse instance in the course outline may or may not re | Subcourse name | Unit course 1 | | Fetch grades from | RefCourse (R) | | Redirect to the referenced course | 1 | - And I follow "Unit course 1" + And I am on the "Unit course 1" "subcourse activity" page logged in as teacher1 Then I should see "Go to RefCourse" And I follow "RefCourse" And I should see "RefCourse" in the "page-header" "region" @@ -71,6 +71,7 @@ Feature: Clicking the subcourse instance in the course outline may or may not re | capability | permission | role | contextlevel | reference | | mod/subcourse:fetchgrades | Prevent | teacher | Activity module | subcourse1 | | mod/subcourse:fetchgrades | Prevent | editingteacher | Activity module | subcourse1 | - And I follow "Unit course 1" - And I follow "RefCourse" + And I am on "MainCourse" course homepage + And I am on the "Unit course 1" "subcourse activity" page logged in as teacher1 + And I am on "RefCourse" course homepage Then I should see "RefCourse" in the "page-header" "region" diff --git a/tests/locallib_test.php b/tests/locallib_test.php index 66a09cf..b685c4e 100644 --- a/tests/locallib_test.php +++ b/tests/locallib_test.php @@ -23,6 +23,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace mod_subcourse; + defined('MOODLE_INTERNAL') || die(); global $CFG; @@ -34,10 +36,12 @@ * @copyright 2020 David Mudrák * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_subcourse_locallib_testcase extends advanced_testcase { +class locallib_test extends \advanced_testcase { /** * Test that it is possible to fetch grades from the referenced course. + * + * @covers ::subcourse_grades_update */ public function test_subcourse_grades_update() { @@ -58,7 +62,7 @@ public function test_subcourse_grades_update() { $generator->enrol_user($student2->id, $refcourse->id, 'student'); // Give some grades in the referenced course. - $gi = new grade_item($generator->create_grade_item(['courseid' => $refcourse->id]), false); + $gi = new \grade_item($generator->create_grade_item(['courseid' => $refcourse->id]), false); $gi->update_final_grade($student1->id, 90, 'test'); $gi->update_final_grade($student2->id, 60, 'test'); $gi->force_regrading(); @@ -100,6 +104,8 @@ public function test_subcourse_grades_update() { /** * Test that calling {see subcourse_set_module_viewed()} does not raise errors. + * + * @covers ::subcourse_set_module_viewed */ public function test_subcourse_set_module_viewed() { @@ -116,7 +122,7 @@ public function test_subcourse_set_module_viewed() { $generator->enrol_user($student->id, $metacourse->id, 'student'); list($course, $cm) = get_course_and_cm_from_instance($subcourse->id, 'subcourse'); - $context = context_module::instance($cm->id); + $context = \context_module::instance($cm->id); subcourse_set_module_viewed($subcourse, $context, $course, $cm); } diff --git a/tests/output_mobile_test.php b/tests/output_mobile_test.php index 5f5bba1..a415f7a 100644 --- a/tests/output_mobile_test.php +++ b/tests/output_mobile_test.php @@ -21,6 +21,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace mod_subcourse; + defined('MOODLE_INTERNAL') || die(); global $CFG; @@ -34,10 +36,12 @@ * @copyright 2020 David Mudrák * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_subcourse_output_mobile_testcase extends advanced_testcase { +class output_mobile_test extends \advanced_testcase { /** * Test the return value of the main_view() method. + * + * @covers ::main_view */ public function test_main_view() { @@ -54,7 +58,7 @@ public function test_main_view() { $generator->enrol_user($student->id, $refcourse->id, 'student'); // Give some grades in the referenced course. - $gi = new grade_item($generator->create_grade_item(['courseid' => $refcourse->id]), false); + $gi = new \grade_item($generator->create_grade_item(['courseid' => $refcourse->id]), false); $gi->update_final_grade($student->id, 90, 'test'); $gi->force_regrading(); grade_regrade_final_grades($refcourse->id); diff --git a/view.php b/view.php index ccb9551..d9c7255 100644 --- a/view.php +++ b/view.php @@ -51,7 +51,7 @@ $refcourse = $DB->get_record('course', ['id' => $subcourse->refcourse], '*', IGNORE_MISSING); } -if ($fetchnow and $refcourse) { +if ($fetchnow && $refcourse) { require_sesskey(); require_capability('mod/subcourse:fetchgrades', $context); @@ -80,7 +80,7 @@ subcourse_set_module_viewed($subcourse, $context, $course, $cm); -if ($refcourse and !empty($subcourse->instantredirect)) { +if ($refcourse && !empty($subcourse->instantredirect)) { if (!has_capability('mod/subcourse:fetchgrades', $context)) { redirect(new moodle_url('/course/view.php', ['id' => $refcourse->id])); }