Merge branch 'MDL-79466_master' of https://github.com/marxjohnson/moodle

This commit is contained in:
Jake Dallimore 2023-10-04 10:21:08 +08:00
commit e430e16c44
No known key found for this signature in database
5 changed files with 68 additions and 7 deletions

View File

@ -32,14 +32,18 @@ class helper {
* @param int $entryid id of the question entry * @param int $entryid id of the question entry
* @param string $returnrul url of the page to return to * @param string $returnrul url of the page to return to
* @param int $courseid id of the course * @param int $courseid id of the course
* @param ?string $filter filter param to pass to the History view
* @return \moodle_url * @return \moodle_url
*/ */
public static function question_history_url(int $entryid, string $returnrul, int $courseid): \moodle_url { public static function question_history_url(int $entryid, string $returnrul, int $courseid, ?string $filter): \moodle_url {
$params = [ $params = [
'entryid' => $entryid, 'entryid' => $entryid,
'returnurl' => $returnrul, 'returnurl' => $returnrul,
'courseid' => $courseid 'courseid' => $courseid
]; ];
if (!is_null($filter)) {
$params['filter'] = $filter;
}
return new \moodle_url('/question/bank/history/history.php', $params); return new \moodle_url('/question/bank/history/history.php', $params);
} }

View File

@ -45,8 +45,12 @@ class history_action extends question_action_base {
} }
if (question_has_capability_on($question, 'use')) { if (question_has_capability_on($question, 'use')) {
$url = helper::question_history_url($question->questionbankentryid, $this->qbank->returnurl, $url = helper::question_history_url(
$this->qbank->course->id); $question->questionbankentryid,
$this->qbank->returnurl,
$this->qbank->course->id,
$this->qbank->base_url()->param('filter'),
);
return [$url, 't/log', $this->strpreview]; return [$url, 't/log', $this->strpreview];
} }

View File

@ -177,4 +177,15 @@ class question_history_view extends view {
return true; return true;
} }
/**
* Override wanted_filters so that we apply the filters provided by the URL, but don't display the filter UI.
*
* @return void
*/
public function wanted_filters(): void {
$this->display_question_bank_header();
// Add search conditions.
$this->add_standard_search_conditions();
}
} }

View File

@ -38,8 +38,22 @@ Feature: Use the qbank plugin manager page for question history
And I should see "Created by" And I should see "Created by"
And I should see "First question" And I should see "First question"
And the "History" action should not exist for the "First question" question in the question bank And the "History" action should not exist for the "First question" question in the question bank
And I click on "#qbank-history-close" "css_element"
And the "History" action should exist for the "First question" question in the question bank @javascript
Scenario: Viewing history for a question in a non-default category
Given the following "question categories" exist:
| contextlevel | reference | name |
| Course | C1 | Test questions 2 |
And the following "questions" exist:
| questioncategory | qtype | name | questiontext |
| Test questions 2 | truefalse | Second question | Answer the second question |
And I am on the "Test quiz" "mod_quiz > question bank" page logged in as "admin"
And I apply question bank filter "Category" with value "Test questions 2"
And I choose "History" action for "Second question" in the question bank
Then I should see "Question history"
And "Filter 1" "fieldset" should not exist
And I should see "Second question"
And "Second question" "table_row" should exist
@javascript @javascript
Scenario: Delete question from the history using Edit question menu Scenario: Delete question from the history using Edit question menu

View File

@ -77,14 +77,42 @@ class helper_test extends \advanced_testcase {
*/ */
public function test_question_history_url() { public function test_question_history_url() {
$this->resetAfterTest(); $this->resetAfterTest();
$actionurl = helper::question_history_url($this->questiondata->questionbankentryid, $this->returnurl, $this->courseid); $filter = urlencode('filters[]');
$actionurl = helper::question_history_url(
$this->questiondata->questionbankentryid,
$this->returnurl,
$this->courseid,
$filter,
);
$params = [ $params = [
'entryid' => $this->questiondata->questionbankentryid, 'entryid' => $this->questiondata->questionbankentryid,
'returnurl' => $this->returnurl, 'returnurl' => $this->returnurl,
'courseid' => $this->courseid 'courseid' => $this->courseid,
'filter' => $filter,
]; ];
$expectedurl = new \moodle_url('/question/bank/history/history.php', $params); $expectedurl = new \moodle_url('/question/bank/history/history.php', $params);
$this->assertEquals($expectedurl, $actionurl); $this->assertEquals($expectedurl, $actionurl);
} }
/**
* Test the history action url when the filter parameter is null.
*
* @covers ::question_history_url
*/
public function test_question_history_url_null_filter() {
$this->resetAfterTest();
$actionurl = helper::question_history_url(
$this->questiondata->questionbankentryid,
$this->returnurl,
$this->courseid,
null,
);
$params = [
'entryid' => $this->questiondata->questionbankentryid,
'returnurl' => $this->returnurl,
'courseid' => $this->courseid,
];
$expectedurl = new \moodle_url('/question/bank/history/history.php', $params);
$this->assertEquals($expectedurl, $actionurl);
}
} }