MDL-73335 question: Add the tertiary nav for question bank

The tertiary navigation has been added to the question bank.
- Url selector has been added for the pages:
  Questions, Categories, Import and Export
- A separate page to "Add category" has been added.
  The "Add category" is available as a tertiary nav button.
- Updated the tests for the changes made.

This commit is mostly Sujith's work, with further changes by
Tim Hunt <T.J.Hunt@open.ac.uk> so we share the blame/credit.

AMOS BEGIN
 CPY [questioncats,mod_quiz],[questioncategories,core_question]
AMOS END
This commit is contained in:
Sujith Haridasan 2022-01-09 20:57:54 +05:30 committed by Ilya Tregubov
parent 3458d159e1
commit b610055bbd
55 changed files with 339 additions and 117 deletions

View File

@ -43,7 +43,7 @@ Feature: Backup user data
| Feedback for the response 'False'. | So you think it is false |
And I log out
When I am on the "Quiz 1" "quiz activity" page logged in as student1
And I follow "Attempt quiz"
And I press "Attempt quiz"
And I click on "True" "radio" in the "First question" "question"
And I click on "False" "radio" in the "Second question" "question"
And I press "Finish attempt"

View File

@ -57,7 +57,7 @@ Feature: Award badges based on activity completion
And the "Receive a passing grade" completion condition of "Test quiz name" is displayed as "failed"
And the "Receive a pass grade or complete all available attempts" completion condition of "Test quiz name" is displayed as "todo"
When I am on the "Test quiz name" "quiz activity" page
And I follow "Attempt quiz"
And I press "Re-attempt quiz"
And I set the field "False" to "1"
And I press "Finish attempt ..."
And I press "Submit all and finish"

View File

@ -281,6 +281,8 @@ $string['published'] = 'shared';
$string['qtypeveryshort'] = 'T';
$string['questionaffected'] = '<a href="{$a->qurl}">Question "{$a->name}" ({$a->qtype})</a> is in this question category but is also being used in <a href="{$a->qurl}">quiz "{$a->quizname}"</a> in another course "{$a->coursename}".';
$string['questionbank'] = 'Question bank';
$string['questionbanknavigation'] = 'Question bank tertiary navigation';
$string['questioncategories'] = 'Question categories';
$string['questioncategory'] = 'Question category';
$string['questioncatsfor'] = 'Question categories for \'{$a}\'';
$string['questiondoesnotexist'] = 'This question does not exist';

View File

@ -60,6 +60,8 @@ $PAGE->set_url($url);
$streditingquestions = get_string('movequestions', 'qbank_bulkmove');
$PAGE->set_title($streditingquestions);
$PAGE->set_heading($COURSE->fullname);
$PAGE->activityheader->disable();
$PAGE->set_secondary_active_tab("questionbank");
if ($category) {
list($tocategoryid, $contextid) = explode(',', $category);

View File

@ -23,14 +23,14 @@ Feature: Use the qbank plugin manager page for bulkmove
And I should see "Bulk move questions"
And I click on "Disable" "link" in the "Bulk move questions" "table_row"
And I am on the "Test quiz" "quiz activity" page
And I navigate to "Question bank > Questions" in current page administration
And I navigate to "Question bank" in current page administration
And I click on "First question" "checkbox"
And I click on "With selected" "button"
Then I should not see question bulk action "move"
And I navigate to "Plugins > Question bank plugins > Manage question bank plugins" in site administration
And I click on "Enable" "link" in the "Bulk move questions" "table_row"
And I am on the "Test quiz" "quiz activity" page
And I navigate to "Question bank > Questions" in current page administration
And I navigate to "Question bank" in current page administration
And I click on "First question" "checkbox"
And I click on "With selected" "button"
And I should see question bulk action "move"

View File

@ -120,7 +120,7 @@ Feature: A Teacher can comment in a question
Scenario: Comments added from the quiz page are visible
Given I log in as "teacher1"
And I am on the "Test quiz" "quiz activity" page
When I navigate to "Edit quiz" in current page administration
When I navigate to "Questions" in current page administration
And I press "Add"
And I follow "from question bank"
And I click on "Select" "checkbox" in the "First question" "table_row"
@ -133,7 +133,7 @@ Feature: A Teacher can comment in a question
And I should see "Some new comment"
And I switch to the main window
And I am on the "Test quiz" "quiz activity" page
And I navigate to "Question bank > Questions" in current page administration
And I navigate to "Question bank" in current page administration
And I choose "Preview" action for "First question" in the question bank
And I click on "Comments" "link"
And I should see "Some new comment"
@ -141,7 +141,7 @@ Feature: A Teacher can comment in a question
And I delete "Some new comment" comment from question preview
And I should not see "Some new comment"
And I am on the "Test quiz" "quiz activity" page
And I navigate to "Edit quiz" in current page administration
And I navigate to "Questions" in current page administration
And I click on "Preview question" "link"
And I switch to "questionpreview" window
And I press "Comments"

View File

@ -38,7 +38,7 @@ Feature: A teacher can edit question with custom fields
| Feedback for the response 'True'. | So you think it is true |
| Feedback for the response 'False'. | So you think it is false |
And I am on the "Test quiz name" "quiz activity" page
And I navigate to "Question bank > Questions" in current page administration
And I navigate to "Question bank" in current page administration
Scenario: Edit a previously created question and see the custom field in the overview table and in the question preview.
When I choose "Edit question" action for "First question" in the question bank

View File

@ -38,7 +38,7 @@ Feature: The visibility of question custom fields control where they are display
| Feedback for the response 'True'. | So you think it is true |
| Feedback for the response 'False'. | So you think it is false |
And I am on the "Test quiz name" "quiz activity" page
And I navigate to "Question bank > Questions" in current page administration
And I navigate to "Question bank" in current page administration
@javascript
Scenario: Display custom question fields to teachers based on their visibility.

View File

@ -58,6 +58,8 @@ $PAGE->set_url($url);
$streditingquestions = get_string('deletequestion', 'qbank_deletequestion');
$PAGE->set_title($streditingquestions);
$PAGE->set_heading($COURSE->fullname);
$PAGE->activityheader->disable();
$PAGE->set_secondary_active_tab("questionbank");
// Unhide a question.
if (($unhide = optional_param('unhide', '', PARAM_INT)) and confirm_sesskey()) {

View File

@ -23,13 +23,13 @@ Feature: Use the qbank plugin manager page for deletequestion
And I should see "Delete question"
And I click on "Disable" "link" in the "Delete question" "table_row"
And I am on the "Test quiz" "quiz activity" page
And I navigate to "Question bank > Questions" in current page administration
And I navigate to "Question bank" in current page administration
And I click on ".dropdown-toggle" "css_element" in the "First question" "table_row"
Then I should not see "Delete" in the "region-main" "region"
And I navigate to "Plugins > Question bank plugins > Manage question bank plugins" in site administration
And I click on "Enable" "link" in the "Delete question" "table_row"
And I am on the "Test quiz" "quiz activity" page
And I navigate to "Question bank > Questions" in current page administration
And I navigate to "Question bank" in current page administration
And I click on ".dropdown-toggle" "css_element" in the "First question" "table_row"
And I should see "Delete" in the "region-main" "region"
@ -40,13 +40,13 @@ Feature: Use the qbank plugin manager page for deletequestion
And I should see "Delete question"
And I click on "Disable" "link" in the "Delete question" "table_row"
And I am on the "Test quiz" "quiz activity" page
And I navigate to "Question bank > Questions" in current page administration
And I navigate to "Question bank" in current page administration
And I click on "With selected" "button"
Then I should not see question bulk action "deleteselected"
And I navigate to "Plugins > Question bank plugins > Manage question bank plugins" in site administration
And I click on "Enable" "link" in the "Delete question" "table_row"
And I am on the "Test quiz" "quiz activity" page
And I navigate to "Question bank > Questions" in current page administration
And I navigate to "Question bank" in current page administration
And I click on "With selected" "button"
And I should see question bulk action "deleteselected"
@ -54,7 +54,7 @@ Feature: Use the qbank plugin manager page for deletequestion
Scenario: I should not see the deleted questions in the base view
Given I log in as "admin"
And I am on the "Test quiz" "quiz activity" page
And I navigate to "Question bank > Questions" in current page administration
And I navigate to "Question bank" in current page administration
And I click on "First question" "checkbox"
And I click on "First question second" "checkbox"
And I click on "With selected" "button"

View File

@ -23,7 +23,7 @@ Feature: Use the qbank plugin manager page for editquestion
And I should see "Edit question"
And I click on "Disable" "link" in the "Edit question" "table_row"
And I am on the "Test quiz" "quiz activity" page
And I navigate to "Question bank > Questions" in current page administration
And I navigate to "Question bank" in current page administration
Then I should not see "Status"
And I click on ".dropdown-toggle" "css_element" in the "First question" "table_row"
And I should not see "Edit question" in the "region-main" "region"
@ -31,7 +31,7 @@ Feature: Use the qbank plugin manager page for editquestion
And I navigate to "Plugins > Question bank plugins > Manage question bank plugins" in site administration
And I click on "Enable" "link" in the "Edit question" "table_row"
And I am on the "Test quiz" "quiz activity" page
And I navigate to "Question bank > Questions" in current page administration
And I navigate to "Question bank" in current page administration
And I click on ".dropdown-toggle" "css_element" in the "First question" "table_row"
Then I should see "Status"
And I click on ".dropdown-toggle" "css_element" in the "First question" "table_row"

View File

@ -52,7 +52,9 @@ echo $OUTPUT->header();
// Print horizontal nav if needed.
$renderer = $PAGE->get_renderer('core_question', 'bank');
echo $renderer->extra_horizontal_navigation();
$qbankaction = new \core_question\output\qbank_action_menu($thispageurl);
echo $renderer->render($qbankaction);
$exportform = new export_form($thispageurl,
['contexts' => $contexts->having_one_edit_tab_cap('export'), 'defaultcategory' => $pagevars['cat']]);

View File

@ -79,8 +79,9 @@ echo $OUTPUT->header();
// Print horizontal nav if needed.
$renderer = $PAGE->get_renderer('core_question', 'bank');
echo $renderer->extra_horizontal_navigation();
$qbankaction = new \core_question\output\qbank_action_menu($thispageurl);
echo $renderer->render($qbankaction);
// File upload form submitted.
if ($form = $importform->get_data()) {

View File

@ -50,11 +50,13 @@ $param->confirm = optional_param('confirm', 0, PARAM_INT);
$param->cancel = optional_param('cancel', '', PARAM_ALPHA);
$param->move = optional_param('move', 0, PARAM_INT);
$param->moveto = optional_param('moveto', 0, PARAM_INT);
$param->edit = optional_param('edit', 0, PARAM_INT);
$param->edit = optional_param('edit', null, PARAM_INT);
$url = new moodle_url($thispageurl);
foreach ((array)$param as $key => $value) {
if (($key !== 'cancel' && $value !== 0) || ($key === 'cancel' && $value !== '')) {
if (($key !== 'cancel' && $key !== 'edit' && $value !== 0) ||
($key === 'cancel' && $value !== '') ||
($key === 'edit' && $value !== null)) {
$url->param($key, $value);
}
}
@ -144,7 +146,7 @@ if ($qcobject->catform->is_cancelled()) {
redirect($thispageurl);
}
if ($param->edit) {
if ($param->edit !== null) {
$PAGE->navbar->add(get_string('editingcategory', 'question'));
}
@ -156,10 +158,12 @@ echo $OUTPUT->header();
// Print horizontal nav if needed.
$renderer = $PAGE->get_renderer('core_question', 'bank');
echo $renderer->extra_horizontal_navigation();
$qbankaction = new \core_question\output\qbank_action_menu($url);
echo $renderer->render($qbankaction);
// Display the UI.
if (!empty($param->edit)) {
if ($param->edit !== null) {
$qcobject->edit_single_category($param->edit);
} else if ($questionstomove) {
$qcobject->display_move_form($questionstomove, $category);

View File

@ -71,7 +71,7 @@ class question_category_edit_form extends moodleform {
$mform->addHelpButton('idnumber', 'idnumber', 'question');
$mform->setType('idnumber', PARAM_RAW);
$this->add_action_buttons(false, get_string('addcategory', 'question'));
$this->add_action_buttons(true, get_string('addcategory', 'question'));
$mform->addElement('hidden', 'id', 0);
$mform->setType('id', PARAM_INT);

View File

@ -136,7 +136,8 @@ class question_category_object {
foreach ($this->editlists as $key => $list) {
list($paged, $count) = $this->editlists[$key]->list_from_records($paged, $count);
}
$this->catform = new question_category_edit_form($this->pageurl, compact('contexts', 'currentcat'));
$this->catform = new question_category_edit_form($this->pageurl,
['contexts' => $contexts, 'currentcat' => $currentcat ?? 0]);
if (!$currentcat) {
$this->catform->set_data(['parent' => $defaultcategory]);
}
@ -147,15 +148,8 @@ class question_category_object {
*
*/
public function display_user_interface(): void {
// Interface for editing existing categories.
$this->output_edit_lists();
echo \html_writer::empty_tag('br');
// Interface for adding a new category.
$this->output_new_table();
echo \html_writer::empty_tag('br');
}
/**
@ -174,7 +168,7 @@ class question_category_object {
public function output_edit_lists(): void {
global $OUTPUT;
echo $OUTPUT->heading_with_help(get_string('editcategories', 'question'), 'editcategories', 'question');
echo $OUTPUT->heading_with_help(get_string('questioncategories', 'question'), 'editcategories', 'question');
foreach ($this->editlists as $context => $list) {
$listhtml = $list->to_html(0, ['str' => $this->str]);
@ -208,26 +202,29 @@ class question_category_object {
}
/**
* Edit a category.
* Edit a category, or add a new one if the id is zero.
*
* @param int $categoryid Category id.
*/
public function edit_single_category(int $categoryid): void {
// Interface for adding a new category.
global $DB;
// Interface for editing existing categories.
$category = $DB->get_record("question_categories", ["id" => $categoryid]);
if (empty($category)) {
throw new moodle_exception('invalidcategory', '', '', $categoryid);
} else if ($category->parent == 0) {
throw new moodle_exception('cannotedittopcat', 'question', '', $categoryid);
} else {
if ($categoryid) {
// Editing an existing category.
$category = $DB->get_record("question_categories", ["id" => $categoryid], '*', MUST_EXIST);
if ($category->parent == 0) {
throw new moodle_exception('cannotedittopcat', 'question', '', $categoryid);
}
$category->parent = "{$category->parent},{$category->contextid}";
$category->submitbutton = get_string('savechanges');
$category->categoryheader = $this->str->edit;
$this->catform->set_data($category);
$this->catform->display();
}
// Show the form.
$this->catform->display();
}
/**

View File

@ -22,7 +22,9 @@ Feature: A teacher can move question categories in the question bank
Scenario: A question category can be moved to another context
When I follow "Test quiz"
And I navigate to "Question bank > Categories" in current page administration
And I navigate to "Question bank" in current page administration
And I select "Categories" from the "questionbankactionselect" singleselect
And I follow "Add category"
And I set the following fields to these values:
| Name | Test category |
| Parent category | Top for Test quiz |
@ -32,7 +34,9 @@ Feature: A teacher can move question categories in the question bank
Scenario: A question category can be moved to top level
When I follow "Test quiz"
And I navigate to "Question bank > Categories" in current page administration
And I navigate to "Question bank" in current page administration
And I select "Categories" from the "questionbankactionselect" singleselect
And I follow "Add category"
And I set the following fields to these values:
| Name | Test category |
| Parent category | Default for Test quiz |

View File

@ -27,7 +27,9 @@ Feature: A teacher can put questions in categories in the question bank
And I am on "Course 1" course homepage
Scenario: A new question category can be created
When I navigate to "Question bank > Categories" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Categories" from the "questionbankactionselect" singleselect
And I follow "Add category"
And I set the following fields to these values:
| Name | New Category 1 |
| Parent category | Top |
@ -39,10 +41,12 @@ Feature: A teacher can put questions in categories in the question bank
And I should see "newcatidnumber"
And I should see "(0)"
And I should see "Created as a test" in the "New Category 1" "list_item"
And I follow "Add category"
And "New Category 1 [newcatidnumber]" "option" should exist in the "Parent category" "select"
Scenario: A question category can be edited
When I navigate to "Question bank > Categories" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Categories" from the "questionbankactionselect" singleselect
And I click on "Edit this category" "link" in the "Subcategory" "list_item"
And the field "parent" matches value "&nbsp;&nbsp;&nbsp;Default for C1"
And I set the following fields to these values:
@ -53,14 +57,17 @@ Feature: A teacher can put questions in categories in the question bank
And I should see "I was edited" in the "New name" "list_item"
Scenario: An empty question category can be deleted
When I navigate to "Question bank > Categories" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Categories" from the "questionbankactionselect" singleselect
And I click on "Delete" "link" in the "Subcategory" "list_item"
Then I should not see "Subcategory"
Scenario: An non-empty question category can be deleted if you move the contents elsewhere
When I navigate to "Question bank > Categories" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Categories" from the "questionbankactionselect" singleselect
And I click on "Delete" "link" in the "Used category" "list_item"
And I should see "The category 'Used category' contains 1 questions"
And I press "Save in category"
Then I should not see "Used category"
And I follow "Add category"
And I should see "Default for C1 (1)"

View File

@ -23,18 +23,22 @@ Feature: A teacher can put questions with idnumbers in categories with idnumbers
| contextlevel | reference | questioncategory | name | idnumber |
| Course | C1 | Top | top | |
| Course | C1 | top | Used category | c1used |
And I navigate to "Question bank > Categories" in current page administration
And I navigate to "Question bank" in current page administration
And I select "Categories" from the "questionbankactionselect" singleselect
And I follow "Add category"
And I set the following fields to these values:
| Name | Sub used category |
| Parent category | Used category |
| Category info | Created as a test |
| ID number | c1used |
And I press "Add category"
# Press the Add category button in category page.
And I click on "Add category" "button" in the "[id='fitem_id_submitbutton']" "css_element"
# Standard warning.
Then I should see "This ID number is already in use"
# Correction to a unique idnumber for the context.
And I set the field "ID number" to "c1unused"
And I press "Add category"
# Press the Add category button in the addcategory page.
And I click on "[id='id_submitbutton']" "css_element"
Then I should see "Sub used category"
And I should see "ID number"
And I should see "c1unused"
@ -46,7 +50,8 @@ Feature: A teacher can put questions with idnumbers in categories with idnumbers
| contextlevel | reference | questioncategory | name | idnumber |
| Course | C1 | Top | top | |
| Course | C1 | top | Used category | c1used |
And I navigate to "Question bank > Categories" in current page administration
And I navigate to "Question bank" in current page administration
And I select "Categories" from the "questionbankactionselect" singleselect
And I click on "Edit this category" "link" in the "Used category" "list_item"
And I press "Save changes"
Then I should not see "This ID number is already in use"

View File

@ -22,13 +22,12 @@ Feature: Use the qbank plugin manager page for managecategories
And I should see "Manage categories"
And I click on "Disable" "link" in the "Manage categories" "table_row"
And I am on the "Test quiz" "quiz activity" page
And I navigate to "Question bank" in current page administration
Then I should not see "Categories"
Then "Categories" "link" should not exist in current page administration
And I navigate to "Plugins > Question bank plugins > Manage question bank plugins" in site administration
And I click on "Enable" "link" in the "Manage categories" "table_row"
And I am on the "Test quiz" "quiz activity" page
And I navigate to "Question bank" in current page administration
And I should see "Categories"
And I should see "Categories" in the "//div[contains(@class, 'urlselect')]//option[contains(text(), 'Categories')]" "xpath_element"
Scenario: Enable/disable the tab New category when tyring to add a random question to a quiz
Given I log in as "admin"
@ -36,7 +35,7 @@ Feature: Use the qbank plugin manager page for managecategories
And I should see "Manage categories"
And I click on "Disable" "link" in the "Manage categories" "table_row"
And I am on the "Test quiz" "quiz activity" page
And I navigate to "Edit quiz" in current page administration
And I click on "Add question" "link"
And I open the "last" add to quiz menu
And I follow "a random question"
Then I should not see "New category"
@ -44,7 +43,7 @@ Feature: Use the qbank plugin manager page for managecategories
And I navigate to "Plugins > Question bank plugins > Manage question bank plugins" in site administration
And I click on "Enable" "link" in the "Manage categories" "table_row"
And I am on the "Test quiz" "quiz activity" page
And I navigate to "Edit quiz" in current page administration
And I click on "Add question" "link"
And I open the "last" add to quiz menu
And I follow "a random question"
And I should see "New category"

View File

@ -22,14 +22,14 @@ Feature: Use the qbank plugin manager page for statistics
And I should see "Question statistics"
And I click on "Disable" "link" in the "Question statistics" "table_row"
And I am on the "Test quiz" "quiz activity" page
And I navigate to "Question bank > Questions" in current page administration
And I navigate to "Question bank" in current page administration
Then I should not see "Facility index"
And I should not see "Discriminative efficiency"
And I should not see "Need for revision"
And I navigate to "Plugins > Question bank plugins > Manage question bank plugins" in site administration
And I click on "Enable" "link" in the "Question statistics" "table_row"
And I am on the "Test quiz" "quiz activity" page
And I navigate to "Question bank > Questions" in current page administration
And I navigate to "Question bank" in current page administration
And I should see "Facility index"
And I should see "Discriminative efficiency"
And I should see "Need for revision"

View File

@ -73,7 +73,7 @@ Feature: Show statistics in question bank
| 1 | True |
| 2 | True |
When I am on the "Course 1" course page logged in as admin
And I navigate to "Question bank > Questions" in current page administration
And I navigate to "Question bank" in current page administration
And I should see "50.00%" in the "TF1" "table_row"
And I should see "75.00%" in the "TF2" "table_row"
And I should see "75.00%" in the "TF3" "table_row"
@ -89,7 +89,7 @@ Feature: Show statistics in question bank
| 1 | True |
| 2 | True |
When I am on the "Course 1" course page logged in as admin
And I navigate to "Question bank > Questions" in current page administration
And I navigate to "Question bank" in current page administration
And I should see "50.00%" in the "TF1" "table_row"
And I should see "75.00%" in the "TF2" "table_row"
And I should see "75.00%" in the "TF3" "table_row"
@ -105,13 +105,13 @@ Feature: Show statistics in question bank
| 1 | True |
| 2 | True |
When I am on the "Course 1" course page logged in as admin
And I navigate to "Question bank > Questions" in current page administration
And I should see "likely" in the "TF1" "table_row"
And I should see "unlikely" in the "TF2" "table_row"
And I should see "unlikely" in the "TF3" "table_row"
And I should see "likely" in the "TF4" "table_row"
And I should see "likely" in the ".alert-warning" "css_element"
And I should see "unlikely" in the ".alert-success" "css_element"
And I navigate to "Question bank" in current page administration
And I should see "Likely" in the "TF1" "table_row"
And I should see "Unlikely" in the "TF2" "table_row"
And I should see "Unlikely" in the "TF3" "table_row"
And I should see "Likely" in the "TF4" "table_row"
And I should see "Likely" in the ".alert-warning" "css_element"
And I should see "Unlikely" in the ".alert-success" "css_element"
Scenario: View discrimination index in question bank, bad questions
Given user "student1" has attempted "Quiz 2" with responses:
@ -127,10 +127,10 @@ Feature: Show statistics in question bank
| 1 | True |
| 2 | False |
When I am on the "Course 1" course page logged in as admin
And I navigate to "Question bank > Questions" in current page administration
And I should see "likely" in the "TF1" "table_row"
And I should see "very likely" in the "TF2" "table_row"
And I should see "very likely" in the "TF3" "table_row"
And I should see "likely" in the "TF4" "table_row"
And I should see "very likely" in the ".alert-danger" "css_element"
And I should see "likely" in the ".alert-warning" "css_element"
And I navigate to "Question bank" in current page administration
And I should see "Likely" in the "TF1" "table_row"
And I should see "Very likely" in the "TF2" "table_row"
And I should see "Very likely" in the "TF3" "table_row"
And I should see "Likely" in the "TF4" "table_row"
And I should see "Very likely" in the ".alert-danger" "css_element"
And I should see "Likely" in the ".alert-warning" "css_element"

View File

@ -22,19 +22,19 @@ Feature: Use the qbank plugin manager page for question usage
And I should see "Question usage"
When I click on "Disable" "link" in the "Question usage" "table_row"
And I am on the "Test quiz" "quiz activity" page
And I navigate to "Question bank > Questions" in current page administration
And I navigate to "Question bank" in current page administration
Then I should not see "Usage"
And I navigate to "Plugins > Question bank plugins > Manage question bank plugins" in site administration
And I click on "Enable" "link" in the "Question usage" "table_row"
And I am on the "Test quiz" "quiz activity" page
And I navigate to "Question bank > Questions" in current page administration
And I navigate to "Question bank" in current page administration
And I should see "Usage"
@javascript
Scenario: Question usage modal should work without any usage data
Given I log in as "admin"
And I am on the "Test quiz" "quiz activity" page
And I navigate to "Question bank > Questions" in current page administration
And I navigate to "Question bank" in current page administration
And I set the field "Select a category" to "Test questions"
And I should see "Test questions"
And I should see "0" on the usage column

View File

@ -0,0 +1,89 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace core_question\output;
use moodle_url;
use renderer_base;
use templatable;
use renderable;
use url_select;
/**
* Rendered HTML elements for tertiary nav for Question bank.
*
* Provides the links for question bank tertiary navigation, below
* are the links provided for the urlselector:
* Questions, Categories, Import and Export
* Also "Add category" button is added to tertiary nav for the categories.
* The "Add category" would take the user to separate page, add category page.
*
* @package core_question
* @copyright 2021 Sujith Haridasan <sujith@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qbank_action_menu implements templatable, renderable {
/** @var moodle_url */
private $currenturl;
/**
* qbank_actionbar constructor.
*
* @param moodle_url $currenturl The current URL.
*/
public function __construct(moodle_url $currenturl) {
$this->currenturl = $currenturl;
}
/**
* Provides the data for the template.
*
* @param renderer_base $output renderer_base object.
* @return array data for the template
*/
public function export_for_template(renderer_base $output): array {
$questionslink = new moodle_url('/question/edit.php', $this->currenturl->params());
if (\core\plugininfo\qbank::is_plugin_enabled("qbank_managecategories")) {
$categorylink = new moodle_url('/question/bank/managecategories/category.php', $this->currenturl->params());
}
$importlink = new moodle_url('/question/bank/importquestions/import.php', $this->currenturl->params());
$exportlink = new moodle_url('/question/bank/exportquestions/export.php', $this->currenturl->params());
$menu = [
$questionslink->out(false) => get_string('questions', 'question'),
];
if (\core\plugininfo\qbank::is_plugin_enabled("qbank_managecategories")) {
$menu[$categorylink->out(false)] = get_string('categories', 'question');
}
$menu[$importlink->out(false)] = get_string('import', 'question');
$menu[$exportlink->out(false)] = get_string('export', 'question');
$addcategory = null;
if (strpos($this->currenturl->get_path(), 'category.php') !== false &&
$this->currenturl->param('edit') === null) {
$addcategory = $this->currenturl->out(false, ['edit' => 0]);
}
$urlselect = new url_select($menu, $this->currenturl->out(false), null, 'questionbankaction');
$urlselect->set_label(get_string('questionbanknavigation', 'question'), ['class' => 'accesshide']);
return [
'questionbankselect' => $urlselect->export_for_template($output),
'addcategory' => $addcategory
];
}
}

View File

@ -52,7 +52,10 @@ echo $OUTPUT->header();
// Print horizontal nav if needed.
$renderer = $PAGE->get_renderer('core_question', 'bank');
echo $renderer->extra_horizontal_navigation();
// Render the selection action.
$qbankaction = new \core_question\output\qbank_action_menu($url);
echo $renderer->render($qbankaction);
// Print the question area.
$questionbank->display($pagevars, 'questions');

View File

@ -25,7 +25,8 @@ Feature: Test exporting questions using Aiken format.
And I am on "Course 1" course homepage
Scenario: Aiken export
When I navigate to "Question bank > Export" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Export" from the "questionbankactionselect" singleselect
And I set the field "id_format_aiken" to "1"
When I press "Export questions to file"
Then following "click here" should download between "68" and "70" bytes

View File

@ -19,7 +19,8 @@ Feature: Test importing questions from Aiken format.
@javascript @_file_upload
Scenario: import some Aiken questions
When I navigate to "Question bank > Import" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Import" from the "questionbankactionselect" singleselect
And I set the field "id_format_aiken" to "1"
And I upload "question/format/aiken/tests/fixtures/questions.aiken.txt" file to "Import" filemanager
And I press "id_submitbutton"

View File

@ -19,7 +19,8 @@ Feature: Test importing questions from GIFT format.
@javascript @_file_upload
Scenario: import some GIFT questions
When I navigate to "Question bank > Import" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Import" from the "questionbankactionselect" singleselect
And I set the field "id_format_gift" to "1"
And I upload "question/format/gift/tests/fixtures/questions.gift.txt" file to "Import" filemanager
And I press "id_submitbutton"
@ -30,14 +31,17 @@ Feature: Test importing questions from GIFT format.
Then I should see "colours"
# Now export again.
And I follow "Export"
And I am on "Course 1" course homepage
And I navigate to "Question bank" in current page administration
And I select "Export" from the "questionbankactionselect" singleselect
And I set the field "id_format_gift" to "1"
And I press "Export questions to file"
And following "click here" should download between "1500" and "1800" bytes
@javascript @_file_upload
Scenario: import a GIFT file which specifies the category
When I navigate to "Question bank > Import" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Import" from the "questionbankactionselect" singleselect
And I set the field "id_format_gift" to "1"
And I upload "question/format/gift/tests/fixtures/questions_in_category.gift.txt" file to "Import" filemanager
And I press "id_submitbutton"

View File

@ -19,7 +19,8 @@ Feature: Test importing questions from Moodle XML format.
@javascript @_file_upload
Scenario: import some true/false questions from Moodle XML format
When I navigate to "Question bank > Import" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Import" from the "questionbankactionselect" singleselect
And I set the field "id_format_xml" to "1"
And I upload "question/format/xml/tests/fixtures/truefalse.xml" file to "Import" filemanager
And I press "id_submitbutton"
@ -32,7 +33,9 @@ Feature: Test importing questions from Moodle XML format.
Then I should see "Moodle acronym (True)"
# Now export again.
And I follow "Export"
And I am on "Course 1" course homepage
When I navigate to "Question bank" in current page administration
And I select "Export" from the "questionbankactionselect" singleselect
And I set the field "id_format_xml" to "1"
And I set the field "Export category" to "TrueFalse"
And I press "Export questions to file"
@ -40,7 +43,8 @@ Feature: Test importing questions from Moodle XML format.
@javascript @_file_upload
Scenario: import some multiple choice questions from Moodle XML format
When I navigate to "Question bank > Import" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Import" from the "questionbankactionselect" singleselect
And I set the field "id_format_xml" to "1"
And I upload "question/format/xml/tests/fixtures/multichoice.xml" file to "Import" filemanager
And I press "id_submitbutton"
@ -52,7 +56,8 @@ Feature: Test importing questions from Moodle XML format.
@javascript @_file_upload
Scenario: import some multi-answer questions from Moodle XML format
When I navigate to "Question bank > Import" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Import" from the "questionbankactionselect" singleselect
And I set the field "id_format_xml" to "1"
And I upload "question/format/xml/tests/fixtures/multianswer.xml" file to "Import" filemanager
And I press "id_submitbutton"
@ -64,7 +69,8 @@ Feature: Test importing questions from Moodle XML format.
@javascript @_file_upload
Scenario: import some questions with legacy-style images from Moodle XML format
When I navigate to "Question bank > Import" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Import" from the "questionbankactionselect" singleselect
And I set the field "id_format_xml" to "1"
And I upload "question/format/xml/tests/fixtures/sample_questions_with_old_image_tag.xml" file to "Import" filemanager
And I press "id_submitbutton"

View File

@ -0,0 +1,70 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template core_question/qbank_action_menu
Question bank tertiary navigtion.
Classes required for JS:
* none
Context variables required for this template:
* see question/classes/output/qbank_actionbar.php
Example context (json):
{
"questionbankselect": {
"action": "http://localhost/moodle/course/jumpto.php",
"classes": "urlselect",
"formid": "questionbankaction",
"id": "url_select61a85bc543dca7",
"label": "questionbankactionselect",
"options": [{
"name": "Questions",
"selected": true,
"value": "/question/edit.php?courseid=7"
},
{
"name": "Categories",
"selected": false,
"value": "/question/bank/managecategories/category.php?courseid=7"
},
{
"name": "Import",
"selected": false,
"value": "/question/bank/importquestions/import.php?courseid=7"
},
{
"name": "Export",
"selected": false,
"value": "/question/bank/exportquestions/export.php?courseid=7"
}
]
},
"addcategory": "http://localhost/moodle/question/bank/managecategories/addcategory.php?cmid=71"
}
}}
<div class="container-fluid mb-2">
<div class="row">
{{#questionbankselect}}
{{>core/url_select}}
{{/questionbankselect}}
{{#addcategory}}
<a class="btn btn-primary ml-2" href="{{ addcategory }}">{{#str}}addcategory, question {{/str}}</a>
{{/addcategory}}
</div>
</div>

View File

@ -60,7 +60,7 @@ Feature: A teacher can delete questions in the question bank
And I click on "Also show old questions" "checkbox"
And I should see "Test used question to be deleted"
And I am on the "Test quiz" "quiz activity" page
And I click on "Preview quiz now" "button"
And I click on "Preview quiz" "button"
And I should see "Write about whatever you want"
@javascript

View File

@ -26,7 +26,8 @@ Feature: Test exporting drag and drop onto image questions
@javascript
Scenario: Export a drag and drop onto image question
# Import sample file.
When I navigate to "Question bank > Export" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Export" from the "questionbankactionselect" singleselect
And I set the field "id_format_xml" to "1"
And I press "Export questions to file"
And following "click here" should download between "18600" and "19150" bytes

View File

@ -19,7 +19,8 @@ Feature: Test importing drag and drop onto image questions
@javascript @_file_upload
Scenario: import drag and drop onto image question.
When I navigate to "Question bank > Import" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Import" from the "questionbankactionselect" singleselect
And I set the field "id_format_xml" to "1"
And I upload "question/type/ddimageortext/tests/fixtures/testquestion.moodle.xml" file to "Import" filemanager
And I press "id_submitbutton"

View File

@ -26,7 +26,8 @@ Feature: Test exporting drag and drop markers questions
@javascript
Scenario: Export a drag and drop markers question
# Import sample file.
When I navigate to "Question bank > Export" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Export" from the "questionbankactionselect" singleselect
And I set the field "id_format_xml" to "1"
And I press "Export questions to file"
And following "click here" should download between "233700" and "233950" bytes

View File

@ -19,7 +19,8 @@ Feature: Test importing drag and drop markers questions
@javascript @_file_upload
Scenario: import drag and drop markers question.
When I navigate to "Question bank > Import" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Import" from the "questionbankactionselect" singleselect
And I set the field "id_format_xml" to "1"
And I upload "question/type/ddmarker/tests/fixtures/testquestion.moodle.xml" file to "Import" filemanager
And I press "id_submitbutton"

View File

@ -26,7 +26,8 @@ Feature: Test exporting drag and drop into text questions
@javascript
Scenario: Export a drag and drop into text question
# Import sample file.
When I navigate to "Question bank > Export" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Export" from the "questionbankactionselect" singleselect
And I set the field "id_format_xml" to "1"
And I press "Export questions to file"
And following "click here" should download between "1550" and "1700" bytes

View File

@ -19,7 +19,8 @@ Feature: Test importing drag and drop into text questions
@javascript @_file_upload
Scenario: import drag and drop into text question.
When I navigate to "Question bank > Import" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Import" from the "questionbankactionselect" singleselect
And I set the field "id_format_xml" to "1"
And I upload "question/type/ddwtos/tests/fixtures/testquestion.moodle.xml" file to "Import" filemanager
And I press "id_submitbutton"

View File

@ -24,7 +24,8 @@ Feature: Test exporting Description questions
And I am on "Course 1" course homepage
Scenario: Export a Description question
When I navigate to "Question bank > Export" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Export" from the "questionbankactionselect" singleselect
And I set the field "id_format_xml" to "1"
And I press "Export questions to file"
Then following "click here" should download between "650" and "900" bytes

View File

@ -19,7 +19,8 @@ Feature: Test importing Description questions
@javascript @_file_upload
Scenario: import a Description question.
When I navigate to "Question bank > Import" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Import" from the "questionbankactionselect" singleselect
And I set the field "id_format_xml" to "1"
And I upload "question/type/description/tests/fixtures/testquestion.moodle.xml" file to "Import" filemanager
And I press "id_submitbutton"

View File

@ -26,7 +26,8 @@ Feature: Test exporting Essay questions
And I am on "Course 1" course homepage
Scenario: Export 3 Essay questions
When I navigate to "Question bank > Export" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Export" from the "questionbankactionselect" singleselect
And I set the field "id_format_xml" to "1"
And I press "Export questions to file"
Then following "click here" should download between "3000" and "3500" bytes

View File

@ -46,7 +46,7 @@ I need to limit the submittable file types
And I upload "lib/tests/fixtures/empty.txt" file to "Files" filemanager
And I press "Save changes"
And I am on the "Quiz 1" "quiz activity" page
And I press "Attempt quiz now"
And I press "Attempt quiz"
And I should see "First question"
And I should see "You can drag and drop files here to add them."
And I click on "Add..." "button"
@ -64,7 +64,7 @@ I need to limit the submittable file types
And I upload "lib/tests/fixtures/upload_users.csv" file to "Files" filemanager
And I press "Save changes"
And I am on the "Quiz 1" "quiz activity" page
And I press "Attempt quiz now"
And I press "Attempt quiz"
And I should see "First question"
And I should see "You can drag and drop files here to add them."
And I click on "Add..." "button"

View File

@ -19,7 +19,8 @@ Feature: Test importing Essay questions
@javascript @_file_upload
Scenario: import Essay question.
When I navigate to "Question bank > Import" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Import" from the "questionbankactionselect" singleselect
And I set the field "id_format_xml" to "1"
And I upload "question/type/essay/tests/fixtures/testquestion.moodle.xml" file to "Import" filemanager
And I press "id_submitbutton"

View File

@ -20,7 +20,8 @@ Feature: Import and export select missing words questions
@javascript @_file_upload
Scenario: Import and export select missing words questions
# Import sample file.
When I navigate to "Question bank > Import" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Import" from the "questionbankactionselect" singleselect
And I set the field "id_format_xml" to "1"
And I upload "question/type/gapselect/tests/fixtures/testquestion.moodle.xml" file to "Import" filemanager
And I press "id_submitbutton"
@ -31,7 +32,9 @@ Feature: Import and export select missing words questions
And I should see "Imported Select missing words 001"
# Now export again.
When I follow "Export"
And I am on "Course 1" course homepage
When I navigate to "Question bank" in current page administration
And I select "Export" from the "questionbankactionselect" singleselect
And I set the field "id_format_xml" to "1"
And I press "Export questions to file"
Then following "click here" should download between "1650" and "1800" bytes

View File

@ -24,7 +24,8 @@ Feature: Test exporting Matching questions
And I am on "Course 1" course homepage
Scenario: Export a Matching question
When I navigate to "Question bank > Export" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Export" from the "questionbankactionselect" singleselect
And I set the field "id_format_xml" to "1"
And I press "Export questions to file"
Then following "click here" should download between "1600" and "1750" bytes

View File

@ -19,7 +19,8 @@ Feature: Test importing Matching questions
@javascript @_file_upload
Scenario: import Matching question.
When I navigate to "Question bank > Import" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Import" from the "questionbankactionselect" singleselect
And I set the field "id_format_xml" to "1"
And I upload "question/type/match/tests/fixtures/testquestion.moodle.xml" file to "Import" filemanager
And I press "id_submitbutton"

View File

@ -40,7 +40,7 @@ Feature: Clear my answers
@javascript
Scenario: Attempt a quiz and reset my chosen answer.
Given I am on the "Quiz 1" "quiz activity" page logged in as student1
When I press "Attempt quiz now"
When I press "Attempt quiz"
And I should see "Question One"
And I click on "Four" "qtype_multichoice > Answer" in the "Question One" "question"
And I should see "Clear my choice"
@ -52,7 +52,7 @@ Feature: Clear my answers
@javascript
Scenario: Attempt a quiz and revisit a cleared answer.
Given I am on the "Quiz 1" "quiz activity" page logged in as student1
When I press "Attempt quiz now"
When I press "Attempt quiz"
And I should see "Question One"
And I click on "Four" "qtype_multichoice > Answer" in the "Question One" "question"
And I follow "Finish attempt ..."

View File

@ -25,7 +25,8 @@ Feature: Test exporting Multiple choice questions
And I am on "Course 1" course homepage
Scenario: Export a Multiple choice question
When I navigate to "Question bank > Export" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Export" from the "questionbankactionselect" singleselect
And I set the field "id_format_xml" to "1"
And I press "Export questions to file"
Then following "click here" should download between "3900" and "4100" bytes

View File

@ -19,7 +19,8 @@ Feature: Test importing Multiple choice questions
@javascript @_file_upload
Scenario: import Multiple choice question.
When I navigate to "Question bank > Import" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Import" from the "questionbankactionselect" singleselect
And I set the field "id_format_xml" to "1"
And I upload "question/type/multichoice/tests/fixtures/testquestion.moodle.xml" file to "Import" filemanager
And I press "id_submitbutton"

View File

@ -25,7 +25,8 @@ Feature: Test exporting Numerical questions
And I am on "Course 1" course homepage
Scenario: Export a Numerical question
When I navigate to "Question bank > Export" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Export" from the "questionbankactionselect" singleselect
And I set the field "id_format_xml" to "1"
And I press "Export questions to file"
Then following "click here" should download between "3650" and "3750" bytes

View File

@ -19,7 +19,8 @@ Feature: Test importing Numerical questions
@javascript @_file_upload
Scenario: import Numerical question.
When I navigate to "Question bank > Import" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Import" from the "questionbankactionselect" singleselect
And I set the field "id_format_xml" to "1"
And I upload "question/type/numerical/tests/fixtures/testquestion.moodle.xml" file to "Import" filemanager
And I press "id_submitbutton"

View File

@ -24,7 +24,8 @@ Feature: Test exporting Short answer questions
And I am on "Course 1" course homepage
Scenario: Export a Short answer question
When I navigate to "Question bank > Export" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Export" from the "questionbankactionselect" singleselect
And I set the field "id_format_xml" to "1"
And I press "Export questions to file"
Then following "click here" should download between "1200" and "1450" bytes

View File

@ -19,7 +19,8 @@ Feature: Test importing Short answer questions
@javascript @_file_upload
Scenario: import Matching question.
When I navigate to "Question bank > Import" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Import" from the "questionbankactionselect" singleselect
And I set the field "id_format_xml" to "1"
And I upload "question/type/shortanswer/tests/fixtures/testquestion.moodle.xml" file to "Import" filemanager
And I press "id_submitbutton"

View File

@ -24,7 +24,8 @@ Feature: Test exporting True/False questions
And I am on "Course 1" course homepage
Scenario: Export a True/False question
When I navigate to "Question bank > Export" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Export" from the "questionbankactionselect" singleselect
And I set the field "id_format_xml" to "1"
And I press "Export questions to file"
Then following "click here" should download between "1000" and "1200" bytes

View File

@ -19,7 +19,8 @@ Feature: Test importing True/False questions
@javascript @_file_upload
Scenario: import a True/False question.
When I navigate to "Question bank > Import" in current page administration
When I navigate to "Question bank" in current page administration
And I select "Import" from the "questionbankactionselect" singleselect
And I set the field "id_format_xml" to "1"
And I upload "question/type/truefalse/tests/fixtures/testquestion.moodle.xml" file to "Import" filemanager
And I press "id_submitbutton"

View File

@ -158,7 +158,7 @@ class behat_theme_classic_behat_navigation extends behat_navigation {
$this->find('xpath', $menuxpath, $exception);
} catch (Exception $e) {
// For question bank a different approach.
$menuxpath = $rootxpath . "//div[contains(@class, 'dropdown-menu')]";
$menuxpath = $rootxpath;
if ($selectortype === 'link') {
$menuxpath .= "//a[contains(text(), 'Categories')]";
}