Skip to content

Commit

Permalink
MDL-82875 question export: test for not exporting hidden questions
Browse files Browse the repository at this point in the history
  • Loading branch information
timhunt committed Sep 13, 2024
1 parent 846e242 commit 4674871
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions question/format/aiken/tests/qformat_aiken_export_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

use core_question\local\bank\question_version_status;

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

global $CFG;
Expand All @@ -35,6 +37,7 @@
*
* @copyright 2018 Jean-Michel vedrine)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \qformat_aiken
*/
class qformat_aiken_export_test extends advanced_testcase {
/**
Expand Down Expand Up @@ -113,4 +116,44 @@ public function test_export_multiline_question(): void {
EOT;
$this->assert_same_aiken($expectedoutput, $exporter->exportprocess());
}

public function test_hidden_question_not_exported(): void {
$this->resetAfterTest();
$this->setAdminUser();

// Create a new course category and a new course in that.
$category = $this->getDataGenerator()->create_category();
$course = $this->getDataGenerator()->create_course(['category' => $category->id]);
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
$context = context_coursecat::instance($category->id);
$cat = $generator->create_question_category(['contextid' => $context->id]);

// Create a visible and a hidden question.
$generator->create_question('multichoice', 'one_of_four', [
'category' => $cat->id,
'questiontext' => ['text' => 'This question is the visible one.', 'format' => FORMAT_HTML],
]);
$generator->create_question('multichoice', 'one_of_four', [
'category' => $cat->id,
'questiontext' => ['text' => 'This question is the hidden one.', 'format' => FORMAT_HTML],
'status' => question_version_status::QUESTION_STATUS_HIDDEN,
]);

// Prepared the expected result.
$expectedoutput = <<<EOT
This question is the visible one.
A) One
B) Two
C) Three
D) Four
ANSWER: A
EOT;

// Do the export and verify.
$exporter = new qformat_aiken();
$exporter->category = $cat;
$exporter->setCourse($course);
$this->assert_same_aiken($expectedoutput, $exporter->exportprocess());
}
}

0 comments on commit 4674871

Please sign in to comment.