mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 08:55:15 +02:00
MDL-84303 qbank: fix recently viewed question tracking
This revealed some Unit tests with incorrect setup (trying to view a qestion bank in course context) so I fixed those.
This commit is contained in:
parent
f67105855c
commit
019e480c35
@ -54,10 +54,10 @@ Feature: Switching question bank when adding questions to a quiz
|
||||
And I should see "Test questions 3"
|
||||
|
||||
Scenario: Viewing question banks not in the current course show as recently accessed
|
||||
Given I am on the "qbank1" "Activity" page
|
||||
And I am on the "qbank2" "Activity" page
|
||||
And I am on the "qbank3" "Activity" page
|
||||
And I am on the "Quiz 1" "mod_quiz > Edit" page
|
||||
Given "teacher" has recently viewed the "qbank1" "qbank" question bank
|
||||
And "teacher" has recently viewed the "qbank2" "qbank" question bank
|
||||
And "teacher" has recently viewed the "qbank3" "qbank" question bank
|
||||
And "teacher" has recently viewed the "Quiz 1" "quiz" question bank
|
||||
When I open the "last" add to quiz menu
|
||||
And I follow "from question bank"
|
||||
And I click on "Switch bank" "button"
|
||||
|
@ -101,7 +101,7 @@ final class question_history_view_test extends \advanced_testcase {
|
||||
$course = $generator->create_course();
|
||||
$qbank = $generator->create_module('qbank', ['course' => $course->id]);
|
||||
$cm = get_coursemodule_from_id('qbank', $qbank->cmid);
|
||||
$context = \context_course::instance($course->id);
|
||||
$context = \context_module::instance($cm->id);
|
||||
|
||||
// Create a question in the default category.
|
||||
$contexts = new \core_question\local\bank\question_edit_contexts($context);
|
||||
|
@ -267,6 +267,9 @@ class view {
|
||||
$this->init_question_actions();
|
||||
$this->init_sort();
|
||||
$this->init_bulk_actions();
|
||||
|
||||
// Record that this question bank has been used.
|
||||
question_bank_helper::add_bank_context_to_recently_viewed($contexts->lowest());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -95,6 +95,5 @@ $category->id = $categoryid;
|
||||
$catcontext = context::instance_by_id($contextid);
|
||||
$event = question_category_viewed::create_from_question_category_instance($category, $catcontext);
|
||||
$event->trigger();
|
||||
\core_question\local\bank\question_bank_helper::add_bank_context_to_recently_viewed($catcontext);
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
|
@ -408,4 +408,36 @@ class behat_core_question extends behat_question_base {
|
||||
// Apply filters.
|
||||
$this->execute("behat_forms::press_button", [get_string('applyfilters')]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Record that a user has recently accessed the question bank related to a particular activity.
|
||||
*
|
||||
* @Given :user has recently viewed the :activityname :activitytype question bank
|
||||
* @param string $useridentifier The user's username or email.
|
||||
* @param string $activityname name of an activity.
|
||||
* @param string $activitytype type of an activity, e.g. 'quiz' or 'qbank'.
|
||||
*/
|
||||
public function user_has_recently_viewed_question_bank(
|
||||
string $useridentifier,
|
||||
string $activityname,
|
||||
string $activitytype,
|
||||
): void {
|
||||
global $USER;
|
||||
$originaluser = $USER;
|
||||
|
||||
if (!plugin_supports('mod', $activitytype, FEATURE_USES_QUESTIONS)) {
|
||||
throw new Exception($activitytype . ' do not have a question bank.');
|
||||
}
|
||||
|
||||
$user = $this->get_user_by_identifier($useridentifier);
|
||||
if (!$user) {
|
||||
throw new Exception('Unknow user ' . $useridentifier . '.');
|
||||
}
|
||||
$USER = $user;
|
||||
|
||||
$cm = $this->get_cm_by_activity_name($activitytype, $activityname);
|
||||
\core_question\local\bank\question_bank_helper::add_bank_context_to_recently_viewed($cm->context);
|
||||
|
||||
$USER = $originaluser;
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ final class question_bank_column_test extends \advanced_testcase {
|
||||
$qbank = $this->getDataGenerator()->create_module('qbank', ['course' => $course->id]);
|
||||
$cm = get_coursemodule_from_id('qbank', $qbank->cmid);
|
||||
$questionbank = new view(
|
||||
new question_edit_contexts(\context_course::instance($course->id)),
|
||||
new question_edit_contexts(\context_module::instance($cm->id)),
|
||||
new \moodle_url('/'),
|
||||
$course,
|
||||
$cm
|
||||
@ -82,7 +82,7 @@ final class question_bank_column_test extends \advanced_testcase {
|
||||
$qbank = $this->getDataGenerator()->create_module('qbank', ['course' => $course->id]);
|
||||
$cm = get_coursemodule_from_id('qbank', $qbank->cmid);
|
||||
$questionbank = new view(
|
||||
new question_edit_contexts(\context_course::instance($course->id)),
|
||||
new question_edit_contexts(\context_module::instance($cm->id)),
|
||||
new \moodle_url('/'),
|
||||
$course,
|
||||
$cm
|
||||
|
Loading…
x
Reference in New Issue
Block a user