diff --git a/question/bank/history/classes/question_history_view.php b/question/bank/history/classes/question_history_view.php index 6d672de2c0d..7824ca51e6a 100644 --- a/question/bank/history/classes/question_history_view.php +++ b/question/bank/history/classes/question_history_view.php @@ -175,7 +175,7 @@ class question_history_view extends view { * Display the header for the question bank in the history page to include question name and type. */ public function display_question_bank_header(): void { - global $PAGE, $DB; + global $PAGE, $DB, $OUTPUT; $sql = 'SELECT q.* FROM {question} q JOIN {question_versions} qv ON qv.questionid = q.id @@ -187,13 +187,19 @@ class question_history_view extends view { WHERE be.id = qbe.id) AND qbe.id = ?'; $latestquestiondata = $DB->get_record_sql($sql, [$this->entryid]); - $historydata = [ - 'questionname' => $latestquestiondata->name, - 'returnurl' => $this->basereturnurl, - 'questionicon' => print_question_icon($latestquestiondata) - ]; - // Header for the page before the actual form from the api. - echo $PAGE->get_renderer('qbank_history')->render_history_header($historydata); + if ($latestquestiondata) { + $historydata = [ + 'questionname' => $latestquestiondata->name, + 'returnurl' => $this->basereturnurl, + 'questionicon' => print_question_icon($latestquestiondata) + ]; + // Header for the page before the actual form from the api. + echo $PAGE->get_renderer('qbank_history')->render_history_header($historydata); + } else { + // Continue when all the question versions are deleted. + echo $OUTPUT->notification(get_string('allquestionversionsdeleted', 'qbank_history'), 'notifysuccess'); + echo $OUTPUT->continue_button($this->basereturnurl); + } } public function is_listing_specific_versions(): bool { diff --git a/question/bank/history/lang/en/qbank_history.php b/question/bank/history/lang/en/qbank_history.php index dcdde155990..c50393c6aaf 100644 --- a/question/bank/history/lang/en/qbank_history.php +++ b/question/bank/history/lang/en/qbank_history.php @@ -23,6 +23,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +$string['allquestionversionsdeleted'] = 'All versions of this question have been deleted.'; $string['close_history'] = 'Close'; $string['history_action'] = 'History'; $string['history_header'] = 'Question history'; diff --git a/question/bank/history/tests/behat/question_history_action.feature b/question/bank/history/tests/behat/question_history_action.feature index 6a39b0852f9..3011eeea9b6 100644 --- a/question/bank/history/tests/behat/question_history_action.feature +++ b/question/bank/history/tests/behat/question_history_action.feature @@ -43,3 +43,15 @@ Feature: Use the qbank plugin manager page for question history 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: Delete question from the history using Edit question menu + Given I am on the "Test quiz" "mod_quiz > question bank" page logged in as "admin" + And I choose "History" action for "First question" in the question bank + When I choose "Delete" action for "First question" in the question bank + And I press "Delete" + And I should not see "First question" + Then I should see "All versions of this question have been deleted." + And I click on "Continue" "button" + And I should see "Question bank" + And I should not see "First question"