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,168 @@
<?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/>.
/**
* Commenting system steps definitions for question.
*
* @package qbank_comment
* @copyright 2021 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
*/
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
require_once(__DIR__ . '/../../../../../lib/behat/behat_base.php');
require_once(__DIR__ . '/../../../../tests/behat/behat_question_base.php');
use Behat\Mink\Exception\ExpectationException as ExpectationException,
Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
/**
* Steps definitions to deal with the commenting system in question.
*
* @package qbank_comment
* @copyright 2021 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
*/
class behat_qbank_comment extends behat_question_base {
/**
* Looks for a table, then looks for a row that contains the given text.
* Once it finds the right row, it clicks a link in that row.
*
* @When I click :arg1 on the row on the comments column
* @param string $linkname
* @param string $rowtext
*/
public function i_click_on_the_row_containing($linkname) {
$exception = new ElementNotFoundException($this->getSession(),
'Cannot find any row on the page containing the text ' . $linkname);
$row = $this->find('css', sprintf('table tbody tr td.commentcount a:contains("%s")', $linkname), $exception);
$row->click();
}
/**
* Looks for the appropriate comment count in the column.
*
* @Then I should see :arg1 on the comments column
* @param string $linkdata
*/
public function i_should_see_on_the_column($linkdata) {
$exception = new ElementNotFoundException($this->getSession(),
'Cannot find any row with the comment count of ' . $linkdata . ' on the column named Comments');
$this->find('css', sprintf('table tbody tr td.commentcount a:contains("%s")', $linkdata), $exception);
}
/**
* Adds the specified option to the question comments of the current modal.
*
* @Then I add :arg1 comment to question
* @param string $comment
*/
public function i_add_comment_to_question($comment) {
// Getting the textarea and setting the provided value.
$exception = new ElementNotFoundException($this->getSession(), 'Question ');
if ($this->running_javascript()) {
$commentstextarea = $this->find('css',
'.modal-dialog .question-comment-view .comment-area textarea', $exception);
$commentstextarea->setValue($comment);
// We delay 1 second which is all we need.
$this->getSession()->wait(1000);
} else {
throw new ExpectationException('JavaScript not running', $this->getSession());
}
}
/**
* Adds the specified option to the question comments of the question preview.
*
* @Then I add :arg1 comment to question preview
* @param string $comment
*/
public function i_add_comment_to_question_preview($comment) {
// Getting the textarea and setting the provided value.
$exception = new ElementNotFoundException($this->getSession(), 'Question ');
if ($this->running_javascript()) {
$commentstextarea = $this->find('css',
'.comment-area textarea', $exception);
$commentstextarea->setValue($comment);
// We delay 1 second which is all we need.
$this->getSession()->wait(1000);
} else {
throw new ExpectationException('JavaScript not running', $this->getSession());
}
}
/**
* Deletes the specified comment from the current question comment preview.
*
* @Then I delete :arg comment from question preview
* @param string $comment
*/
public function i_delete_comment_from_question_preview($comment) {
$exception = new ElementNotFoundException($this->getSession(), '"' . $comment . '" comment ');
// Using xpath liternal to avoid possible problems with comments containing quotes.
$commentliteral = behat_context_helper::escape($comment);
$commentxpath = "//*[contains(concat(' ', normalize-space(@class), ' '), ' comment-ctrl ')]" .
"/descendant::div[@class='comment-message'][contains(., $commentliteral)]";
// Click on delete icon.
$this->execute('behat_general::i_click_on_in_the',
["Delete comment posted by", "icon", $this->escape($commentxpath), "xpath_element"]
);
// Wait for the animation to finish, in theory is just 1 sec, adding 4 just in case.
$this->getSession()->wait(4 * 1000);
}
/**
* Deletes the specified comment from the current question comment modal.
*
* @Then I delete :arg comment from question
* @param string $comment
*/
public function i_delete_comment_from_question($comment) {
$exception = new ElementNotFoundException($this->getSession(), '"' . $comment . '" comment ');
// Using xpath liternal to avoid possible problems with comments containing quotes.
$commentliteral = behat_context_helper::escape($comment);
$commentxpath = "//*[contains(concat(' ', normalize-space(@class), ' '), ' question-comment-view ')]" .
"/descendant::div[@class='comment-message'][contains(., $commentliteral)]";
// Click on delete icon.
$this->execute('behat_general::i_click_on_in_the',
["Delete comment posted by", "icon", $this->escape($commentxpath), "xpath_element"]
);
// Wait for the animation to finish, in theory is just 1 sec, adding 4 just in case.
$this->getSession()->wait(4 * 1000);
}
}
@@ -0,0 +1,151 @@
@qbank @qbank_comment @javascript
Feature: A Teacher can comment in a question
Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | T1 | Teacher1 | teacher1@example.com |
| teacher2 | T2 | Teacher2 | teacher2@example.com |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| teacher2 | C1 | editingteacher |
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 |
@javascript
Scenario: Add a comment in question
Given I am on the "Test quiz" "mod_quiz > question bank" page logged in as "teacher1"
And I apply question bank filter "Category" with value "Test questions"
And I should see "0" on the comments column
When I click "0" on the row on the comments column
And I add "Super test comment 01" comment to question
And I click on "Add comment" "button" in the ".modal-dialog" "css_element"
And I should see "Super test comment 01"
And I click on "Close" "button" in the ".modal-dialog" "css_element"
Then I should see "1" on the comments column
@javascript
Scenario: Delete a comment from question
Given I am on the "Test quiz" "mod_quiz > question bank" page logged in as "teacher1"
And I apply question bank filter "Category" with value "Test questions"
And I should see "0" on the comments column
When I click "0" on the row on the comments column
And I add "Super test comment 01 to be deleted" comment to question
And I click on "Add comment" "button" in the ".modal-dialog" "css_element"
And I should see "Super test comment 01 to be deleted"
And I click on "Close" "button" in the ".modal-dialog" "css_element"
Then I should see "1" on the comments column
And I click "1" on the row on the comments column
And I delete "Super test comment 01 to be deleted" comment from question
And I should not see "Super test comment 01 to be deleted"
And I click on "Close" "button" in the ".modal-dialog" "css_element"
But I should see "0" on the comments column
@javascript
Scenario: Preview question with comments
Given I am on the "Test quiz" "mod_quiz > question bank" page logged in as "teacher1"
And I apply question bank filter "Category" with value "Test questions"
And I choose "Preview" action for "First question" in the question bank
And I click on "Comments" "link"
Then I should see "Save comment"
And I add "Super test comment 01" comment to question preview
And I click on "Save comment" "link"
And I wait "1" seconds
Then I should see "Super test comment 01"
And I click on "Close preview" "button"
Then I should see "1" on the comments column
And I choose "Preview" action for "First question" in the question bank
And I click on "Comments" "link"
And I delete "Super test comment 01" comment from question preview
And I should not see "Super test comment 01"
And I click on "Close preview" "button"
Then I should see "0" on the comments column
@javascript
Scenario: Teacher with comment permissions for their own questions but not others questions
Given the following "role capability" exists:
| role | editingteacher |
| moodle/question:commentmine | allow |
| moodle/question:commentall | prevent |
And I am on the "Test quiz" "mod_quiz > question bank" page logged in as "teacher1"
And I apply question bank filter "Category" with value "Test questions"
And I choose "Preview" action for "First question" in the question bank
Then I should not see "Save comment"
And I click on "Close preview" "button"
Then I click on "Create a new question ..." "button"
And I set the field "item_qtype_essay" to "1"
And I press "submitbutton"
Then I should see "Adding an Essay question"
And I set the field "Question name" to "Essay 01 new"
And I set the field "Question text" to "Please write 200 words about Essay 01"
And I press "id_submitbutton"
Then I should see "Essay 01 new"
And I choose "Preview" action for "Essay 01 new" in the question bank
And I click on "Comments" "link"
Then I should see "Save comment"
And I log out
And I am on the "Test quiz" "mod_quiz > question bank" page logged in as "teacher2"
And I apply question bank filter "Category" with value "Test questions"
And I choose "Preview" action for "First question" in the question bank
Then I should not see "Save comment"
And I click on "Close preview" "button"
And I choose "Preview" action for "Essay 01 new" in the question bank
Then I should not see "Save comment"
And I click on "Close preview" "button"
@javascript
Scenario: Comments added from the quiz page are visible
Given I am on the "Test quiz" "mod_quiz > edit" page logged in as "teacher1"
And I press "Add"
And I follow "from question bank"
And I click on "Select" "checkbox" in the "First question" "table_row"
And I click on "Add selected questions to the quiz" "button"
And I click on "Preview question" "link"
And I switch to "questionpreview" window
And I press "Comments"
And I set the field "content" to "Some new comment"
And I click on "Save comment" "link"
And I should see "Some new comment"
And I switch to the main window
And I am on the "Test quiz" "mod_quiz > question bank" page
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"
And I should see "T1 Teacher1"
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" "mod_quiz > edit" page
And I click on "Preview question" "link"
And I switch to "questionpreview" window
And I press "Comments"
Then I should not see "Some new comment"
@javascript
Scenario: Comments modal can change the version using dropdown
Given I log in as "teacher1"
And I am on the "Test quiz" "quiz activity" page
When I navigate to "Question bank" in current page administration
And I should see "First question"
And I choose "Edit question" action for "First question" in the question bank
And I set the field "id_name" to "Renamed question v2"
And I set the field "id_questiontext" to "edited question"
And I press "id_submitbutton"
And I should not see "First question"
And I should see "Renamed question v2"
And I click "0" on the row on the comments column
And I should see "Version 2"
Then I should see "edited question"
And I should see "Version 1"
And I set the field "question_version_dropdown" to "Version 1"
And I should see "Answer the first question"
@@ -0,0 +1,30 @@
@qbank @qbank_comment
Feature: Use the qbank plugin manager page for comment
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 |
@javascript
Scenario: Enable/disable comment 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 comments"
And I click on "Disable" "link" in the "Question comments" "table_row"
And I am on the "Test quiz" "mod_quiz > question bank" page
Then "#categoryquestions .header.commentcount" "css_element" should not be visible
And I navigate to "Plugins > Question bank plugins > Manage question bank plugins" in site administration
And I click on "Enable" "link" in the "Question comments" "table_row"
And I am on the "Test quiz" "mod_quiz > question bank" page
And "#categoryquestions .header.commentcount" "css_element" should be visible