Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/moodlepluginci'
Browse files Browse the repository at this point in the history
  • Loading branch information
srobotta committed Sep 12, 2024
2 parents d7dbf8d + ca06c49 commit 3e64f60
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 10 deletions.
152 changes: 152 additions & 0 deletions .github/workflows/moodle-plugin-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
name: Moodle Plugin CI

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest

services:
postgres:
image: postgres:13
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3
mariadb:
image: mariadb:10.6
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

strategy:
fail-fast: false
matrix:
include:
- php: 8.3
moodle-branch: main
database: pgsql
plugin-ci: ^4
- php: 8.3
moodle-branch: main
database: mariadb
plugin-ci: ^4
- php: 8.2
moodle-branch: main
database: pgsql
plugin-ci: ^4
- php: 8.2
moodle-branch: main
database: mariadb
plugin-ci: ^4
- php: 8.1
moodle-branch: main
database: pgsql
plugin-ci: ^4
- php: 8.1
moodle-branch: main
database: mariadb
plugin-ci: ^4
- php: 8.3
moodle-branch: MOODLE_404_STABLE
database: pgsql
plugin-ci: ^4
- php: 8.3
moodle-branch: MOODLE_404_STABLE
database: mariadb
plugin-ci: ^4
- php: 8.2
moodle-branch: MOODLE_404_STABLE
database: pgsql
plugin-ci: ^4
- php: 8.2
moodle-branch: MOODLE_404_STABLE
database: mariadb
plugin-ci: ^4
- php: 8.1
moodle-branch: MOODLE_404_STABLE
database: pgsql
plugin-ci: ^4
- php: 8.1
moodle-branch: MOODLE_404_STABLE
database: mariadb
plugin-ci: ^4

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

- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: ${{ matrix.extensions }}
ini-values: max_input_vars=5000
coverage: none

- name: Initialise moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ${{ matrix.plugin-ci }}
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
sudo locale-gen en_AU.UTF-8
echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV
- 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 }}
IGNORE_PATHS: moodle/tests/fixtures,moodle/Sniffs

- name: PHP Lint
if: ${{ always() }}
run: moodle-plugin-ci phplint

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

- name: Moodle Code Checker
if: ${{ always() }}
run: moodle-plugin-ci codechecker --max-warnings 0

- name: Moodle PHPDoc Checker
if: ${{ always() }}
run: moodle-plugin-ci phpdoc

- name: Validating
if: ${{ always() }}
run: moodle-plugin-ci validate

- name: Check upgrade savepoints
if: ${{ always() }}
run: moodle-plugin-ci savepoints

- name: Mustache Lint
if: ${{ always() }}
run: moodle-plugin-ci mustache

- name: Grunt
if: ${{ always() }}
run: moodle-plugin-ci grunt --max-lint-warnings 0

- name: PHPUnit tests
if: ${{ always() }}
run: moodle-plugin-ci phpunit --coverage-text

- name: Behat features
if: ${{ always() }}
run: moodle-plugin-ci behat --profile chrome

6 changes: 5 additions & 1 deletion classes/plugin_feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.


namespace qbank_bulkxmlexport;
use core_question\local\bank\plugin_features_base;

Expand All @@ -27,6 +26,11 @@
*/
class plugin_feature extends plugin_features_base {

/**
* This method will return the array objects for the bulk actions ui.
*
* @return bulk_action_base[]
*/
public function get_bulk_actions(): array {
return [
new xmlexport(),
Expand Down
6 changes: 6 additions & 0 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
*/
class provider implements \core_privacy\local\metadata\null_provider {

/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
Expand Down
28 changes: 28 additions & 0 deletions classes/xmlexport.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,49 @@
*/
class xmlexport extends \core_question\local\bank\bulk_action_base {

/**
* The key for the action.
*/
public const KEY = 'bulkxmlexport';

/**
* The URL for the action.
*/
public const URL = '/question/bank/bulkxmlexport/export.php';

/**
* Return the string to show in the list.
*
* @return string
* @throws \coding_exception
*/
public function get_bulk_action_title(): string {
return get_string('exportasxml', 'question');
}

/**
* Return the key for the action.
*
* @return string
*/
public function get_key(): string {
return self::KEY;
}

/**
* Return the URL of the bulk action redirect page.
*
* @return \moodle_url
*/
public function get_bulk_action_url(): \moodle_url {
return new \moodle_url(self::URL);
}

/**
* Get the capabilities for the bulk action.
*
* @return string[]|null
*/
public function get_bulk_action_capabilities(): ?array {
return [
'moodle/question:viewall',
Expand Down
20 changes: 11 additions & 9 deletions tests/behat/bulk_xml_export_action.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@
Feature: Use the plugin to export several question at once in the qbank manager.

Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
And the following "courses" exist:
Given the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "activities" exist:
| activity | name | course | idnumber |
| quiz | Test quiz | C1 | quiz1 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| activity | name | course | idnumber |
| quiz | Test quiz | C1 | quiz1 |
And the following "question categories" exist:
| contextlevel | reference | questioncategory | name |
| Course | C1 | Top | top |
| Course | C1 | top | Default for C1 |
| Course | C1 | Default for C1 | Subcategory |
| Course | C1 | Test questions | testquestions |
And the following "questions" exist:
| questioncategory | qtype | name | questiontext |
| Test questions | truefalse | First question | Answer the first question |
| Default for C1 | truefalse | First question | Answer the first question |
| Subcategory | essay | Essay Foo Bar | Write about whatever you want |
And the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |

Scenario: Enable/disable bulk export xml questions bulk action from the base view
Given I log in as "admin"
Expand Down
1 change: 1 addition & 0 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* Version information for qbank_bulkxmlexport.
*
* @package qbank_bulkxmlexport
* @copyright 2024 Stephan Robotta
* @author 2024 Stephan Robotta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
Expand Down

0 comments on commit 3e64f60

Please sign in to comment.