Skip to content

Commit 7733822

Browse files
author
Matthias Opitz
committed
Updates required for Moodle 4.2+
- using correct class names for test cases used by Moodle 4.2+ - using core_external subsystem as of Moodle 4.2 - using numericals to set savepoints - added moodle_ci.yml to trigger GitHub Actions
1 parent f6e5df7 commit 7733822

14 files changed

+252
-104
lines changed

.github/workflows/moodle-ci.yml

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: Moodle Plugin CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
9+
services:
10+
postgres:
11+
image: postgres:13
12+
env:
13+
POSTGRES_USER: 'postgres'
14+
POSTGRES_HOST_AUTH_METHOD: 'trust'
15+
ports:
16+
- 5432:5432
17+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3
18+
mariadb:
19+
# https://tracker.moodle.org/browse/MDL-72131
20+
image: mariadb:10
21+
env:
22+
MYSQL_USER: 'root'
23+
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
24+
ports:
25+
- 3306:3306
26+
options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3
27+
28+
strategy:
29+
fail-fast: false
30+
matrix:
31+
include:
32+
- php: '8.1'
33+
moodle-branch: 'master'
34+
extensions: "mbstring, pgsql, mysqli"
35+
database: 'pgsql'
36+
- php: '8.0'
37+
moodle-branch: 'MOODLE_402_STABLE'
38+
extensions: "mbstring, pgsql, mysqli"
39+
database: 'mariadb'
40+
41+
steps:
42+
- name: Check out repository code
43+
uses: actions/checkout@v2
44+
with:
45+
path: plugin
46+
47+
- name: Setup PHP ${{ matrix.php }}
48+
uses: shivammathur/setup-php@v2
49+
with:
50+
php-version: ${{ matrix.php }}
51+
extensions: ${{ matrix.extensions }}
52+
ini-values: max_input_vars=5000
53+
tools: phpunit
54+
coverage: none
55+
56+
- name: Initialise moodle-plugin-ci
57+
run: |
58+
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
59+
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
60+
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
61+
sudo locale-gen en_AU.UTF-8
62+
echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV
63+
64+
- name: Install Moodle
65+
run: |
66+
moodle-plugin-ci add-plugin --branch MOODLE_402_STABLE Microsoft/moodle-auth_oidc
67+
moodle-plugin-ci install -vvv --plugin ./plugin --db-host=127.0.0.1
68+
env:
69+
DB: ${{ matrix.database }}
70+
MOODLE_BRANCH: ${{ matrix.moodle-branch }}
71+
72+
- name: PHP Lint
73+
if: ${{ always() }}
74+
run: moodle-plugin-ci phplint
75+
76+
- name: PHP Copy/Paste Detector
77+
continue-on-error: true # This step will show errors but will not fail
78+
if: ${{ always() }}
79+
run: moodle-plugin-ci phpcpd
80+
81+
- name: PHP Mess Detector
82+
continue-on-error: true # This step will show errors but will not fail
83+
if: ${{ always() }}
84+
run: moodle-plugin-ci phpmd
85+
86+
- name: Moodle Code Checker
87+
if: ${{ false }}
88+
run: moodle-plugin-ci codechecker --max-warnings 0
89+
90+
- name: Moodle PHPDoc Checker
91+
continue-on-error: true # This step will show errors but will not fail
92+
if: ${{ always() }}
93+
run: moodle-plugin-ci phpdoc
94+
95+
- name: Validating
96+
if: ${{ always() }}
97+
run: moodle-plugin-ci validate
98+
99+
- name: Check upgrade savepoints
100+
if: ${{ always() }}
101+
run: moodle-plugin-ci savepoints
102+
103+
- name: Mustache Lint
104+
if: ${{ always() }}
105+
run: moodle-plugin-ci mustache
106+
107+
- name: Grunt
108+
if: ${{ false }}
109+
run: moodle-plugin-ci grunt --max-lint-warnings 0
110+
111+
- name: PHPUnit tests
112+
if: ${{ always() }}
113+
run: moodle-plugin-ci phpunit
114+
115+
- name: Behat features
116+
if: ${{ always() }}
117+
run: moodle-plugin-ci behat --profile chrome

classes/webservices/create_onenoteassignment.php

+15-9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525

2626
namespace local_o365\webservices;
2727

28+
use \core_external\external_api;
29+
use \core_external\external_function_parameters;
30+
use \core_external\external_multiple_structure;
31+
use \core_external\external_single_structure;
32+
use \core_external\external_value;
33+
2834
defined('MOODLE_INTERNAL') || die();
2935

3036
global $CFG;
@@ -34,21 +40,21 @@
3440
/**
3541
* Create assignment API class.
3642
*/
37-
class create_onenoteassignment extends \external_api {
43+
class create_onenoteassignment extends external_api {
3844
/**
3945
* Returns description of method parameters.
4046
*
4147
* @return external_function_parameters The parameters object for this webservice method.
4248
*/
4349
public static function assignment_create_parameters() {
44-
return new \external_function_parameters([
45-
'data' => new \external_single_structure([
46-
'name' => new \external_value(PARAM_TEXT, 'name'),
47-
'course' => new \external_value(PARAM_INT, 'course id'),
48-
'intro' => new \external_value(PARAM_TEXT, 'intro', VALUE_DEFAULT, ''),
49-
'section' => new \external_value(PARAM_INT, 'section', VALUE_DEFAULT, 0),
50-
'visible' => new \external_value(PARAM_BOOL, 'visible', VALUE_DEFAULT, false),
51-
'duedate' => new \external_value(PARAM_INT, 'duedate', VALUE_DEFAULT, 0),
50+
return new external_function_parameters([
51+
'data' => new external_single_structure([
52+
'name' => new external_value(PARAM_TEXT, 'name'),
53+
'course' => new external_value(PARAM_INT, 'course id'),
54+
'intro' => new external_value(PARAM_TEXT, 'intro', VALUE_DEFAULT, ''),
55+
'section' => new external_value(PARAM_INT, 'section', VALUE_DEFAULT, 0),
56+
'visible' => new external_value(PARAM_BOOL, 'visible', VALUE_DEFAULT, false),
57+
'duedate' => new external_value(PARAM_INT, 'duedate', VALUE_DEFAULT, 0),
5258
])
5359
]);
5460
}

classes/webservices/delete_onenoteassignment.php

+13-7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525

2626
namespace local_o365\webservices;
2727

28+
use \core_external\external_api;
29+
use \core_external\external_function_parameters;
30+
use \core_external\external_multiple_structure;
31+
use \core_external\external_single_structure;
32+
use \core_external\external_value;
33+
2834
defined('MOODLE_INTERNAL') || die();
2935

3036
global $CFG;
@@ -34,17 +40,17 @@
3440
/**
3541
* Delete assignment API class.
3642
*/
37-
class delete_onenoteassignment extends \external_api {
43+
class delete_onenoteassignment extends external_api {
3844
/**
3945
* Returns description of method parameters.
4046
*
4147
* @return external_function_parameters The parameters object for this webservice method.
4248
*/
4349
public static function assignment_delete_parameters() {
44-
return new \external_function_parameters([
45-
'data' => new \external_single_structure([
46-
'coursemodule' => new \external_value(PARAM_INT, 'course module id'),
47-
'course' => new \external_value(PARAM_INT, 'course id'),
50+
return new external_function_parameters([
51+
'data' => new external_single_structure([
52+
'coursemodule' => new external_value(PARAM_INT, 'course module id'),
53+
'course' => new external_value(PARAM_INT, 'course id'),
4854
])
4955
]);
5056
}
@@ -79,8 +85,8 @@ public static function assignment_delete($data) {
7985
*/
8086
public static function assignment_delete_returns() {
8187
$params = [
82-
'result' => new \external_value(PARAM_BOOL, 'success/failure'),
88+
'result' => new external_value(PARAM_BOOL, 'success/failure'),
8389
];
84-
return new \external_single_structure($params);
90+
return new external_single_structure($params);
8591
}
8692
}

classes/webservices/read_onenoteassignment.php

+11-5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525

2626
namespace local_o365\webservices;
2727

28+
use \core_external\external_api;
29+
use \core_external\external_function_parameters;
30+
use \core_external\external_multiple_structure;
31+
use \core_external\external_single_structure;
32+
use \core_external\external_value;
33+
2834
defined('MOODLE_INTERNAL') || die();
2935

3036
global $CFG;
@@ -34,17 +40,17 @@
3440
/**
3541
* Read assignment API class.
3642
*/
37-
class read_onenoteassignment extends \external_api {
43+
class read_onenoteassignment extends external_api {
3844
/**
3945
* Returns description of method parameters.
4046
*
4147
* @return external_function_parameters The parameters object for this webservice method.
4248
*/
4349
public static function assignment_read_parameters() {
44-
return new \external_function_parameters([
45-
'data' => new \external_single_structure([
46-
'coursemodule' => new \external_value(PARAM_INT, 'course module id'),
47-
'course' => new \external_value(PARAM_INT, 'course id'),
50+
return new external_function_parameters([
51+
'data' => new external_single_structure([
52+
'coursemodule' => new external_value(PARAM_INT, 'course module id'),
53+
'course' => new external_value(PARAM_INT, 'course id'),
4854
])
4955
]);
5056
}

classes/webservices/update_onenoteassignment.php

+14-9
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
namespace local_o365\webservices;
2727

2828
use \local_o365\webservices\exception as exception;
29+
use \core_external\external_api;
30+
use \core_external\external_function_parameters;
31+
use \core_external\external_multiple_structure;
32+
use \core_external\external_single_structure;
33+
use \core_external\external_value;
2934

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

@@ -36,21 +41,21 @@
3641
/**
3742
* Update assignment API class.
3843
*/
39-
class update_onenoteassignment extends \external_api {
44+
class update_onenoteassignment extends external_api {
4045
/**
4146
* Returns description of method parameters.
4247
*
4348
* @return external_function_parameters The parameters object for this webservice method.
4449
*/
4550
public static function assignment_update_parameters() {
46-
return new \external_function_parameters([
47-
'data' => new \external_single_structure([
48-
'coursemodule' => new \external_value(PARAM_INT, 'course module id'),
49-
'course' => new \external_value(PARAM_INT, 'course id'),
50-
'name' => new \external_value(PARAM_TEXT, 'name', VALUE_DEFAULT, null),
51-
'intro' => new \external_value(PARAM_TEXT, 'intro', VALUE_DEFAULT, null),
52-
'section' => new \external_value(PARAM_INT, 'section', VALUE_DEFAULT, null),
53-
'visible' => new \external_value(PARAM_BOOL, 'visible', VALUE_DEFAULT, null),
51+
return new external_function_parameters([
52+
'data' => new external_single_structure([
53+
'coursemodule' => new external_value(PARAM_INT, 'course module id'),
54+
'course' => new external_value(PARAM_INT, 'course id'),
55+
'name' => new external_value(PARAM_TEXT, 'name', VALUE_DEFAULT, null),
56+
'intro' => new external_value(PARAM_TEXT, 'intro', VALUE_DEFAULT, null),
57+
'section' => new external_value(PARAM_INT, 'section', VALUE_DEFAULT, null),
58+
'visible' => new external_value(PARAM_BOOL, 'visible', VALUE_DEFAULT, null),
5459
])
5560
]);
5661
}

classes/webservices/utils.php

+13-10
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525

2626
namespace local_o365\webservices;
2727

28+
use \core_external\external_multiple_structure;
29+
use \core_external\external_single_structure;
30+
use \core_external\external_value;
2831
use \local_o365\webservices\exception as exception;
2932

3033
defined('MOODLE_INTERNAL') || die();
@@ -71,19 +74,19 @@ public static function verify_assignment($coursemoduleid, $courseid) {
7174
*/
7275
public static function get_assignment_return_info_schema() {
7376
$params = [
74-
'data' => new \external_multiple_structure(
75-
new \external_single_structure([
76-
'course' => new \external_value(PARAM_INT, 'course id'),
77-
'coursemodule' => new \external_value(PARAM_INT, 'coursemodule id'),
78-
'name' => new \external_value(PARAM_TEXT, 'name'),
79-
'intro' => new \external_value(PARAM_TEXT, 'intro'),
80-
'section' => new \external_value(PARAM_INT, 'section'),
81-
'visible' => new \external_value(PARAM_INT, 'visible'),
82-
'instance' => new \external_value(PARAM_INT, 'instance id'),
77+
'data' => new external_multiple_structure(
78+
new external_single_structure([
79+
'course' => new external_value(PARAM_INT, 'course id'),
80+
'coursemodule' => new external_value(PARAM_INT, 'coursemodule id'),
81+
'name' => new external_value(PARAM_TEXT, 'name'),
82+
'intro' => new external_value(PARAM_TEXT, 'intro'),
83+
'section' => new external_value(PARAM_INT, 'section'),
84+
'visible' => new external_value(PARAM_INT, 'visible'),
85+
'instance' => new external_value(PARAM_INT, 'instance id'),
8386
])
8487
),
8588
];
86-
return new \external_single_structure($params);
89+
return new external_single_structure($params);
8790
}
8891

8992
/**

0 commit comments

Comments
 (0)