forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-76591 comment: create test generators and Behat scenarios.
The added scenarios cover the management of comments: viewing, filtering and deletion.
- Loading branch information
1 parent
35f3847
commit 76327f0
Showing
5 changed files
with
181 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
@core_comment @javascript | ||
Feature: Manage comments made by users | ||
As an admin | ||
I want to view, filter and delete comments | ||
|
||
Background: | ||
Given I log in as "admin" | ||
And the following "course" exists: | ||
| fullname | Course 1 | | ||
| shortname | CS101 | | ||
And the following "core_comment > Comments" exist: | ||
| contextlevel | reference | component | area | content | | ||
| Course | CS101 | block_comments | page_comments | Uno | | ||
| Course | CS101 | block_comments | page_comments | Dos | | ||
| Course | CS101 | block_comments | page_comments | Tres | | ||
|
||
Scenario: View and filter site comments | ||
When I navigate to "Reports > Comments" in site administration | ||
And the following should exist in the "reportbuilder-table" table: | ||
| -0- | Content | Context URL | | ||
| Admin User | Uno | Course: Course 1 | | ||
| Admin User | Dos | Course: Course 1 | | ||
| Admin User | Tres | Course: Course 1 | | ||
And I click on "Filters" "button" | ||
And I set the following fields in the "Content" "core_reportbuilder > Filter" to these values: | ||
| Content operator | Contains | | ||
| Content value | Uno | | ||
And I click on "Apply" "button" in the "[data-region='report-filters']" "css_element" | ||
Then I should see "Uno" in the "reportbuilder-table" "table" | ||
And I should not see "Dos" in the "reportbuilder-table" "table" | ||
And I should not see "Tres" in the "reportbuilder-table" "table" | ||
|
||
Scenario: Delete single comment | ||
When I navigate to "Reports > Comments" in site administration | ||
And I press "Delete" action in the "Uno" report row | ||
And I click on "Delete" "button" in the "Delete" "dialogue" | ||
Then I should not see "Uno" in the "reportbuilder-table" "table" | ||
And I should see "Dos" in the "reportbuilder-table" "table" | ||
And I should see "Tres" in the "reportbuilder-table" "table" | ||
|
||
Scenario: Delete multiple comments | ||
When I navigate to "Reports > Comments" in site administration | ||
And I click on "Select" "checkbox" in the "Uno" "table_row" | ||
And I click on "Select" "checkbox" in the "Dos" "table_row" | ||
And I press "Delete selected" | ||
And I click on "Delete" "button" in the "Delete selected" "dialogue" | ||
Then I should not see "Uno" in the "reportbuilder-table" "table" | ||
And I should not see "Dos" in the "reportbuilder-table" "table" | ||
And I should see "Tres" in the "reportbuilder-table" "table" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?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/>. | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Behat data generator for comments | ||
* | ||
* @package core_comment | ||
* @copyright 2022 Paul Holden <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class behat_core_comment_generator extends behat_generator_base { | ||
|
||
/** | ||
* Get a list of the entities that can be created for this component | ||
* | ||
* @return array[] | ||
*/ | ||
protected function get_creatable_entities(): array { | ||
return [ | ||
'Comments' => [ | ||
'singular' => 'Comment', | ||
'datagenerator' => 'comment', | ||
'required' => [ | ||
'contextlevel', | ||
'reference', | ||
'component', | ||
'area', | ||
'content', | ||
], | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* Pre-process comment, populate context property | ||
* | ||
* @param array $comment | ||
* @return array | ||
*/ | ||
protected function preprocess_comment(array $comment): array { | ||
$comment['context'] = $this->get_context($comment['contextlevel'], $comment['reference']); | ||
unset($comment['contextlevel'], $comment['reference']); | ||
|
||
return $comment; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?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/>. | ||
|
||
declare(strict_types=1); | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
global $CFG; | ||
require_once("{$CFG->dirroot}/comment/lib.php"); | ||
|
||
/** | ||
* Comment test generator | ||
* | ||
* @package core_comment | ||
* @copyright 2022 Paul Holden <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class core_comment_generator extends component_generator_base { | ||
|
||
/** | ||
* Create comment | ||
* | ||
* @param array|stdClass $record | ||
*/ | ||
public function create_comment($record): comment { | ||
$record = (array) $record; | ||
|
||
$content = $record['content'] ?? ''; | ||
unset($record['content']); | ||
|
||
$comment = new comment((object) $record); | ||
$comment->add($content); | ||
|
||
return $comment; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters