Merge branch 'MDL-81114_402' of https://github.com/timhunt/moodle into MOODLE_402_STABLE

This commit is contained in:
Andrew Nicols 2024-04-11 23:26:21 +08:00
commit 88290b1968
No known key found for this signature in database
GPG key ID: 6D1E3157C8CFBF14
2 changed files with 43 additions and 7 deletions

View file

@ -614,12 +614,10 @@ class question_finder implements cache_data_source {
$from = $from . " " . $join; $from = $from . " " . $join;
$where = "qbe.questioncategoryid {$qcsql} $where = "qbe.questioncategoryid {$qcsql}
AND q.parent = 0 AND q.parent = 0
AND qv.status = '$readystatus' AND qv.version = (SELECT MAX(version)
AND qv.version = (SELECT MAX(v.version)
FROM {question_versions} v FROM {question_versions} v
JOIN {question_bank_entries} be WHERE questionbankentryid = qbe.id
ON be.id = v.questionbankentryid AND status = '$readystatus')";
WHERE be.id = qbe.id)";
$params = $qcparams; $params = $qcparams;
if (!empty($tagids)) { if (!empty($tagids)) {

View file

@ -16,6 +16,9 @@
namespace core_question; namespace core_question;
use core_question\local\bank\question_version_status;
use core_question\local\bank\random_question_loader;
use core_question_generator;
use qubaid_list; use qubaid_list;
use question_bank; use question_bank;
use question_engine; use question_engine;
@ -24,8 +27,9 @@ use question_engine;
* Tests for the {@see core_question\local\bank\random_question_loader} class. * Tests for the {@see core_question\local\bank\random_question_loader} class.
* *
* @package core_question * @package core_question
* @copyright 2015 The Open University * @copyright 2015 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \core_question\local\bank\random_question_loader
*/ */
class random_question_loader_test extends \advanced_testcase { class random_question_loader_test extends \advanced_testcase {
@ -97,6 +101,40 @@ class random_question_loader_test extends \advanced_testcase {
$this->assertNull($loader->get_next_question_id($cat->id, 0)); $this->assertNull($loader->get_next_question_id($cat->id, 0));
} }
public function test_draft_questions_not_returned(): void {
$this->resetAfterTest();
$this->setAdminUser();
/** @var core_question_generator $questiongenerator */
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
// Create a question in draft state.
$category = $questiongenerator->create_question_category();
$questiongenerator->create_question('shortanswer', null,
['category' => $category->id, 'status' => question_version_status::QUESTION_STATUS_DRAFT]);
// Try to a random question from that category - should not be one.
$loader = new random_question_loader(new qubaid_list([]));
$this->assertNull($loader->get_next_question_id($category->id, false));
}
public function test_questions_with_later_draft_version_is_returned(): void {
$this->resetAfterTest();
$this->setAdminUser();
/** @var core_question_generator $questiongenerator */
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
// Create a question in draft state.
$category = $questiongenerator->create_question_category();
$question = $questiongenerator->create_question('shortanswer', null,
['questiontext' => 'V1', 'category' => $category->id]);
$questiongenerator->update_question($question, null,
['questiontext' => 'V2', 'status' => question_version_status::QUESTION_STATUS_DRAFT]);
// Try to a random question from that category - should get V1.
$loader = new random_question_loader(new qubaid_list([]));
$this->assertEquals($question->id, $loader->get_next_question_id($category->id, false));
}
public function test_one_question_category_returns_that_q_then_null() { public function test_one_question_category_returns_that_q_then_null() {
$this->resetAfterTest(); $this->resetAfterTest();
$generator = $this->getDataGenerator()->get_plugin_generator('core_question'); $generator = $this->getDataGenerator()->get_plugin_generator('core_question');