Skip to content

Commit

Permalink
Merge branch 'MDL-79466_master' of https://github.com/marxjohnson/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
snake committed Oct 4, 2023
2 parents 5fec728 + 7daa40f commit e430e16
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 7 deletions.
6 changes: 5 additions & 1 deletion question/bank/history/classes/helper.php
Expand Up @@ -32,14 +32,18 @@ class helper {
* @param int $entryid id of the question entry
* @param string $returnrul url of the page to return to
* @param int $courseid id of the course
* @param ?string $filter filter param to pass to the History view
* @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 = [
'entryid' => $entryid,
'returnurl' => $returnrul,
'courseid' => $courseid
];
if (!is_null($filter)) {
$params['filter'] = $filter;
}

return new \moodle_url('/question/bank/history/history.php', $params);
}
Expand Down
8 changes: 6 additions & 2 deletions question/bank/history/classes/history_action.php
Expand Up @@ -45,8 +45,12 @@ protected function get_url_icon_and_label(\stdClass $question): array {
}

if (question_has_capability_on($question, 'use')) {
$url = helper::question_history_url($question->questionbankentryid, $this->qbank->returnurl,
$this->qbank->course->id);
$url = helper::question_history_url(
$question->questionbankentryid,
$this->qbank->returnurl,
$this->qbank->course->id,
$this->qbank->base_url()->param('filter'),
);
return [$url, 't/log', $this->strpreview];
}

Expand Down
11 changes: 11 additions & 0 deletions question/bank/history/classes/question_history_view.php
Expand Up @@ -177,4 +177,15 @@ public function is_listing_specific_versions(): bool {
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();
}

}
18 changes: 16 additions & 2 deletions question/bank/history/tests/behat/question_history_action.feature
Expand Up @@ -38,8 +38,22 @@ Feature: Use the qbank plugin manager page for question history
And I should see "Created by"
And I should see "First question"
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
Scenario: Delete question from the history using Edit question menu
Expand Down
32 changes: 30 additions & 2 deletions question/bank/history/tests/helper_test.php
Expand Up @@ -77,14 +77,42 @@ public function setUp(): void {
*/
public function test_question_history_url() {
$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 = [
'entryid' => $this->questiondata->questionbankentryid,
'returnurl' => $this->returnurl,
'courseid' => $this->courseid
'courseid' => $this->courseid,
'filter' => $filter,
];
$expectedurl = new \moodle_url('/question/bank/history/history.php', $params);
$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);
}
}

0 comments on commit e430e16

Please sign in to comment.