diff --git a/server/moodle/mod/livequiz/classes/models/livequiz_questions_lecturer_relation.php b/server/moodle/mod/livequiz/classes/models/livequiz_questions_lecturer_relation.php index ccba01c9a..1120bfdd0 100644 --- a/server/moodle/mod/livequiz/classes/models/livequiz_questions_lecturer_relation.php +++ b/server/moodle/mod/livequiz/classes/models/livequiz_questions_lecturer_relation.php @@ -87,7 +87,7 @@ public static function get_lecturer_questions_relation_by_id(int $id): array { /** * - * Deletes lecturer_questions_relation by the relation id + * Deletes lecturer_questions_relation by the question id * * * @param int $id @@ -96,8 +96,8 @@ public static function get_lecturer_questions_relation_by_id(int $id): array { * @throws dml_transaction_exception * */ - public static function delete_lecturer_questions_relation_by_id(int $id): void { + public static function delete_lecturer_questions_relation_by_question_id(int $id): void { global $DB; - $DB->delete_records('livequiz_questions_lecturer', ['id' => $id]); + $DB->delete_records('livequiz_questions_lecturer', ['question_id' => $id]); } } diff --git a/server/moodle/mod/livequiz/classes/services/livequiz_services.php b/server/moodle/mod/livequiz/classes/services/livequiz_services.php index aa6a2f8f9..5079a3b4e 100644 --- a/server/moodle/mod/livequiz/classes/services/livequiz_services.php +++ b/server/moodle/mod/livequiz/classes/services/livequiz_services.php @@ -384,10 +384,10 @@ private static function delete_question(int $questionid): void { $answers = questions_answers_relation::get_answers_from_question($questionid); foreach ($answers as $answer) { $currentanswerid = $answer->get_id(); - self::delete_answer($currentanswerid, $questionid); + self::delete_answer($currentanswerid); } quiz_questions_relation::delete_question_quiz_relation($questionid); - livequiz_questions_lecturer_relation::delete_lecturer_questions_relation_by_id($questionid); + livequiz_questions_lecturer_relation::delete_lecturer_questions_relation_by_question_id($questionid); question::delete_question($questionid); } diff --git a/server/moodle/mod/livequiz/tests/phpunit/livequiz_service_test.php b/server/moodle/mod/livequiz/tests/phpunit/livequiz_service_test.php index c6f7ce2fe..64f17ba5a 100644 --- a/server/moodle/mod/livequiz/tests/phpunit/livequiz_service_test.php +++ b/server/moodle/mod/livequiz/tests/phpunit/livequiz_service_test.php @@ -472,7 +472,7 @@ public function test_delete_question(): void { } /** - * Test that deleting a question, with a relation, throws. + * Test that deleting a question, with a relation, throws an exception. * * @covers \mod_livequiz\services\livequiz_services::submit_quiz * @throws dml_exception @@ -500,9 +500,11 @@ public function test_delete_question_throws_if_relation_exist(): void { array_shift($testquizsubmittedquestions); $testquizsubmitted->set_questions($testquizsubmittedquestions); + // This sets up the test to expect the exception later in the code. $this->expectException(dml_exception::class); $this->expectExceptionMessage('error/Cannot delete answer with participations'); + // This is the actual test where the exception is thrown. $service->submit_quiz($testquizsubmitted, $lecturerid); $testquizresubmittedquestions = $testquizsubmitted->get_questions(); }