Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix phpunit with Moodle 4.3 and PHP 8.2. #734

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions classes/modules/turnitin_quiz.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,13 @@ public function update_mark($attemptid, $identifier, $userid, $grade, $quizgrade
global $DB;

$transaction = $DB->start_delegated_transaction();
if (class_exists('\mod_quiz\quiz_attempt')) {
$quizattemptclass = '\mod_quiz\quiz_attempt';
} else {
$quizattemptclass = 'quiz_attempt';
}

$attempt = quiz_attempt::create($attemptid);
$attempt = $quizattemptclass::create($attemptid);
$quba = question_engine::load_questions_usage_by_activity($attempt->get_uniqueid());

// Loop through each question slot.
Expand All @@ -101,9 +106,15 @@ public function update_mark($attemptid, $identifier, $userid, $grade, $quizgrade
$update->sumgrades = $quba->get_total_mark();
$DB->update_record('quiz_attempts', $update);

quiz_save_best_grade($attempt->get_quiz(), $userid);
if (class_exists('\mod_quiz\grade_calculator')) {
// Support Moodle 4.3+.
$attempt->get_quizobj()->get_grade_calculator()->recompute_final_grade($userid);
} else {
// Support older Moodle versions.
quiz_save_best_grade($attempt->get_quiz(), $userid);
}

$transaction->allow_commit();
}

}
}
8 changes: 7 additions & 1 deletion tests/modules/turnitin_assign_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
*/
class plagiarism_turnitin_assign_testcase extends advanced_testcase {

/** @var stdClass created in setUp. */
protected $course;

/** @var stdClass created in setUp. */
protected $assign;

/**
* Create a course and assignment module instance
*/
Expand Down Expand Up @@ -105,4 +111,4 @@ public function test_check_is_resubmission_allowed_maxfiles_above_threshold() {
$resubmissionallowed = $moduleobject->is_resubmission_allowed($assign->id, 1, 'text_content', ASSIGN_ATTEMPT_REOPEN_METHOD_NONE);
$this->assertTrue($resubmissionallowed);
}
}
}
11 changes: 10 additions & 1 deletion tests/modules/turnitin_forum_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@
*/
class plagiarism_turnitin_forum_testcase extends advanced_testcase {

/** @var stdClass created in setUp. */
protected $forum;

/** @var stdClass created in setUp. */
protected $discussion;

/** @var stdClass created in setUp. */
protected $post;

/**
* Create a course and forum module instance
*/
Expand Down Expand Up @@ -99,4 +108,4 @@ public function test_to_check_content_from_database_is_returned_by_set_content_i
$this->assertEquals($content, $this->post->message);
}

}
}
16 changes: 12 additions & 4 deletions tests/modules/turnitin_quiz_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,15 @@ public function test_update_mark() {
'layout' => '1,0',
]);

$quizobj = quiz::create($quiz->id, $user->id);
if (class_exists('\mod_quiz\quiz_settings')) {
$quizsettingsclass = '\mod_quiz\quiz_settings';
$quizattemptclass = '\mod_quiz\quiz_attempt';
} else {
$quizsettingsclass = 'quiz';
$quizattemptclass = 'quiz_attempt';
}

$quizobj = $quizsettingsclass::create($quiz->id, $user->id);
$quba = question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj->get_context());
$quba->set_preferred_behaviour($quizobj->get_quiz()->preferredbehaviour);

Expand All @@ -69,11 +77,11 @@ public function test_update_mark() {
$attempt = quiz_create_attempt($quizobj, 1, false, $timenow, false, $user->id);
quiz_start_new_attempt($quizobj, $quba, $attempt, 1, $timenow);
quiz_attempt_save_started($quizobj, $quba, $attempt);
$attemptobj = quiz_attempt::create($attempt->id);
$attemptobj = $quizattemptclass::create($attempt->id);
$attemptobj->process_finish($timenow, false);

// Expect no marks or grade for the attempt yet.
$attemptobj = quiz_attempt::create($attempt->id);
$attemptobj = $quizattemptclass::create($attempt->id);
$this->assertEquals(0.0, $attemptobj->get_sum_marks());
$grade = quiz_get_best_grade($quiz, $user->id);
$this->assertEquals(0.0, $grade);
Expand All @@ -86,7 +94,7 @@ public function test_update_mark() {
$tiiquiz->update_mark($attempt->id, $identifier, $user->id, 75, $quiz->grade);

// Reload the attempt and check the total marks and grade are as we expect it.
$attemptobj = quiz_attempt::create($attempt->id);
$attemptobj = $quizattemptclass::create($attempt->id);
$this->assertEquals(0.75, $attemptobj->get_sum_marks());
$grade = quiz_get_best_grade($quiz, $user->id);
$this->assertEquals(75.0, $grade);
Expand Down