forked from ngandrass/moodle-quiz_archiver
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ngandrass:master' into MBS-8820_Add_pdf_coversheet_hand…
…ling
- Loading branch information
Showing
68 changed files
with
5,595 additions
and
1,633 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Testing | ||
|
||
**ATTENTION:** The following notes are meant **for developers only**. If you only want | ||
to use this plugin you can fully ignore this file. | ||
|
||
|
||
## Creating a PHPUnit test environment | ||
|
||
See: https://moodledev.io/general/development/tools/phpunit | ||
|
||
1. Spawn a shell inside your Moodle/php-fpm container and navigate to your | ||
Moodle root directory: | ||
```bash | ||
docker exec -it my-moodle-container sh | ||
cd /usr/share/nginx/www/moodle/ | ||
``` | ||
2. Prepare PHPUnit configuration. Add the following lines to your `config.php`: | ||
```php | ||
$CFG->phpunit_prefix = 'phpu_'; | ||
$CFG->phpunit_dataroot = '/path/to/your/phpunit_moodledata'; | ||
``` | ||
3. Download composer and install dev dependencies: | ||
```bash | ||
wget https://getcomposer.org/download/latest-stable/composer.phar | ||
php composer.phar install | ||
``` | ||
4. Bootstrap test environment: | ||
```bash | ||
php admin/tool/phpunit/cli/init.php --disable-composer | ||
``` | ||
|
||
|
||
## Running tests | ||
|
||
- Run all tests: | ||
```bash | ||
vendor/bin/phpunit --colors --testdox | ||
``` | ||
- Run all tests for a single component: | ||
```bash | ||
vendor/bin/phpunit --colors --testdox --filter quiz_archiver/* | ||
``` | ||
- Run a single test suite: | ||
```bash | ||
vendor/bin/phpunit --colors --testdox mod/quiz/report/archiver/tests/Report_test.php | ||
``` | ||
|
||
### Automatic test execution for all supported software configurations | ||
|
||
The configuration for automated test execution via GitHub CI can be found in | ||
`.github/workflows/moodle-plugin-ci.yml`. It holds a matrix of all supported | ||
software configurations and runs the tests for each of them. | ||
|
||
|
||
## Generating code coverage reports | ||
|
||
**You need to have xdebug installed and enabled in order to generate coverage | ||
reports!** | ||
|
||
1. Run PHPUnit with coverage report: | ||
```bash | ||
XDEBUG_MODE=coverage vendor/bin/phpunit --colors --testdox --coverage-html /tmp/coverage --filter quiz_archiver/* | ||
``` | ||
2. Copy the generated report to your machin: | ||
```bash | ||
docker cp my-moodle-container:/tmp/coverage /tmp/coverage | ||
``` | ||
3. Open the report in your browser: | ||
```bash | ||
xdg-open /tmp/coverage/index.html | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Handler for autoinstall feature from the admin UI of the quiz archiver plugin. | ||
* | ||
* @package quiz_archiver | ||
* @copyright 2024 Niels Gandraß <[email protected]> | ||
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
require_once(__DIR__.'/../../../../../config.php'); | ||
require_once("{$CFG->libdir}/moodlelib.php"); | ||
require_once("{$CFG->dirroot}/mod/quiz/report/archiver/classes/form/autoinstall_form.php"); | ||
|
||
use quiz_archiver\form\autoinstall_form; | ||
use quiz_archiver\local\autoinstall; | ||
|
||
/** @var bool Disables output buffering */ | ||
const NO_OUTPUT_BUFFERING = true; | ||
|
||
// Ensure user has permissions. | ||
require_login(); | ||
$ctx = context_system::instance(); | ||
require_capability('moodle/site:config', $ctx); | ||
|
||
// Setup page. | ||
$PAGE->set_context($ctx); | ||
$PAGE->set_url('/mod/quiz/report/archiver/adminui/autoinstall.php'); | ||
$title = get_string('autoinstall_plugin', 'quiz_archiver'); | ||
$PAGE->set_title($title); | ||
|
||
$returnlink = html_writer::link( | ||
new moodle_url('/admin/settings.php', ['section' => 'quiz_archiver_settings']), | ||
get_string('back') | ||
); | ||
|
||
echo $OUTPUT->header(); | ||
echo $OUTPUT->heading($title); | ||
|
||
// Content. | ||
if (autoinstall::plugin_is_unconfigured()) { | ||
$form = new autoinstall_form(); | ||
|
||
if ($form->is_cancelled()) { | ||
// Cancelled. | ||
echo '<p>'.get_string('autoinstall_cancelled', 'quiz_archiver').'</p>'; | ||
echo '<p>'.$returnlink.'</p>'; | ||
} else if ($data = $form->get_data()) { | ||
// Perform autoinstall. | ||
list($success, $log) = autoinstall::execute( | ||
$data->workerurl, | ||
$data->wsname, | ||
$data->rolename, | ||
$data->username | ||
); | ||
|
||
// Show result. | ||
echo '<p>'.get_string('autoinstall_started', 'quiz_archiver').'</p>'; | ||
echo '<p>'.get_string('logs').'</p>'; | ||
echo "<pre>{$log}</pre><br/>"; | ||
|
||
if ($success) { | ||
echo '<p>'.get_string('autoinstall_success', 'quiz_archiver').'</p>'; | ||
} else { | ||
echo '<p>'.get_string('autoinstall_failure', 'quiz_archiver').'</p>'; | ||
} | ||
|
||
echo '<p>'.$returnlink.'</p>'; | ||
} else { | ||
echo '<p>'.get_string('autoinstall_explanation', 'quiz_archiver').'</p>'; | ||
echo '<p>'.get_string('autoinstall_explanation_details', 'quiz_archiver').'</p>'; | ||
$form->display(); | ||
} | ||
} else { | ||
echo '<p>'.get_string('autoinstall_already_configured_long', 'quiz_archiver').'</p>'; | ||
echo '<p>'.$returnlink.'</p>'; | ||
} | ||
|
||
// End page. | ||
echo $OUTPUT->footer(); |
Oops, something went wrong.