Skip to content

Commit

Permalink
compat old/new class names
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippImhof committed Apr 25, 2024
1 parent 9c7c933 commit afbcb69
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ jobs:
- name: PHPUnit tests
if: ${{ always() }}
run: |
moodle-plugin-ci phpunit --fail-on-warning --coverage-clover
moodle-plugin-ci phpunit --fail-on-warning
8 changes: 3 additions & 5 deletions report.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@
// This work-around is required until Moodle 4.2 is the lowest version we support.
if (class_exists('\mod_quiz\local\reports\attempts_report')) {
class_alias('\mod_quiz\local\reports\attempts_report', '\quiz_essaydownload_report_parent_alias');
} else {
require_once($CFG->dirroot . '/mod/quiz/report/attemptsreport.php');
class_alias('\quiz_attempts_report', '\quiz_essaydownload_report_parent_alias');
}
if (class_exists('\mod_quiz\quiz_attempt')) {
class_alias('\mod_quiz\quiz_attempt', '\quiz_essaydownload_quiz_attempt_alias');
} else {
require_once($CFG->dirroot . '/mod/quiz/report/default.php');
require_once($CFG->dirroot . '/mod/quiz/report/attemptsreport.php');
require_once($CFG->dirroot . '/mod/quiz/attemptlib.php');
class_alias('\quiz_attempts_report', '\quiz_essaydownload_report_parent_alias');
class_alias('\quiz_attempt', '\quiz_essaydownload_quiz_attempt_alias');
}

Expand Down
20 changes: 14 additions & 6 deletions tests/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,16 @@
namespace quiz_essaydownload;

use advanced_testcase;
use mod_quiz\quiz_attempt;
use mod_quiz\quiz_settings;

defined('MOODLE_INTERNAL') || die();

// This work-around is required until Moodle 4.2 is the lowest version we support.
if (class_exists('\mod_quiz\quiz_settings')) {
class_alias('\mod_quiz\quiz_settings', '\quiz_essaydownload_quiz_settings_alias');
} else {
require_once($CFG->dirroot . '/mod/quiz/classes/plugininfo/quiz.php');
class_alias('\quiz', '\quiz_essaydownload_quiz_settings_alias');
}

/**
* Helper class providing some useful methods for Essay responses downloader plugin unit
Expand Down Expand Up @@ -87,7 +95,7 @@ public static function add_random_nonessay_question($questiongenerator, \stdClas
$questiongenerator->create_question('shortanswer', null, ['category' => $cat->id]);
$questiongenerator->create_question('shortanswer', null, ['category' => $cat->id]);

$quizobj = quiz_settings::create($quiz->id);
$quizobj = \quiz_essaydownload_quiz_settings_alias::create($quiz->id);
$structure = $quizobj->get_structure();
$filtercondition = [
'filter' => [
Expand All @@ -114,7 +122,7 @@ public static function add_random_essay_question($questiongenerator, \stdClass $
$questiongenerator->create_question('essay', null, ['category' => $cat->id]);
$questiongenerator->create_question('essay', null, ['category' => $cat->id]);

$quizobj = quiz_settings::create($quiz->id);
$quizobj = \quiz_essaydownload_quiz_settings_alias::create($quiz->id);
$structure = $quizobj->get_structure();
$filtercondition = [
'filter' => [
Expand Down Expand Up @@ -162,7 +170,7 @@ public static function start_attempt_at_quiz(\stdClass $quiz, \stdClass $user, $
advanced_testcase::setUser($user);

$starttime = time();
$quizobj = quiz_settings::create($quiz->id, $user->id);
$quizobj = \quiz_essaydownload_quiz_settings_alias::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 @@ -171,7 +179,7 @@ public static function start_attempt_at_quiz(\stdClass $quiz, \stdClass $user, $
$attempt = quiz_create_attempt($quizobj, $attemptnumber, null, $starttime, false, $user->id);
quiz_start_new_attempt($quizobj, $quba, $attempt, $attemptnumber, $starttime);
quiz_attempt_save_started($quizobj, $quba, $attempt);
$attemptobj = quiz_attempt::create($attempt->id);
$attemptobj = \quiz_essaydownload_quiz_attempt_alias::create($attempt->id);

advanced_testcase::setUser();

Expand Down

0 comments on commit afbcb69

Please sign in to comment.