Skip to content

Commit

Permalink
Assure compatibility for Moodle 4.1.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaboesch committed Jan 7, 2023
1 parent b0dfd77 commit c9a02b7
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 106 deletions.
100 changes: 29 additions & 71 deletions .github/workflows/moodle-plugin-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ on: [push, pull_request]

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

services:
postgres:
image: postgres:10
image: postgres:12
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
Expand All @@ -20,6 +20,8 @@ jobs:
env:
MYSQL_USER: 'root'
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
MYSQL_CHARACTER_SET_SERVER: "utf8mb4"
MYSQL_COLLATION_SERVER: "utf8mb4_unicode_ci"
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3
Expand All @@ -28,6 +30,30 @@ jobs:
fail-fast: false
matrix:
include:
- php: 8.0
moodle-branch: MOODLE_401_STABLE
database: pgsql
- php: 8.0
moodle-branch: MOODLE_401_STABLE
database: mariadb
- php: 7.4
moodle-branch: MOODLE_401_STABLE
database: pgsql
- php: 7.4
moodle-branch: MOODLE_401_STABLE
database: mariadb
- php: 8.0
moodle-branch: MOODLE_400_STABLE
database: pgsql
- php: 8.0
moodle-branch: MOODLE_400_STABLE
database: mariadb
- php: 7.4
moodle-branch: MOODLE_400_STABLE
database: pgsql
- php: 7.4
moodle-branch: MOODLE_400_STABLE
database: mariadb
- php: 7.4
moodle-branch: MOODLE_311_STABLE
database: pgsql
Expand All @@ -46,12 +72,6 @@ jobs:
- php: 7.4
moodle-branch: MOODLE_39_STABLE
database: mariadb
- php: 7.4
moodle-branch: MOODLE_38_STABLE
database: pgsql
- php: 7.4
moodle-branch: MOODLE_38_STABLE
database: mariadb

- php: 7.3
moodle-branch: MOODLE_311_STABLE
Expand All @@ -71,24 +91,6 @@ jobs:
- php: 7.3
moodle-branch: MOODLE_39_STABLE
database: mariadb
- php: 7.3
moodle-branch: MOODLE_38_STABLE
database: pgsql
- php: 7.3
moodle-branch: MOODLE_38_STABLE
database: mariadb
- php: 7.3
moodle-branch: MOODLE_37_STABLE
database: pgsql
- php: 7.3
moodle-branch: MOODLE_37_STABLE
database: mariadb
- php: 7.3
moodle-branch: MOODLE_36_STABLE
database: pgsql
- php: 7.3
moodle-branch: MOODLE_36_STABLE
database: mariadb

- php: 7.2
moodle-branch: MOODLE_310_STABLE
Expand All @@ -102,54 +104,10 @@ jobs:
- php: 7.2
moodle-branch: MOODLE_39_STABLE
database: mariadb
- php: 7.2
moodle-branch: MOODLE_38_STABLE
database: pgsql
- php: 7.2
moodle-branch: MOODLE_38_STABLE
database: mariadb
- php: 7.2
moodle-branch: MOODLE_37_STABLE
database: pgsql
- php: 7.2
moodle-branch: MOODLE_37_STABLE
database: mariadb
- php: 7.2
moodle-branch: MOODLE_36_STABLE
database: pgsql
- php: 7.2
moodle-branch: MOODLE_36_STABLE
database: mariadb

- php: 7.1
moodle-branch: MOODLE_38_STABLE
database: pgsql
- php: 7.1
moodle-branch: MOODLE_38_STABLE
database: mariadb
- php: 7.1
moodle-branch: MOODLE_37_STABLE
database: pgsql
- php: 7.1
moodle-branch: MOODLE_37_STABLE
database: mariadb
- php: 7.1
moodle-branch: MOODLE_36_STABLE
database: pgsql
- php: 7.1
moodle-branch: MOODLE_36_STABLE
database: mariadb

- php: 7.0
moodle-branch: MOODLE_36_STABLE
database: mariadb
- php: 7.0
moodle-branch: MOODLE_35_STABLE
database: mariadb

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

Expand Down
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Changes

### Unreleased

* 2022-11-18 - Check to work with Moodle ≥ 4.0 hence question versions.
* 2021-07-31 - Cosmetic change (newline at the end of file) for phpcs check.
* 2021-07-31 - Adding Moodle plugin CI info in README.md.

Expand Down
3 changes: 0 additions & 3 deletions archive_options.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/


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

/**
* Class to store the options for a {@see quiz_archive_report}.
*
Expand Down
2 changes: 0 additions & 2 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

namespace quiz_archive\privacy;

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

/**
* Privacy Subsystem implementing null_provider.
*
Expand Down
4 changes: 0 additions & 4 deletions db/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/


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


/**
* Post-install script
*/
Expand Down
3 changes: 0 additions & 3 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/


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

/**
* Upgrade function
*
Expand Down
1 change: 1 addition & 0 deletions report.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

use mod_quiz\local\reports\report_base;

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

Expand Down
12 changes: 4 additions & 8 deletions tests/behat/basic.feature
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,26 @@ Feature: Basic use of the Archive report
And I log in as "student1"
And I am on "Course 1" course homepage
And I follow "Quiz 1"
And I press "Attempt quiz now"
And I press "Attempt quiz"
And I click on "True" "radio" in the "First question" "question"
And I click on "False" "radio" in the "Second question" "question"
And I press "Finish attempt ..."
And I press "Submit all and finish"
And I click on "Submit all and finish" "button" in the "Confirmation" "dialogue"
And I log out

And I log in as "student2"
And I am on "Course 1" course homepage
And I follow "Quiz 1"
And I press "Attempt quiz now"
And I press "Attempt quiz"
And I click on "True" "radio" in the "First question" "question"
And I click on "True" "radio" in the "Second question" "question"
And I press "Finish attempt ..."
And I press "Submit all and finish"
And I click on "Submit all and finish" "button" in the "Confirmation" "dialogue"
And I confirm the quiz submission in the modal dialog
And I log out

# Basic check of the Archive report
When I log in as "teacher1"
And I am on "Course 1" course homepage
And I follow "Quiz 1"
And I navigate to "Results > Archive" in current page administration
When I am on the "Quiz 1" "quiz_archive > Archive" page logged in as "teacher1"
Then I should see "Quiz 1"
# Check student1's attempt
And I should see "S1 Student1"
Expand Down
118 changes: 118 additions & 0 deletions tests/behat/behat_quiz_archive.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?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/>.

/**
* Behat quiz_archive related steps definitions.
*
* @package quiz_archive
* @category test
* @copyright 2022 Luca Bösch <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.

require_once(__DIR__ . '/../../../../../../lib/behat/behat_base.php');

/**
* Step definitions related to quiz_archive.
*/
class behat_quiz_archive extends behat_question_base {

/**
* Convert page names to URLs for steps like 'When I am on the "[page name]" page'.
*
* Recognised page names are:
* | None so far! | |
*
* @param string $page name of the page, with the component name removed e.g. 'Admin notification'.
* @return moodle_url the corresponding URL.
* @throws Exception with a meaningful error message if the specified page cannot be found.
*/
protected function resolve_page_url(string $page): moodle_url {
switch ($page) {
default:
throw new Exception('Unrecognised quiz_archive page type "' . $page . '."');
}
}

/**
* Convert page names to URLs for steps like 'When I am on the "[identifier]" "[page type]" page'.
*
* Recognised page names are:
* | pagetype | name meaning | description |
* | Report | Quiz name | The report page (mod/quiz/report.php?mode=archive) |
*
* @param string $type identifies which type of page this is, e.g. 'Attempt review'.
* @param string $identifier identifies the particular page, e.g. 'Test quiz > student > Attempt 1'.
* @return moodle_url the corresponding URL.
* @throws Exception with a meaningful error message if the specified page cannot be found.
*/
protected function resolve_page_instance_url(string $type, string $identifier): moodle_url {
global $DB;

switch ($type) {
case 'Archive':
return new moodle_url('/mod/quiz/report.php',
['id' => $this->get_cm_by_quiz_name($identifier)->id, 'mode' => 'archive']);

default:
throw new Exception('Unrecognised quiz_archives page type "' . $type . '".');
}
}

/**
* Get a quiz by name.
*
* @param string $name quiz name.
* @return stdClass the corresponding DB row.
*/
protected function get_quiz_by_name(string $name): stdClass {
global $DB;
return $DB->get_record('quiz', ['name' => $name], '*', MUST_EXIST);
}

/**
* Get a quiz cmid from the quiz name.
*
* @param string $name quiz name.
* @return stdClass cm from get_coursemodule_from_instance.
*/
protected function get_cm_by_quiz_name(string $name): stdClass {
$quiz = $this->get_quiz_by_name($name);
return get_coursemodule_from_instance('quiz', $quiz->id, $quiz->course);
}

/**
* Work around modal dialogs with different wordings in different Moodle versions.
*
* @Given /^I confirm the quiz submission in the modal dialog$/
* @throws Exception
*/
public function i_confirm_the_quiz_submission_in_the_modal_dialog() {
global $CFG;
require_once($CFG->libdir . '/environmentlib.php');
require($CFG->dirroot . '/version.php');
$currentversion = normalize_version($release);
if (version_compare($currentversion, '4.1', ">=")) {
$xpath = "//div[contains(@class, 'modal-dialog')]/*/*/button[contains(@class, 'btn-primary')]";
} else if (version_compare($currentversion, '3.9', ">=")) {
$xpath = "//div[contains(@class, 'confirmation-dialogue')]/*/input[contains(@class, 'btn-primary')]";
}
$this->execute("behat_general::i_click_on", array($this->escape($xpath), "xpath_element"));
}
}

Loading

0 comments on commit c9a02b7

Please sign in to comment.