first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,68 @@
@qbank @qbank_history
Feature: Use the qbank plugin manager page for question history
In order to check the plugin behaviour with enable and disable
Background:
Given the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "activities" exist:
| activity | name | course | idnumber |
| quiz | Test quiz | C1 | quiz1 |
And the following "question categories" exist:
| contextlevel | reference | name |
| Course | C1 | Test questions |
And the following "questions" exist:
| questioncategory | qtype | name | questiontext |
| Test questions | truefalse | First question | Answer the first question |
Scenario: Enable/disable question history column from the base view
Given I log in as "admin"
When I navigate to "Plugins > Question bank plugins > Manage question bank plugins" in site administration
And I should see "Question history"
And I click on "Disable" "link" in the "Question history" "table_row"
And I am on the "Test quiz" "mod_quiz > question bank" page
Then the "History" action should not exist for the "First question" question in the question bank
And I navigate to "Plugins > Question bank plugins > Manage question bank plugins" in site administration
And I click on "Enable" "link" in the "Question history" "table_row"
And I am on the "Test quiz" "mod_quiz > question bank" page
Then the "History" action should exist for the "First question" question in the question bank
Scenario: History page shows only the specified features and questions
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
And I should see "Question"
And I should see "Actions"
And I should see "Status"
And I should see "Version"
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
@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
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"
@@ -0,0 +1,29 @@
@qbank @qbank_history
Feature: Use the qbank plugin manager page for version column
In order to check the plugin behaviour with enable and disable
Background:
Given the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "activities" exist:
| activity | name | course | idnumber |
| quiz | Test quiz | C1 | quiz1 |
And the following "question categories" exist:
| contextlevel | reference | name |
| Course | C1 | Test questions |
And the following "questions" exist:
| questioncategory | qtype | name | questiontext |
| Test questions | truefalse | First question | Answer the first question |
Scenario: Enable/disable version column from the base view
Given I log in as "admin"
And I navigate to "Plugins > Question bank plugins > Manage question bank plugins" in site administration
And I should see "Question history"
When I click on "Disable" "link" in the "Question history" "table_row"
And I am on the "Test quiz" "mod_quiz > question bank" page
Then I should not see "Version" 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 "Question history" "table_row"
And I am on the "Test quiz" "mod_quiz > question bank" page
And I should see "Version" in the "region-main" "region"
+118
View File
@@ -0,0 +1,118 @@
<?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 qbank_history;
use question_bank;
/**
* Helper class test.
*
* @package qbank_history
* @copyright 2022 Catalyst IT Australia Pty Ltd
* @author Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \qbank_history\helper
*/
class helper_test extends \advanced_testcase {
/**
* @var bool|\context|\context_course $context
*/
public $context;
/**
* @var object $questiondata;
*/
public $questiondata;
/**
* @var \moodle_url $returnurl
*/
public $returnurl;
/**
* @var int $courseid
*/
public $courseid;
/**
* Test set up.
*
* This is executed before running any test in this file.
*/
public function setUp(): void {
$this->setAdminUser();
$generator = $this->getDataGenerator();
$questiongenerator = $generator->get_plugin_generator('core_question');
// Create a course.
$course = $generator->create_course();
$this->courseid = $course->id;
$this->context = \context_course::instance($course->id);
// Create a question in the default category.
$contexts = new \core_question\local\bank\question_edit_contexts($this->context);
$cat = question_make_default_categories($contexts->all());
$question = $questiongenerator->create_question('numerical', null,
['name' => 'Example question', 'category' => $cat->id]);
$this->questiondata = question_bank::load_question($question->id);
$this->returnurl = new \moodle_url('/question/edit.php');
}
/**
* Test the history action url from the helper class.
*
* @covers ::question_history_url
*/
public function test_question_history_url(): void {
$this->resetAfterTest();
$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,
'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(): void {
$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,0 +1,138 @@
<?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 qbank_history;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/question/editlib.php');
/**
* Custom history view - qbank api test.
*
* @package qbank_history
* @copyright 2022 Catalyst IT Australia Pty Ltd
* @author Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \qbank_history\question_history_view
*/
class question_history_view_test extends \advanced_testcase {
/**
* Test that the history page shows all the versions of a question.
*
* @covers ::display
*/
public function test_question_history_shows_all_versions(): void {
$this->resetAfterTest();
$this->setAdminUser();
$generator = $this->getDataGenerator();
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
// Create a course.
$course = $generator->create_course();
$context = \context_course::instance($course->id);
// Create a question in the default category.
$contexts = new \core_question\local\bank\question_edit_contexts($context);
$cat = $questiongenerator->create_question_category();
$questiondata1 = $questiongenerator->create_question('numerical', null,
['name' => 'Example question', 'category' => $cat->id]);
// Create a new version.
$questiondata2 = $questiongenerator->update_question($questiondata1, null,
['name' => 'Example question second version']);
$entry = get_question_bank_entry($questiondata1->id);
$pagevars = [
'qpage' => 0,
'qperpage' => DEFAULT_QUESTIONS_PER_PAGE,
'cat' => $cat->id . ',' . $cat->contextid,
'tabname' => 'questions'
];
// Generate the view.
$viewclass = \qbank_history\question_history_view::class;
$extraparams = [
'view' => $viewclass,
'entryid' => $entry->id,
'returnurl' => "/",
];
$view = new $viewclass($contexts, new \moodle_url('/'), $course, null, $pagevars, $extraparams);
ob_start();
$view->display();
$html = ob_get_clean();
// Verify the output includes the first version.
$this->assertStringContainsString($questiondata1->name, $html);
// Verify the output includes the second version.
$this->assertStringContainsString($questiondata2->name, $html);
}
/**
* Test that the question bank header in the history page shows the latest question.
*
* @covers ::display_question_bank_header
*/
public function test_display_question_bank_header(): void {
$this->resetAfterTest();
$this->setAdminUser();
$generator = $this->getDataGenerator();
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
// Create a course.
$course = $generator->create_course();
$context = \context_course::instance($course->id);
// Create a question in the default category.
$contexts = new \core_question\local\bank\question_edit_contexts($context);
$cat = $questiongenerator->create_question_category();
$questiondata1 = $questiongenerator->create_question('numerical', null,
['name' => 'First version', 'category' => $cat->id]);
$entry = get_question_bank_entry($questiondata1->id);
$pagevars = [
'qpage' => 0,
'qperpage' => DEFAULT_QUESTIONS_PER_PAGE,
'cat' => $cat->id . ',' . $cat->contextid,
'tabname' => 'questions'
];
// Generate the view.
$viewclass = \qbank_history\question_history_view::class;
$extraparams = [
'view' => $viewclass,
'entryid' => $entry->id,
'returnurl' => "/",
];
$view = new $viewclass($contexts, new \moodle_url('/'), $course, null, $pagevars, $extraparams);
ob_start();
$view->display_question_bank_header();
$headerhtml = ob_get_clean();
// Verify the output includes the latest version.
$this->assertStringContainsString($questiondata1->name, $headerhtml);
$questiondata2 = $questiongenerator->update_question($questiondata1, null,
['name' => 'Second version']);
$view = new $viewclass($contexts, new \moodle_url('/'), $course, null, $pagevars, $extraparams);
ob_start();
$view->display_question_bank_header();
$headerhtml = ob_get_clean();
$this->assertStringContainsString($questiondata2->name, $headerhtml);
}
}