Skip to content

Commit

Permalink
Fix PHPUnit failure
Browse files Browse the repository at this point in the history
  • Loading branch information
danghieu1407 authored and AnupamaSarjoshi committed Feb 19, 2025
1 parent e5b5e50 commit 9a61f9b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 25 deletions.
16 changes: 8 additions & 8 deletions tests/backup_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static function backup_test_data_provider(): array {
'coursefullname' => 'before upgrade feedback column',
'courseshortname' => 'bufc',
'questionname' => 'crossword-001',
'words' => [
'expectedwords' => [
[
'clue' => 'where is the Christ the Redeemer statue located in?',
'clueformat' => FORMAT_HTML,
Expand Down Expand Up @@ -116,7 +116,7 @@ public static function backup_test_data_provider(): array {
'coursefullname' => 'after upgrade feedback column',
'courseshortname' => 'aufc',
'questionname' => 'crossword-001',
'words' => [
'expectedwords' => [
[
'clue' => '<p>where is the Christ the Redeemer statue located in?</p>',
'clueformat' => FORMAT_HTML,
Expand Down Expand Up @@ -146,7 +146,7 @@ public static function backup_test_data_provider(): array {
'coursefullname' => 'before upgrade feedback column 3.11',
'courseshortname' => 'bufc311',
'questionname' => 'crossword-001',
'words' => [
'expectedwords' => [
[
'clue' => 'where is the Christ the Redeemer statue located in?',
'clueformat' => FORMAT_HTML,
Expand Down Expand Up @@ -176,7 +176,7 @@ public static function backup_test_data_provider(): array {
'coursefullname' => 'Crossword in Quiz with image files in editor fields',
'courseshortname' => 'cwwf',
'questionname' => 'Crossword with image files',
'words' => [
'expectedwords' => [
[
'clue' => 'Clue with image',
'clueformat' => FORMAT_HTML,
Expand Down Expand Up @@ -302,16 +302,16 @@ public static function backup_restore_course_with_cw_test_provider(): array {

return [
'Normal crossword' => [
'template' => 'normal',
'crosswordtemplate' => 'normal',
],
'Crossword with accent grade type is strict' => [
'template' => 'not_accept_wrong_accents',
'crosswordtemplate' => 'not_accept_wrong_accents',
],
'Crossword with accent grade type is penalty' => [
'template' => 'accept_wrong_accents_but_subtract_point',
'crosswordtemplate' => 'accept_wrong_accents_but_subtract_point',
],
'Crossword with accent grade type is ignore' => [
'template' => 'accept_wrong_accents_but_not_subtract_point',
'crosswordtemplate' => 'accept_wrong_accents_but_not_subtract_point',
],
];
}
Expand Down
15 changes: 10 additions & 5 deletions tests/form_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,16 @@ public function prepare_test_data(): array {
$this->setAdminUser();
$gen = $this->getDataGenerator();
$course = $gen->create_course();
$context = \context_course::instance($course->id);

$contexts = qtype_crossword_test_helper::question_edit_contexts($context);
$category = question_make_default_categories($contexts->all());

if (qtype_crossword_test_helper::plugin_is_installed('mod_qbank')) {
$qbank = $gen->create_module('qbank', ['course' => $course->id]);
$context = \context_module::instance($qbank->cmid);
$contexts = qtype_crossword_test_helper::question_edit_contexts($context);
$category = question_get_default_category($context->id, true);
} else {
// TODO: remove this once Moodle 5.0 is the lowest supported version.
$contexts = new \core_question\local\bank\question_edit_contexts(\context_course::instance($course->id));
$category = question_make_default_categories($contexts->all());
}
$question = new \stdClass();
$question->category = $category->id;
$question->contextid = $category->contextid;
Expand Down
14 changes: 14 additions & 0 deletions tests/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -817,4 +817,18 @@ private function set_multiple_tries_for_form_data(stdClass $fromform, float $pen
$fromform->hintoptions = [1, 1];
return $fromform;
}

/**
* Checks if given plugin is installed.
*
* @param string $plugin frankenstyle plugin name, e.g. 'mod_qbank'.
* @return bool
*/
public static function plugin_is_installed(string $plugin): bool {
$path = core_component::get_component_directory($plugin);
if (!is_readable($path . '/version.php')) {
return false;
}
return true;
}
}
24 changes: 12 additions & 12 deletions tests/question_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,95 +421,95 @@ public static function calculate_fraction_for_answer_test_provider(): array {
'accentoption' => \qtype_crossword::ACCENT_GRADING_STRICT,
'accentpenalty' => 0,
],
'fraction' => [1, 1],
'expectedfractions' => [1, 1],
],
'Wrong accents are not accepted and 1 correct answer and 1 wrong accents answer.' => [
'inputoptions' => [
'response' => ['PATE', 'TÉLÉPHONE'],
'accentoption' => \qtype_crossword::ACCENT_GRADING_STRICT,
'accentpenalty' => 0,
],
'fraction' => [0, 1],
'expectedfractions' => [0, 1],
],
'Wrong accents are not accepted and both answer are wrong accents.' => [
'inputoptions' => [
'response' => ['PATE', 'TELEPHONE'],
'accentoption' => \qtype_crossword::ACCENT_GRADING_STRICT,
'accentpenalty' => 0,
],
'fraction' => [0, 0],
'expectedfractions' => [0, 0],
],
'Wrong accents are not accepted and both answers are wrong.' => [
'inputoptions' => [
'response' => ['PETE', 'TALAPHONE'],
'accentoption' => \qtype_crossword::ACCENT_GRADING_STRICT,
'accentpenalty' => 0,
],
'fraction' => [0, 0],
'expectedfractions' => [0, 0],
],
'Accept wrong accents but points will be deducted and answers are absolutely correct.' => [
'inputoptions' => [
'response' => ['PÂTÉ', 'TÉLÉPHONE'],
'accentoption' => \qtype_crossword::ACCENT_GRADING_PENALTY,
'accentpenalty' => 0.5,
],
'fraction' => [1, 1],
'expectedfractions' => [1, 1],
],
'Accept wrong accents but points will be deducted and one answer is wrong accents.' => [
'inputoptions' => [
'response' => ['PATE', 'TÉLÉPHONE'],
'accentoption' => \qtype_crossword::ACCENT_GRADING_PENALTY,
'accentpenalty' => 0.5,
],
'fraction' => [0.5, 1],
'expectedfractions' => [0.5, 1],
],
'Accept wrong accents but points will be deducted and both answer are wrong accents.' => [
'inputoptions' => [
'response' => ['PATE', 'TELEPHONE'],
'accentoption' => \qtype_crossword::ACCENT_GRADING_PENALTY,
'accentpenalty' => 0.5,
],
'fraction' => [0.5, 0.5],
'expectedfractions' => [0.5, 0.5],
],
'Accept wrong accents but points will be deducted and both answer are wrong' => [
'inputoptions' => [
'response' => ['PETE', 'TALAPHONE'],
'accentoption' => \qtype_crossword::ACCENT_GRADING_PENALTY,
'accentpenalty' => 0.5,
],
'fraction' => [0, 0],
'expectedfractions' => [0, 0],
],
'Accept wrong accents and answers are absolutely correct.' => [
'inputoptions' => [
'response' => ['PÂTÉ', 'TÉLÉPHONE'],
'accentoption' => \qtype_crossword::ACCENT_GRADING_IGNORE,
'accentpenalty' => 0.5,
],
'fraction' => [1, 1],
'expectedfractions' => [1, 1],
],
'Accept wrong accents and one answer is wrong accents.' => [
'inputoptions' => [
'response' => ['PATE', 'TÉLÉPHONE'],
'accentoption' => \qtype_crossword::ACCENT_GRADING_IGNORE,
'accentpenalty' => 0.5,
],
'fraction' => [1, 1],
'expectedfractions' => [1, 1],
],
'Accept wrong accents and both answer are wrong accents.' => [
'inputoptions' => [
'response' => ['PATE', 'TELEPHONE'],
'accentoption' => \qtype_crossword::ACCENT_GRADING_IGNORE,
'accentpenalty' => 0.5,
],
'fraction' => [1, 1],
'expectedfractions' => [1, 1],
],
'Accept wrong accents and both answer are wrong' => [
'inputoptions' => [
'response' => ['PETE', 'TALAPHONE'],
'accentoption' => \qtype_crossword::ACCENT_GRADING_IGNORE,
'accentpenalty' => 0.5,
],
'fraction' => [0, 0],
'expectedfractions' => [0, 0],
],
];
}
Expand Down

0 comments on commit 9a61f9b

Please sign in to comment.