Skip to content

Compatibility with Moodle 4.5 #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Moodle Plugin CI

on: [pull_request]
on: [pull_request, push]

jobs:
test:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest

services:
postgres:
Expand All @@ -28,12 +28,24 @@ jobs:
fail-fast: false
matrix:
include:
- php: '8.3'
moodle-branch: 'MOODLE_405_STABLE'
database: 'pgsql'
- php: '8.2'
moodle-branch: 'MOODLE_404_STABLE'
moodle-branch: 'MOODLE_405_STABLE'
database: 'mariadb'
- php: '8.1'
moodle-branch: 'MOODLE_405_STABLE'
database: 'pgsql'
- php: '8.3'
moodle-branch: 'MOODLE_404_STABLE'
database: 'mariadb'
- php: '8.2'
moodle-branch: 'MOODLE_404_STABLE'
database: 'pgsql'
- php: '8.1'
moodle-branch: 'MOODLE_404_STABLE'
database: 'mariadb'
- php: '8.2'
moodle-branch: 'MOODLE_403_STABLE'
database: 'pgsql'
Expand All @@ -46,7 +58,7 @@ jobs:

steps:
- name: Check out repository code
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
path: plugin

Expand All @@ -59,7 +71,7 @@ jobs:

- name: Initialise moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
sudo locale-gen en_AU.UTF-8
Expand All @@ -77,15 +89,6 @@ jobs:
if: ${{ always() }}
run: moodle-plugin-ci phplint

- name: PHP Copy/Paste Detector
continue-on-error: true # This step will show errors but will not fail
if: ${{ always() }}
run: moodle-plugin-ci phpcpd

- name: PHP Mess Detector
if: ${{ always() }}
run: moodle-plugin-ci phpmd

- name: Moodle Code Checker
if: ${{ always() }}
run: moodle-plugin-ci codechecker --max-warnings 0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ The pro version (different repository) adds the following features:
See the changes.md.

# Installation
Install the plugin like any other plugin to folder /mod/pulse
Install the plugin like any other plugin to folder /blocks/dash
See http://docs.moodle.org/en/Installing_plugins for details on installing Moodle plugins

# Initial Configuration
Expand Down
4 changes: 2 additions & 2 deletions classes/local/configuration/abstract_configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ abstract class abstract_configuration implements configuration_interface {
* abstract_configuration constructor.
*
* @param \context $context
* @param data_source_interface|null $datasource
* @param ?data_source_interface $datasource
*/
protected function __construct(\context $context, data_source_interface $datasource = null) {
protected function __construct(\context $context, ?data_source_interface $datasource = null) {
$this->context = $context;
$this->datasource = $datasource;
}
Expand Down
4 changes: 2 additions & 2 deletions classes/local/data_grid/filter/filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,9 @@ public function get_custom_operation(): string {
/**
* Set preferences on this filter.
*
* @param array $preferences
* @param ?array $preferences
*/
public function set_preferences(array $preferences = null): void {
public function set_preferences(?array $preferences = null): void {
$this->preferences = $preferences;
}

Expand Down
4 changes: 2 additions & 2 deletions classes/local/data_grid/filter/filter_interface.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,9 @@ public function get_custom_operation(): string;
/**
* Set preferences on this filter.
*
* @param array $preferences
* @param ?array $preferences
*/
public function set_preferences(array $preferences = null): void;
public function set_preferences(?array $preferences = null): void;

/**
* Get preferences related to this filter.
Expand Down
13 changes: 13 additions & 0 deletions classes/table/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,17 @@ public function col_groupname($row) {
public function col_course($row) {
return format_string(get_course($row->courseid)->fullname);
}

/**
* Check capability for users accessing the groups table.
*
* @return bool
*/
public function has_capability(): bool {
global $CFG;
require_once($CFG->dirroot . '/course/lib.php');

$context = $this->course->id == SITEID ? \context_system::instance() : $this->get_context();
return has_capability('block/dash:mygroups_view', $context);
}
}
13 changes: 13 additions & 0 deletions classes/table/members.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,17 @@ public function col_fullname($row) {
public function col_roles($row) {
return get_user_roles_in_course($row->userid, $row->courseid);
}

/**
* Check capability for users accessing the members table.
*
* @return bool
*/
public function has_capability(): bool {
global $CFG;
require_once($CFG->dirroot . '/course/lib.php');

$context = $this->course->id == SITEID ? \context_system::instance() : $this->get_context();
return has_capability('block/dash:mygroups_viewmembers', $context);
}
}
2 changes: 1 addition & 1 deletion download.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
$sortdir = optional_param('sort_direction', '', PARAM_TEXT);

$PAGE->set_context(context_system::instance());
$PAGE->set_url('/blocks/dash/download.php', array('block_instance_id' => $instanceid));
$PAGE->set_url('/blocks/dash/download.php', ['block_instance_id' => $instanceid]);

$renderer = $PAGE->get_renderer('block_dash');
$binstance = $DB->get_record('block_instances', ['id' => $instanceid]);
Expand Down
10 changes: 4 additions & 6 deletions lang/en/block_dash.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment
// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder

$string['accordionfield1'] = 'Top left field';
$string['accordionfield1icon'] = 'Top left field icon';
$string['accordionfield2'] = 'Top right field';
Expand Down Expand Up @@ -64,12 +67,11 @@
$string['courseoverviewfilesurl'] = 'Course image URL';
$string['coursesummary'] = 'Course summary';
$string['courseurl'] = 'Course URL';
$string['courseurl'] = 'Course URL';
$string['createcustomdatasource'] = 'Create custom data source';
$string['createcustomlayout'] = 'Create custom layout';
$string['createdashboard'] = 'Create dashboard';
$string['createlayout'] = 'Create custom layout';
$string['cssclass'] = 'CSS Class';
$string['cssclass'] = 'CSS classes';
$string['currentcourse'] = 'Current course';
$string['currentcoursecontext'] = 'Current course context';
$string['currentcoursegroups'] = 'Current course groups';
Expand Down Expand Up @@ -409,7 +411,6 @@
$string['coursedate:present'] = 'Present';
$string['coursedate:future'] = 'Future';

$string['viewcourse'] = 'View course';
$string['enrolnow'] = 'Enrol now';
$string['buynow'] = 'Buy now';
$string['notavailable'] = 'Not available';
Expand Down Expand Up @@ -570,7 +571,6 @@
// ...Form section headers.
$string['fieldssection'] = 'Fields setup';
$string['conditionsection'] = 'Condition setup';
$string['fields'] = 'Fields';
$string['field'] = 'Field';
$string['fieldtransformdata'] = 'Transform the format';
$string['fieldtransformdata_help'] = 'Transform the format of the value when displayed in the table';
Expand Down Expand Up @@ -779,7 +779,6 @@
// ... enrol program string.
$string['programimagelink'] = 'Program image linked';
$string['smart_coursebutton'] = 'Smart course button';
$string['fullnamelinked'] = 'Fullname linked';
$string['contextlinked'] = 'Context linked';
$string['description'] = 'Description';
$string['programs:view'] = 'View programs';
Expand Down Expand Up @@ -814,7 +813,6 @@
$string['categoryimgfallbackdesc'] = 'Upload the image for the default fallback of categories. If new categories are created, the fallback image will be displayed until a new image is added for the category';
$string['categoryimageurl'] = 'Category image url';

$string['cssclass'] = "CSS classes";
$string['cssclass_help'] = "Use a custom CSS class to apply multiple classes.";
$string['backgroundposition'] = 'Background Position';
$string['backgroundposition_help'] = 'Background image will focused on the given position';
Expand Down
14 changes: 7 additions & 7 deletions tests/behat/mycontacts.feature
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ Feature: Add user contacts widget in dash block
Given I log in as "student1"
And I should see "Student Two" in the "New Dash" "block"
And I should see "Student Three" in the "New Dash" "block"
And I should see "2" in the ".block_dash-community-block .contact-element .row div.col-xl-3:nth-child(1) .badge-block" "css_element"
And ".badge-block" "css_element" should not exist in the ".block_dash-community-block .contact-element .row div:nth-child(2)" "css_element"
And I hover ".block_dash-community-block .contact-element .row div.col-xl-3:nth-child(1)" "css_element"
And I click on ".contact-widget-viewgroup" "css_element" in the ".block_dash-community-block .contact-element .row div.col-xl-3:nth-child(1)" "css_element"
And I should see "2" in the ".block_dash-community-block .contact-block .contact-element .row .col-xl-3:nth-child(1) .contact-img-block .img-block .badge-block" "css_element"
And ".badge-block" "css_element" should not exist in the ".block_dash-community-block .contact-block .contact-element .row .col-xl-3:nth-child(2)" "css_element"
And I hover ".block_dash-community-block .contact-element .row .col-xl-3:nth-child(1)" "css_element"
And I click on ".contact-widget-viewgroup" "css_element" in the ".block_dash-community-block .contact-element .row .col-xl-3:nth-child(1)" "css_element"
And I should see "Groups" in the ".modal-title" "css_element"
And "Group 1" "table_row" should exist
And I click on ".close" "css_element" in the ".modal-header" "css_element"
And I hover ".block_dash-community-block .contact-element .row div.col-xl-3:nth-child(2)" "css_element"
And I click on ".contact-widget-viewgroup" "css_element" in the ".block_dash-community-block .contact-element .row div.col-xl-3:nth-child(2)" "css_element"
And I click on "Close" "button" in the "Groups" "dialogue"
And I hover ".block_dash-community-block .contact-element .row .col-xl-3:nth-child(2)" "css_element"
And I click on ".contact-widget-viewgroup" "css_element" in the ".block_dash-community-block .contact-element .row .col-xl-3:nth-child(2)" "css_element"
And I should see "Groups" in the ".modal-title" "css_element"
Then I should see "Nothing to display" in the ".modal-body" "css_element"

Expand Down
2 changes: 1 addition & 1 deletion tests/behat/mygroups.feature
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Feature: Add My Groups widget in dash block
And I click on ".dropdown-toggle" "css_element" in the ".block_dash-community-block .list-block:nth-child(1)" "css_element"
And I click on ".group-widget-viewmembers" "css_element" in the ".block_dash-community-block .list-block:nth-child(1)" "css_element"
And "Student Two" "table_row" should exist
And I click on ".close" "css_element" in the ".modal-header" "css_element"
And I click on "Close" "button" in the "Groups" "dialogue"
And I click on ".dropdown-toggle" "css_element" in the ".block_dash-community-block .list-block:nth-child(3)" "css_element"
And I click on ".group-widget-viewmembers" "css_element" in the ".block_dash-community-block .list-block:nth-child(3)" "css_element"
Then I should see "Nothing to display" in the ".modal-body" "css_element"
Expand Down
29 changes: 27 additions & 2 deletions tests/behat/mylearning.feature
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ Feature: Enable the widget in dash block on the dashboard page and view it's con
And ".fa.fa-check" "css_element" should exist in the ".block_dash-info-element .card:nth-child(1)" "css_element"

@javascript @_file_upload
Scenario: Course badges list in Mylearning widget
Given I log in as "admin"
Scenario: Course badges list in Mylearning widget for Moodle ≤ 4.4
Given the site is running Moodle version 4.4 or lower
And I log in as "admin"
And I am on "Course 1" course homepage
And I navigate to "Badges > Add a new badge" in current page administration
And I set the following fields to these values:
Expand All @@ -99,6 +100,30 @@ Feature: Enable the widget in dash block on the dashboard page and view it's con
When I log in as "student1"
Then ".collected .activatebadge[alt=\"Badge 1\"]" "css_element" should exist in the "My Learning" "block"

@javascript @_file_upload
Scenario: Course badges list in Mylearning widget for Moodle ≥ 4.5
Given the site is running Moodle version 4.5 or higher
And I log in as "admin"
And I am on "Course 1" course homepage
And I navigate to "Badges > Add a new badge" in current page administration
And I set the following fields to these values:
| id_name | Badge 1 |
| id_description | Badge 1 |
And I upload "blocks/badges/tests/fixtures/badge.png" file to "Image" filemanager
And I press "Create badge"
And I select "Manual issue by role" from the "Add badge criteria" singleselect
And I set the field "Teacher" to "1"
And I press "Save"
And I press "Enable access"
And I click on "Enable" "button" in the "Confirm" "dialogue"
And I follow badge recipients
And I press "Award badge"
And I set the field "potentialrecipients[]" to "Student First ([email protected])"
And I press "Award badge"
And I log out
When I log in as "student1"
Then ".collected .activatebadge[alt=\"Badge 1\"]" "css_element" should exist in the "My Learning" "block"

@javascript
Scenario: Check the empty state option.
Given I log in as "student2"
Expand Down
15 changes: 8 additions & 7 deletions tests/filter_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* @group bdecent
* @group filter_test
*/
class filter_test extends \advanced_testcase {
final class filter_test extends \advanced_testcase {

/**
* @var filter_collection_interface
Expand All @@ -53,6 +53,7 @@ class filter_test extends \advanced_testcase {
* This method is called before each test.
*/
protected function setUp(): void {
parent::setUp();
$this->resetAfterTest();
$this->setAdminUser();

Expand All @@ -71,7 +72,7 @@ protected function setUp(): void {
* @covers ::general_stuff
* @return void
*/
public function test_general_stuff() {
public function test_general_stuff(): void {
$this->assertEquals('testing', $this->filtercollection->get_unique_identifier());
$this->assertCount(1, $this->filtercollection->get_filters());
$this->assertTrue($this->filtercollection->has_filter('filter1'));
Expand All @@ -84,7 +85,7 @@ public function test_general_stuff() {
* @covers ::remove_filter
* @return void
*/
public function test_remove_filter() {
public function test_remove_filter(): void {
$filter = $this->filtercollection->get_filter('filter1');
$this->filtercollection->remove_filter($filter);

Expand All @@ -99,7 +100,7 @@ public function test_remove_filter() {
* @covers ::applying_filter
* @return void
*/
public function test_applying_filter() {
public function test_applying_filter(): void {
$this->assertCount(0, $this->filtercollection->get_applied_filters());
$this->assertCount(0, $this->filtercollection->get_filters_with_values());

Expand All @@ -118,7 +119,7 @@ public function test_applying_filter() {
* @covers ::filter_sql_and_params_collection
* @return void
*/
public function test_filter_sql_and_params_collection() {
public function test_filter_sql_and_params_collection(): void {
$this->assertTrue($this->filtercollection->apply_filter('filter1', 123));

list($sql, $params) = $this->filtercollection->get_sql_and_params();
Expand All @@ -132,7 +133,7 @@ public function test_filter_sql_and_params_collection() {
* @covers ::required_filters
* @return void
*/
public function test_required_filters() {
public function test_required_filters(): void {
$this->assertFalse($this->filtercollection->has_required_filters());
$this->assertCount(0, $this->filtercollection->get_required_filters());

Expand All @@ -150,7 +151,7 @@ public function test_required_filters() {
* @covers ::caching
* @return void
*/
public function test_caching() {
public function test_caching(): void {
$this->filtercollection->apply_filter('filter1', 234);
$this->filtercollection->cache($this->user);

Expand Down
Loading