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 080b20b commit e13a9ef
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 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 Down Expand Up @@ -111,4 +113,44 @@ public function test_export_multiline_question() {
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 e13a9ef

Please sign in to comment.