Skip to content

Commit

Permalink
MDL-82587 mod_quiz: Add slot version updated event
Browse files Browse the repository at this point in the history
  • Loading branch information
cameron1729 committed Jul 26, 2024
1 parent 0114667 commit 8f38bc6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
2 changes: 0 additions & 2 deletions mod/quiz/classes/external/submit_question_version.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
use core_external\external_single_structure;
use core_external\external_value;
use mod_quiz\quiz_settings;
use mod_quiz\structure;
use stdClass;

/**
* External api for changing the question version in the quiz.
Expand Down
28 changes: 28 additions & 0 deletions mod/quiz/tests/event/events_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use mod_quiz\quiz_attempt;
use mod_quiz\quiz_settings;
use context_module;
use mod_quiz\external\submit_question_version;

/**
* Unit tests for quiz events.
Expand Down Expand Up @@ -68,6 +69,10 @@ protected function prepare_quiz() {
$saq = $questiongenerator->create_question('shortanswer', null, ['category' => $cat->id]);
$numq = $questiongenerator->create_question('numerical', null, ['category' => $cat->id]);

// Update the numq question so it has multiple versions. Needed to test
// the version updated event.
$questiongenerator->update_question($numq, null, ['name' => 'Second version of numq']);

// Add them to the quiz.
quiz_add_quiz_question($saq->id, $quiz);
quiz_add_quiz_question($numq->id, $quiz);
Expand Down Expand Up @@ -1202,6 +1207,29 @@ public function test_slot_mark_updated(): void {
$this->assertEventContextNotUsed($event);
}

/**
* Test the slot version updated event.
*
* @covers \mod_quiz\external\submit_question_version
*/
public function test_slot_version_updated(): void {
$quizobj = $this->prepare_quiz();
$this->setAdminUser();

$quizobj->preload_questions();
[, $numqslotid] = array_column($quizobj->get_questions(null, false), 'slotid');

$sink = $this->redirectEvents();
submit_question_version::execute($numqslotid, 2);
$events = $sink->get_events();
$event = reset($events);

// Check that the event data is valid.
$this->assertInstanceOf('\mod_quiz\event\slot_version_updated', $event);
$this->assertEquals($quizobj->get_context(), $event->get_context());
$this->assertEventContextNotUsed($event);
}

/**
* Test quiz_grade_item_created.
*
Expand Down

0 comments on commit 8f38bc6

Please sign in to comment.