Skip to content

Commit

Permalink
Merge pull request #62 from lucaboesch/php81compatibility
Browse files Browse the repository at this point in the history
Check PHP 8.1 compatibility and coding style.
  • Loading branch information
danmarsden authored Oct 30, 2023
2 parents 63ef3f4 + 587e4c3 commit bc4163c
Show file tree
Hide file tree
Showing 19 changed files with 74 additions and 67 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions backup/moodle2/backup_subcourse_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
4 changes: 1 addition & 3 deletions backup/moodle2/restore_subcourse_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 0 additions & 2 deletions classes/event/course_module_instance_list_viewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

namespace mod_subcourse\event;

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

/**
* Represents the "course module instance list viewed" event.
*
Expand Down
2 changes: 0 additions & 2 deletions classes/event/course_module_viewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

namespace mod_subcourse\event;

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

/**
* Represents the "course module viewed" event.
*
Expand Down
2 changes: 0 additions & 2 deletions classes/event/subcourse_grades_fetched.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

namespace mod_subcourse\event;

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

/**
* Represents the "grades fetched" event.
*
Expand Down
2 changes: 0 additions & 2 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

namespace mod_subcourse\privacy;

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

/**
* Privacy API implementation for the Subcourse plugin.
*
Expand Down
2 changes: 0 additions & 2 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
4 changes: 1 addition & 3 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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']);
Expand Down
2 changes: 1 addition & 1 deletion mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 6 additions & 4 deletions tests/behat/auto_fetch_grades.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand All @@ -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 | 01000 |
Expand All @@ -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 | 01000 |
Expand All @@ -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 | 01000 |
11 changes: 5 additions & 6 deletions tests/behat/completion_course.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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
Expand All @@ -48,16 +48,15 @@ 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"
# Running completion task just after clicking sometimes fail, as record should be created before the task runs.
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
Expand Down
22 changes: 11 additions & 11 deletions tests/behat/course_page_display.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"

Expand All @@ -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"
25 changes: 17 additions & 8 deletions tests/behat/fetch_percentage_grades.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down Expand Up @@ -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 %) |
Expand All @@ -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 |
Expand All @@ -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- |
Expand All @@ -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 |
Expand All @@ -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- |
Expand Down
6 changes: 4 additions & 2 deletions tests/behat/hidden_grades.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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- |
Expand Down Expand Up @@ -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- |
Expand Down
7 changes: 4 additions & 3 deletions tests/behat/instant_redirect.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Loading

0 comments on commit bc4163c

Please sign in to comment.