Skip to content

Commit

Permalink
Merge branch 'develop' into feature/mkdocs
Browse files Browse the repository at this point in the history
  • Loading branch information
ngandrass committed Oct 8, 2024
2 parents b76e2df + 1eea191 commit 09d19a6
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 61 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Create an official Quiz Archiver documentation website: [https://quizarchiver.gandrass.de/](https://quizarchiver.gandrass.de/)
- Automate building and deployment of documentation website
- Cleanup and restructure existing documentation within README
- Add demo quiz archive worker information to admin settings page
- Fix PHP warning on autoinstall admin page


Expand Down
2 changes: 1 addition & 1 deletion lang/de/quiz_archiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@
$string['setting_webservice_userid'] = 'Webservice Nutzer-ID';
$string['setting_webservice_userid_desc'] = 'User-ID des Moodle Nutzers, der vom Archive Worker Service genutzt wird, um auf Testdaten zuzugreifen. Er muss alle Berechtigungen besitzen, die in der <a href="https://quizarchiver.gandrass.de/configuration/initialconfig/manual" target="_blank">Dokumentation</a> aufgelistet sind, um korrekt zu funktionieren. Aus Sicherheitsgründen sollte dies ein dedizierter Nutzer ohne globale Administrationsrechte sein.';
$string['setting_worker_url'] = 'Archive Worker URL';
$string['setting_worker_url_desc'] = 'URL des Archive Worker Services, der für die Ausführung von Archivierungsaufträgen genutzt wird.<br/>Beispiel: <code>http://127.0.0.1:8080</code> oder <code>http://moodle-quiz-archive-worker:8080</code>';
$string['setting_worker_url_desc'] = 'URL des Archive Worker Services, der für die Ausführung von Archivierungsaufträgen genutzt wird. Wenn Sie den Quiz Archiver lediglich ausprobieren wollen, können Sie vorerst auch den <a href="https://quizarchiver.gandrass.de/installation/archiveworker/#using-the-free-public-demo-service" target="_blank">kostenfreien öffentlichen Archive Worker Service</a> nutzen. <br/>Beispiel: <code>http://127.0.0.1:8080</code> oder <code>http://moodle-quiz-archive-worker:8080</code>';

// Errors.
$string['error_worker_connection_failed'] = 'Verbindung zum Archive Worker fehlgeschlagen.';
Expand Down
2 changes: 1 addition & 1 deletion lang/en/quiz_archiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@
$string['setting_webservice_userid'] = 'Web service user-ID';
$string['setting_webservice_userid_desc'] = 'User-ID of the Moodle user that is used by the archive worker service to access quiz data. It must have all capabilities that are listed in the <a href="https://quizarchiver.gandrass.de/configuration/initialconfig/manual" target="_blank">documentation</a> to work properly. For security reasons, this should be a dedicated user account without full administrative privileges.';
$string['setting_worker_url'] = 'Archive worker URL';
$string['setting_worker_url_desc'] = 'URL of the archive worker service to call for quiz archive task execution.<br/>Example: <code>http://127.0.0.1:8080</code> or <code>http://moodle-quiz-archive-worker:8080</code>';
$string['setting_worker_url_desc'] = 'URL of the archive worker service to call for quiz archive task execution. If you only want to try the Quiz Archiver, you can use the <a href="https://quizarchiver.gandrass.de/installation/archiveworker/#using-the-free-public-demo-service" target="_blank">free public demo quiz archive worker service</a>, eliminating the need to set up your own worker service right away.<br/>Example: <code>http://127.0.0.1:8080</code> or <code>http://moodle-quiz-archive-worker:8080</code>';

// Errors.
$string['error_worker_connection_failed'] = 'Establishing a connection to the archive worker failed.';
Expand Down
69 changes: 41 additions & 28 deletions tests/external/get_backup_status_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ public function test_assure_return_parameter_spec(): void {
* @covers \quiz_archiver\external\get_backup_status::execute
* @covers \quiz_archiver\external\get_backup_status::validate_parameters
*
* @param string $jobid Job ID
* @param string $backupid Backup ID
* @param string|null $jobid Job ID to check
* @param string|null $backupid Backup ID to check
* @param bool $shouldfail Whether a failure is expected
* @return void
* @throws \coding_exception
Expand All @@ -123,17 +123,37 @@ public function test_assure_return_parameter_spec(): void {
* @throws \required_capability_exception
*/
public function test_parameter_validation(
string $jobid,
string $backupid,
bool $shouldfail
?string $jobid,
?string $backupid,
bool $shouldfail
): void {
// Gain webservice permission.
$this->setAdminUser();

// Create mock quiz.
$this->resetAfterTest();
$mocks = $this->getDataGenerator()->create_mock_quiz();
$job = ArchiveJob::create(
'20000000-1234-5678-abcd-ef4242424242',
$mocks->course->id,
$mocks->quiz->cmid,
$mocks->quiz->id,
$mocks->user->id,
null,
'TEST-WS-TOKEN',
[],
[]
);
$_GET['wstoken'] = 'TEST-WS-TOKEN';

if ($shouldfail) {
$this->expectException(\invalid_parameter_exception::class);
}

get_backup_status::execute($jobid, $backupid);
get_backup_status::execute(
$jobid === null ? $job->get_jobid() : $jobid,
$backupid === null ? 'f1d2d2f924e986ac86fdf7b36c94bcdf32beec15' : $backupid
);
}

/**
Expand All @@ -144,29 +164,22 @@ public function test_parameter_validation(
* @throws \moodle_exception
*/
public static function parameter_data_provider(): array {
// Create job.
$self = new self();
$mocks = $self->getDataGenerator()->create_mock_quiz();
$job = ArchiveJob::create(
'20000000-1234-5678-abcd-ef4242424242',
$mocks->course->id,
$mocks->quiz->cmid,
$mocks->quiz->id,
$mocks->user->id,
null,
'TEST-WS-TOKEN',
[],
[]
);
$base = [
'jobid' => $job->get_jobid(),
'backupid' => 'f1d2d2f924e986ac86fdf7b36c94bcdf32beec15',
];

return [
'Valid' => array_merge($base, ['shouldfail' => false]),
'Invalid jobid' => array_merge($base, ['jobid' => '<a href="localhost">Foo</a>', 'shouldfail' => true]),
'Invalid backupid' => array_merge($base, ['backupid' => '<a href="localhost">Bar</a>', 'shouldfail' => true]),
'Valid' => array_merge([
'jobid' => null,
'backupid' => null,
'shouldfail' => false,
]),
'Invalid jobid' => array_merge([
'jobid' => '<a href="localhost">Foo</a>',
'backupid' => null,
'shouldfail' => true,
]),
'Invalid backupid' => array_merge([
'jobid' => null,
'backupid' => '<a href="localhost">Bar</a>',
'shouldfail' => true,
]),
];
}

Expand Down
76 changes: 45 additions & 31 deletions tests/external/process_uploaded_artifact_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,15 @@ public function test_wstoken_write_access_check(): void {
* @covers \quiz_archiver\external\process_uploaded_artifact::execute
* @covers \quiz_archiver\external\process_uploaded_artifact::validate_parameters
*
* @param string $jobid Job ID
* @param string $artifactcomponent Component name
* @param int $artifactcontextid Context ID
* @param int $artifactuserid User ID
* @param string $artifactfilearea File area name
* @param string $artifactfilename File name
* @param string $artifactfilepath File path
* @param int $artifactitemid Item ID
* @param string $artifactsha256sum SHA256 checksum
* @param string|null $jobid Job ID
* @param string|null $artifactcomponent Component name
* @param int|null $artifactcontextid Context ID
* @param int|null $artifactuserid User ID
* @param string|null $artifactfilearea File area name
* @param string|null $artifactfilename File name
* @param string|null $artifactfilepath File path
* @param int|null $artifactitemid Item ID
* @param string|null $artifactsha256sum SHA256 checksum
* @param bool $shouldfail Whether a failure is expected
* @return void
* @throws \coding_exception
Expand All @@ -213,33 +213,36 @@ public function test_wstoken_write_access_check(): void {
* @throws \required_capability_exception
*/
public function test_parameter_validation(
string $jobid,
string $artifactcomponent,
int $artifactcontextid,
int $artifactuserid,
string $artifactfilearea,
string $artifactfilename,
string $artifactfilepath,
int $artifactitemid,
string $artifactsha256sum,
bool $shouldfail
?string $jobid,
?string $artifactcomponent,
?int $artifactcontextid,
?int $artifactuserid,
?string $artifactfilearea,
?string $artifactfilename,
?string $artifactfilepath,
?int $artifactitemid,
?string $artifactsha256sum,
bool $shouldfail
): void {
// Create mock quiz.
$this->resetAfterTest();
$mocks = $this->getDataGenerator()->create_mock_quiz();
$base = $this->generate_valid_request('xxx', $mocks->quiz->cmid, $mocks->user->id);

if ($shouldfail) {
$this->expectException(\invalid_parameter_exception::class);
}

process_uploaded_artifact::execute(
$jobid,
$artifactcomponent,
$artifactcontextid,
$artifactuserid,
$artifactfilearea,
$artifactfilename,
$artifactfilepath,
$artifactitemid,
$artifactsha256sum
$jobid === null ? $base['jobid'] : $jobid,
$artifactcomponent === null ? $base['artifact_component'] : $artifactcomponent,
$artifactcontextid === null ? $base['artifact_contextid'] : $artifactcontextid,
$artifactuserid === null ? $base['artifact_userid'] : $artifactuserid,
$artifactfilearea === null ? $base['artifact_filearea'] : $artifactfilearea,
$artifactfilename === null ? $base['artifact_filename'] : $artifactfilename,
$artifactfilepath === null ? $base['artifact_filepath'] : $artifactfilepath,
$artifactitemid === null ? $base['artifact_itemid'] : $artifactitemid,
$artifactsha256sum === null ? $base['artifact_sha256sum'] : $artifactsha256sum
);
}

Expand All @@ -249,9 +252,20 @@ public function test_parameter_validation(
* @return array[] Test data
*/
public static function parameter_data_provider(): array {
$self = new self();
$mocks = $self->getDataGenerator()->create_mock_quiz();
$base = $self->generate_valid_request('xxx', $mocks->quiz->cmid, $mocks->user->id);
// Create base data (no modification).
$base = [
"jobid" => null,
"artifact_component" => null,
"artifact_contextid" => null,
"artifact_userid" => null,
"artifact_filearea" => null,
"artifact_filename" => null,
"artifact_filepath" => null,
"artifact_itemid" => null,
"artifact_sha256sum" => null,
];

// Define test datasets.
return [
'Valid' => array_merge($base, [
'shouldfail' => false,
Expand Down

0 comments on commit 09d19a6

Please sign in to comment.