Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
34 changes: 16 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ jobs:
fail-fast: false
matrix:
include:
- php: '7.4'
moodle-branch: 'master'
database: 'pgsql'
- php: '7.4'
moodle-branch: 'MOODLE_311_STABLE'
database: 'mariadb'
- { php: '8.1', moodle-branch: MOODLE_404_STABLE, database: pgsql }
- { php: '8.2', moodle-branch: MOODLE_405_STABLE, database: mariadb }
- { php: '8.3', moodle-branch: MOODLE_500_STABLE, database: pgsql }
- { php: '8.3', moodle-branch: main, database: pgsql }

services:
postgres:
image: postgres
image: postgres:14
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
Expand All @@ -30,7 +28,7 @@ jobs:
- 5432:5432

mariadb:
image: mariadb
image: mariadb:10
env:
MYSQL_USER: 'root'
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
Expand All @@ -49,25 +47,25 @@ jobs:
with:
node-version: '14.15.0'

- name: Setup PHP
- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mbstring, pgsql, mysqli
# tools: phpunit
# coverage: none
extensions: ${{ matrix.extensions }}
ini-values: max_input_vars=5000
coverage: none

- name: Deploy moodle-plugin-ci
- name: Initialise moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
# Add dirs to $PATH
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
# PHPUnit depends on en_AU.UTF-8 locale
sudo locale-gen en_AU.UTF-8
echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV

- name: Install Moodle
run: moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1
- name: Install moodle-plugin-ci
run: |
moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1
env:
DB: ${{ matrix.database }}
MOODLE_BRANCH: ${{ matrix.moodle-branch }}
Expand Down
104 changes: 104 additions & 0 deletions classes/utils.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Utility functions for the oumultiresponse question type.
*
* @package qtype_oumultiresponse
* @copyright 2025 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace qtype_oumultiresponse;

/**
* Class that holds utility functions used by the oumultiresponse question type.
*
* @package qtype_oumultiresponse
* @copyright 2025 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class utils {

/** @var string - Less than operator */
const OP_LT = "<";
/** @var string - equal operator */
const OP_E = "=";
/** @var string - greater than operator */
const OP_GT = ">";

/**
* Conveniently compare the current moodle version to a provided version in branch format. This function will
* inflate version numbers to a three digit number before comparing them. This way moodle minor versions greater
* than 9 can be correctly and easily compared.
*
* Examples:
* utils::moodle_version_is("<", "39");
* utils::moodle_version_is("<=", "310");
* utils::moodle_version_is(">", "39");
* utils::moodle_version_is(">=", "38");
* utils::moodle_version_is("=", "41");
*
* CFG reference:
* $CFG->branch = "311", "310", "39", "38", ...
* $CFG->release = "3.11+ (Build: 20210604)", ...
* $CFG->version = "2021051700.04", ...
*
* @param string $operator for the comparison
* @param string $version to compare to
* @return boolean
*/
public static function moodle_version_is(string $operator, string $version): bool {
global $CFG;

if (strlen($version) == 2) {
$version = $version[0]."0".$version[1];
}

$current = $CFG->branch;
if (strlen($current) == 2) {
$current = $current[0]."0".$current[1];
}

$from = intval($current);
$to = intval($version);
$ops = str_split($operator);

foreach ($ops as $op) {
switch ($op) {
case self::OP_LT:
if ($from < $to) {
return true;
}
break;
case self::OP_E:
if ($from == $to) {
return true;
}
break;
case self::OP_GT:
if ($from > $to) {
return true;
}
break;
default:
throw new \coding_exception('invalid operator '.$op);
}
}

return false;
}
}
2 changes: 1 addition & 1 deletion combinable/combinable.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function add_form_fragment(moodleform $combinedform, MoodleQuickForm $mfo
get_string('choiceno', 'qtype_multichoice', '{no}'), ['rows' => 2]);
$mform->setType($this->form_field_name('answer'), PARAM_RAW);
$answerels[] = $mform->createElement('advcheckbox', $this->form_field_name('correctanswer'),
get_string('correct', 'question'), get_string('correct', 'question'));
'', get_string('correct', 'question'));

$answergroupel = $mform->createElement('group',
$this->form_field_name('answergroup'),
Expand Down
7 changes: 4 additions & 3 deletions combinable/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ public function subquestion(question_attempt $qa,
$fullresponse = new qtype_combined_response_array_param($qa->get_last_qt_data());
$response = $fullresponse->for_subq($subq);

$commonattributes = array(
'type' => 'checkbox'
);
$commonattributes = [
'type' => 'checkbox',
'class' => empty($response) ? 'required' : '',
];

if ($options->readonly) {
$commonattributes['disabled'] = 'disabled';
Expand Down
2 changes: 2 additions & 0 deletions tests/behat/backup_and_restore.feature
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Feature: Test duplicating a quiz containing an OU multiple response question
| quiz | Test quiz | C1 | quiz1 |
And quiz "Test quiz" contains the following questions:
| oumultiresponse 001 | 1 |
And the following config values are set as admin:
| enableasyncbackup | 0 |

@javascript
Scenario: Backup and restore a course containing an OU multiple response question
Expand Down
6 changes: 3 additions & 3 deletions tests/behat/preview.feature
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Feature: Preview an OU multiple response question
When I am on the "oumultiresponse 001" "core_question > preview" page logged in as teacher
And I expand all fieldsets
And I set the field "How questions behave" to "Immediate feedback"
And I press "Start again with these options"
And I press "id_saverestart"
And I click on "One" "qtype_multichoice > Answer"
And I click on "Two" "qtype_multichoice > Answer"
And I press "Check"
Expand All @@ -38,7 +38,7 @@ Feature: Preview an OU multiple response question
When I am on the "oumultiresponse 001" "core_question > preview" page logged in as teacher
And I expand all fieldsets
And I set the field "How questions behave" to "Immediate feedback"
And I press "Start again with these options"
And I press "id_saverestart"
And I click on "One" "qtype_multichoice > Answer"
And I click on "Three" "qtype_multichoice > Answer"
And I press "Check"
Expand All @@ -60,7 +60,7 @@ Feature: Preview an OU multiple response question
And I am on the "oumultiresponse 002" "core_question > preview" page
And I expand all fieldsets
And I set the field "How questions behave" to "Immediate feedback"
And I press "Start again with these options"
And I press "id_saverestart"
And I click on "One" "qtype_multichoice > Answer"
And I click on "Two" "qtype_multichoice > Answer"
And I press "Check"
Expand Down
2 changes: 1 addition & 1 deletion tests/privacy_provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function test_export_user_preferences($name, $value, $expected) {
*
* @return array Array of valid user preferences.
*/
public function user_preference_provider() {
public static function user_preference_provider() {
return [
'default mark 2' => ['defaultmark', 2, 2],
'penalty 33.33333%' => ['penalty', 0.3333333, '33.33333%'],
Expand Down
6 changes: 5 additions & 1 deletion tests/walkthrough_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,13 @@ public function test_shows_standrd_instruction_no() {
$this->start_attempt_at_question($mc, 'interactive', 3);
$this->render();

$standardinstructionclass = 'prompt h6 fw-normal visually-hidden';
if (utils::moodle_version_is("<=" , "45")) {
$standardinstructionclass = 'prompt h6 font-weight-normal sr-only';
}
// Check for 'Show standard instruction'.
$standardinstruction = \html_writer::tag('legend', get_string('answer'), [
'class' => 'prompt h6 font-weight-normal sr-only'
'class' => $standardinstructionclass,
]);
$this->assertStringContainsString($standardinstruction, $this->currentoutput);
}
Expand Down