mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 00:42:54 +02:00
Merge branch 'MDL-75275-master' of https://github.com/sarjona/moodle
This commit is contained in:
commit
ce2c78251f
@ -276,6 +276,10 @@ class manager {
|
||||
$options['comments'] = true;
|
||||
$options['ratings'] = true;
|
||||
}
|
||||
if ($templatename === 'listtemplate') {
|
||||
// The "Show more" button should be only displayed in the listtemplate.
|
||||
$options['showmore'] = true;
|
||||
}
|
||||
return new template($this, $templatecontent, $options);
|
||||
}
|
||||
|
||||
|
@ -127,6 +127,7 @@ class template_editor_tools implements templatable, renderable {
|
||||
'##delete##' => get_string('delete', 'data'),
|
||||
'##approve##' => get_string('approve', 'data'),
|
||||
'##disapprove##' => get_string('disapprove', 'data'),
|
||||
'##actionsmenu##' => get_string('actionsmenu', 'data'),
|
||||
];
|
||||
if ($templatename != 'rsstemplate') {
|
||||
$taglist['##export##'] = get_string('export', 'data');
|
||||
|
@ -16,6 +16,8 @@
|
||||
|
||||
namespace mod_data;
|
||||
|
||||
use action_menu;
|
||||
use action_menu_link_secondary;
|
||||
use core\output\checkbox_toggleall;
|
||||
use html_writer;
|
||||
use mod_data\manager;
|
||||
@ -59,6 +61,9 @@ class template {
|
||||
/** @var bool if comments must be added if not present in the template. */
|
||||
private $forcecomments;
|
||||
|
||||
/** @var bool if show more option must be added. */
|
||||
private $showmore;
|
||||
|
||||
/** @var bool if the current user can manage entries. */
|
||||
private $canmanageentries = null;
|
||||
|
||||
@ -115,6 +120,7 @@ class template {
|
||||
$this->search = $options['search'] ?? null;
|
||||
$this->ratings = $options['ratings'] ?? false;
|
||||
$this->forcecomments = $options['comments'] ?? false;
|
||||
$this->showmore = $options['showmore'] ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -320,6 +326,11 @@ class template {
|
||||
*/
|
||||
protected function get_tag_more_replacement(stdClass $entry, bool $canmanageentry): string {
|
||||
global $OUTPUT;
|
||||
|
||||
if (!$this->showmore) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$url = new moodle_url($this->baseurl, [
|
||||
'rid' => $entry->id,
|
||||
'filter' => 1,
|
||||
@ -599,4 +610,123 @@ class template {
|
||||
return (string) $entry->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ##actionsmenu## tag replacement for an entry.
|
||||
*
|
||||
* @param stdClass $entry the entry object
|
||||
* @param bool $canmanageentry if the current user can manage this entry
|
||||
* @return string the tag replacement
|
||||
*/
|
||||
protected function get_tag_actionsmenu_replacement(stdClass $entry, bool $canmanageentry): string {
|
||||
global $OUTPUT, $CFG;
|
||||
|
||||
$actionmenu = new action_menu();
|
||||
$icon = $OUTPUT->pix_icon('i/menu', get_string('actions'));
|
||||
$actionmenu->set_menu_trigger($icon, 'btn btn-icon d-flex align-items-center justify-content-center');
|
||||
$actionmenu->set_action_label(get_string('actions'));
|
||||
$actionmenu->attributes['class'] .= ' entry-actionsmenu';
|
||||
|
||||
// Show more.
|
||||
if ($this->showmore) {
|
||||
$showmoreurl = new moodle_url($this->baseurl, [
|
||||
'rid' => $entry->id,
|
||||
'filter' => 1,
|
||||
]);
|
||||
$actionmenu->add(new action_menu_link_secondary(
|
||||
$showmoreurl,
|
||||
null,
|
||||
get_string('showmore', 'mod_data')
|
||||
));
|
||||
}
|
||||
|
||||
if ($canmanageentry) {
|
||||
// Edit entry.
|
||||
$backurl = new moodle_url($this->baseurl, [
|
||||
'rid' => $entry->id,
|
||||
'mode' => 'single',
|
||||
]);
|
||||
$editurl = new moodle_url('/mod/data/edit.php', $this->baseurl->params());
|
||||
$editurl->params([
|
||||
'rid' => $entry->id,
|
||||
'sesskey' => sesskey(),
|
||||
'backto' => urlencode($backurl->out(false))
|
||||
]);
|
||||
|
||||
$actionmenu->add(new action_menu_link_secondary(
|
||||
$editurl,
|
||||
null,
|
||||
get_string('edit')
|
||||
));
|
||||
|
||||
// Delete entry.
|
||||
$deleteurl = new moodle_url($this->baseurl, [
|
||||
'delete' => $entry->id,
|
||||
'sesskey' => sesskey(),
|
||||
'mode' => 'single',
|
||||
]);
|
||||
|
||||
$actionmenu->add(new action_menu_link_secondary(
|
||||
$deleteurl,
|
||||
null,
|
||||
get_string('delete')
|
||||
));
|
||||
}
|
||||
|
||||
// Approve/disapprove entry.
|
||||
$context = $this->manager->get_context();
|
||||
if (has_capability('mod/data:approve', $context) && $this->instance->approval) {
|
||||
if ($entry->approved) {
|
||||
$disapproveurl = new moodle_url($this->baseurl, [
|
||||
'disapprove' => $entry->id,
|
||||
'sesskey' => sesskey(),
|
||||
]);
|
||||
$actionmenu->add(new action_menu_link_secondary(
|
||||
$disapproveurl,
|
||||
null,
|
||||
get_string('disapprove', 'mod_data')
|
||||
));
|
||||
} else {
|
||||
$approveurl = new moodle_url($this->baseurl, [
|
||||
'approve' => $entry->id,
|
||||
'sesskey' => sesskey(),
|
||||
]);
|
||||
$actionmenu->add(new action_menu_link_secondary(
|
||||
$approveurl,
|
||||
null,
|
||||
get_string('approve', 'mod_data')
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// Export entry to portfolio.
|
||||
if (!empty($CFG->enableportfolios)) {
|
||||
// Check the user can export the entry.
|
||||
$cm = $this->manager->get_coursemodule();
|
||||
$canexportall = has_capability('mod/data:exportentry', $context);
|
||||
$canexportown = has_capability('mod/data:exportownentry', $context);
|
||||
if ($canexportall || (data_isowner($entry->id) && $canexportown)) {
|
||||
// Add the portfolio export button.
|
||||
require_once($CFG->libdir . '/portfoliolib.php');
|
||||
$button = new portfolio_add_button();
|
||||
$button->set_callback_options(
|
||||
'data_portfolio_caller',
|
||||
['id' => $cm->id, 'recordid' => $entry->id],
|
||||
'mod_data'
|
||||
);
|
||||
$fields = $this->manager->get_fields();
|
||||
list($formats, $files) = data_portfolio_caller::formats($fields, $entry);
|
||||
$button->set_formats($formats);
|
||||
$exporturl = $button->to_html(PORTFOLIO_ADD_MOODLE_URL);
|
||||
if (!is_null($exporturl)) {
|
||||
$actionmenu->add(new action_menu_link_secondary(
|
||||
$exporturl,
|
||||
null,
|
||||
get_string('addtoportfolio', 'portfolio')
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $OUTPUT->render($actionmenu);
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@
|
||||
*/
|
||||
|
||||
$string['action'] = 'Action';
|
||||
$string['actionsmenu'] = 'Actions menu';
|
||||
$string['add'] = 'Add entry';
|
||||
$string['addcomment'] = 'Add comment';
|
||||
$string['addentries'] = 'Add entries';
|
||||
@ -388,6 +389,7 @@ $string['selectedrequired'] = 'All selected required';
|
||||
$string['selectfields'] = 'Select fields';
|
||||
$string['selectexportoptions'] = 'Select export options';
|
||||
$string['showall'] = 'Show all entries';
|
||||
$string['showmore'] = 'Show more';
|
||||
$string['single'] = 'View single';
|
||||
$string['singleview'] = 'Single view';
|
||||
$string['singletemplate'] = 'Single template';
|
||||
|
@ -149,6 +149,7 @@
|
||||
padding-left: 10px;
|
||||
}
|
||||
|
||||
.preset_action_menu .dropdown-toggle::after {
|
||||
.preset_action_menu .dropdown-toggle::after,
|
||||
.entry-actionsmenu .dropdown-toggle::after {
|
||||
display: none;
|
||||
}
|
||||
|
@ -41,6 +41,10 @@
|
||||
{
|
||||
"name": "Actions",
|
||||
"tags": [
|
||||
{
|
||||
"tag": "##actionsmenu##",
|
||||
"tagname": "Actions menu - ##actionsmenu##"
|
||||
},
|
||||
{
|
||||
"tag": "##edit##",
|
||||
"tagname": "Edit - ##edit##"
|
||||
|
349
mod/data/tests/behat/actionsmenu_replacement.feature
Normal file
349
mod/data/tests/behat/actionsmenu_replacement.feature
Normal file
@ -0,0 +1,349 @@
|
||||
@mod @mod_data
|
||||
Feature: Users can add the ##actionsmenu## replacement to the database templates
|
||||
In order to display all the actions for entries in templates
|
||||
As a teacher
|
||||
I need to edit the templates and add the actionsmenu replacement
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||
| student1 | Student | 1 | student1@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 |
|
||||
| student1 | C1 | student |
|
||||
And the following "activities" exist:
|
||||
| activity | name | intro | course | idnumber |
|
||||
| data | Test database name | Database intro | C1 | data1 |
|
||||
And the following "mod_data > fields" exist:
|
||||
| database | type | name | description |
|
||||
| data1 | text | field1 | Test field description |
|
||||
| data1 | text | field2 | Test field 2 description |
|
||||
And the following "mod_data > templates" exist:
|
||||
| database | name |
|
||||
| data1 | singletemplate |
|
||||
| data1 | listtemplate |
|
||||
| data1 | addtemplate |
|
||||
| data1 | asearchtemplate |
|
||||
| data1 | rsstemplate |
|
||||
And the following "mod_data > entries" exist:
|
||||
| database | user | field1 | field2 |
|
||||
| data1 | student1 | Student entry 1 | Some student content 1 |
|
||||
| data1 | teacher1 | Teacher entry 1 | Some teacher content 1 |
|
||||
And I am on the "Test database name" "data activity" page logged in as teacher1
|
||||
And I navigate to "Templates" in current page administration
|
||||
And I set the following fields to these values:
|
||||
| Header | <table> |
|
||||
| Repeated entry | <tr><td>[[field1]]</td><td>##actionsmenu##</td><tr> |
|
||||
| Footer | </table> |
|
||||
And I click on "Save template" "button"
|
||||
And I set the field "Templates tertiary navigation" to "Single template"
|
||||
And I set the following fields to these values:
|
||||
| Single template | <table><tr><td>[[field1]]</td><td>[[field2]]</td><td>##actionsmenu##</td><tr></table> |
|
||||
And I click on "Save template" "button"
|
||||
|
||||
@javascript
|
||||
Scenario: The ##actionsmenu## replacement displays the expected actions with default settings depending on the user permissions
|
||||
Given I navigate to "Database" in current page administration
|
||||
# Teachers should be able to edit/delete all the entries.
|
||||
When I open the action menu in "Student entry 1" "table_row"
|
||||
Then I should see "Show more"
|
||||
And I should see "Edit"
|
||||
And I should see "Delete"
|
||||
But I should not see "Approve"
|
||||
And I should not see "Undo approval"
|
||||
And I should not see "Export to portfolio"
|
||||
And I press the escape key
|
||||
And I open the action menu in "Teacher entry 1" "table_row"
|
||||
And I should see "Show more"
|
||||
And I should see "Edit"
|
||||
And I should see "Delete"
|
||||
# Single view (for teacher).
|
||||
And I choose "Show more" in the open action menu
|
||||
And I should see "Teacher entry 1"
|
||||
And I should see "Some teacher content 1"
|
||||
And I should not see "Student entry 1"
|
||||
And I open the action menu in "Teacher entry 1" "table_row"
|
||||
And I should not see "Show more"
|
||||
And I should see "Edit"
|
||||
And I should see "Delete"
|
||||
And I should not see "Approve"
|
||||
And I should not see "Undo approval"
|
||||
And I should not see "Export to portfolio"
|
||||
And I press the escape key
|
||||
And I follow "Previous page"
|
||||
And I should see "Student entry 1"
|
||||
And I should see "Some student content 1"
|
||||
And I should not see "Teacher entry 1"
|
||||
And I open the action menu in "Student entry 1" "table_row"
|
||||
And I should not see "Show more"
|
||||
And I should see "Edit"
|
||||
And I should see "Delete"
|
||||
And I log out
|
||||
# Students only should edit/delete their entries.
|
||||
But I am on the "Test database name" "data activity" page logged in as student1
|
||||
And I open the action menu in "Student entry 1" "table_row"
|
||||
And I should see "Show more"
|
||||
And I should see "Edit"
|
||||
And I should see "Delete"
|
||||
And I should not see "Approve"
|
||||
And I should not see "Undo approval"
|
||||
And I should not see "Export to portfolio"
|
||||
And I press the escape key
|
||||
And I open the action menu in "Teacher entry 1" "table_row"
|
||||
And I should see "Show more"
|
||||
And I should not see "Edit"
|
||||
And I should not see "Delete"
|
||||
# Single view (for student).
|
||||
And I choose "Show more" in the open action menu
|
||||
And I should see "Teacher entry 1"
|
||||
And I should see "Some teacher content 1"
|
||||
And I should not see "Student entry 1"
|
||||
And I should not see "Actions" in the "Teacher entry 1" "table_row"
|
||||
And I follow "Previous page"
|
||||
And I should see "Student entry 1"
|
||||
And I should see "Some student content 1"
|
||||
And I should not see "Teacher entry 1"
|
||||
And I open the action menu in "Student entry 1" "table_row"
|
||||
And I should not see "Show more"
|
||||
And I should see "Edit"
|
||||
And I should see "Delete"
|
||||
And I should not see "Approve"
|
||||
And I should not see "Undo approval"
|
||||
And I should not see "Export to portfolio"
|
||||
|
||||
@javascript
|
||||
Scenario: The ##actionsmenu## replacement displays the Approval/Undo approval options
|
||||
Given I navigate to "Settings" in current page administration
|
||||
And I follow "Entries"
|
||||
And I set the field "Approval required" to "Yes"
|
||||
And I press "Save and display"
|
||||
When I navigate to "Database" in current page administration
|
||||
# Teachers should be able to approve/unapprove all the entries from list view.
|
||||
And I open the action menu in "Student entry 1" "table_row"
|
||||
Then I should see "Approve"
|
||||
And I should not see "Undo approval"
|
||||
And I choose "Approve" in the open action menu
|
||||
And I should see "Entry approved"
|
||||
And I press "Dismiss this notification"
|
||||
And I open the action menu in "Student entry 1" "table_row"
|
||||
And I should see "Undo approval"
|
||||
And I should not see "Approve" in the ".menu-action-text" "css_element"
|
||||
And I press the escape key
|
||||
And I open the action menu in "Teacher entry 1" "table_row"
|
||||
And I should see "Undo approval"
|
||||
And I should not see "Approve" in the ".menu-action-text" "css_element"
|
||||
# Single view (for teacher).
|
||||
And I choose "Show more" in the open action menu
|
||||
And I should see "Teacher entry 1"
|
||||
And I open the action menu in "Teacher entry 1" "table_row"
|
||||
And I should see "Undo approval"
|
||||
And I should not see "Approve"
|
||||
And I press the escape key
|
||||
And I follow "Previous page"
|
||||
And I should see "Student entry 1"
|
||||
And I open the action menu in "Student entry 1" "table_row"
|
||||
And I should not see "Approve"
|
||||
And I should see "Undo approval"
|
||||
# Check entries can be approved/unapproved from single view too.
|
||||
And I choose "Undo approval" in the open action menu
|
||||
And I should see "Entry unapproved"
|
||||
And I press "Dismiss this notification"
|
||||
And I open the action menu in "Student entry 1" "table_row"
|
||||
And I should see "Approve"
|
||||
And I should not see "Undo approval"
|
||||
And I log out
|
||||
# Students should not see the Approve/Undo approval options.
|
||||
But I am on the "Test database name" "data activity" page logged in as student1
|
||||
And I open the action menu in "Teacher entry 1" "table_row"
|
||||
And I should not see "Approve"
|
||||
And I should not see "Undo approval"
|
||||
And I press the escape key
|
||||
And I open the action menu in "Student entry 1" "table_row"
|
||||
And I should not see "Approve"
|
||||
And I should not see "Undo approval"
|
||||
# Single view (for student).
|
||||
And I choose "Show more" in the open action menu
|
||||
And I should see "Student entry 1"
|
||||
And I open the action menu in "Student entry 1" "table_row"
|
||||
And I should not see "Approve"
|
||||
And I should not see "Undo approval"
|
||||
And I follow "Next page"
|
||||
And I should see "Teacher entry 1"
|
||||
And I should not see "Actions" in the "Teacher entry 1" "table_row"
|
||||
|
||||
@javascript
|
||||
Scenario: The ##actionsmenu## replacement displays the Export to portfolio options
|
||||
Given I log in as "admin"
|
||||
And the following config values are set as admin:
|
||||
| enableportfolios | 1 |
|
||||
And I navigate to "Plugins > Portfolios > Manage portfolios" in site administration
|
||||
And I set portfolio instance "File download" to "Enabled and visible"
|
||||
And I click on "Save" "button"
|
||||
And I log out
|
||||
And I am on the "Test database name" "data activity" page logged in as teacher1
|
||||
# Teachers should be able to export to portfolio all the entries from list view.
|
||||
When I open the action menu in "Student entry 1" "table_row"
|
||||
Then I should see "Export to portfolio"
|
||||
And I choose "Export to portfolio" in the open action menu
|
||||
And I should see "Configure exported data"
|
||||
And I press "Cancel"
|
||||
And I click on "Yes" "button" in the "Confirm" "dialogue"
|
||||
And I open the action menu in "Teacher entry 1" "table_row"
|
||||
And I should see "Export to portfolio"
|
||||
# Single view (for teacher).
|
||||
And I choose "Show more" in the open action menu
|
||||
And I should see "Teacher entry 1"
|
||||
And I open the action menu in "Teacher entry 1" "table_row"
|
||||
And I should see "Export to portfolio"
|
||||
And I press the escape key
|
||||
And I follow "Previous page"
|
||||
And I should see "Student entry 1"
|
||||
And I open the action menu in "Student entry 1" "table_row"
|
||||
And I should see "Export to portfolio"
|
||||
# Check entries can be exported from single view too.
|
||||
And I choose "Export to portfolio" in the open action menu
|
||||
And I should see "Configure exported data"
|
||||
And I log out
|
||||
# Students should only export their entries.
|
||||
But I am on the "Test database name" "data activity" page logged in as student1
|
||||
And I open the action menu in "Teacher entry 1" "table_row"
|
||||
And I should not see "Export to portfolio"
|
||||
And I press the escape key
|
||||
And I open the action menu in "Student entry 1" "table_row"
|
||||
And I should see "Export to portfolio"
|
||||
And I choose "Export to portfolio" in the open action menu
|
||||
And I should see "Configure exported data"
|
||||
And I press "Cancel"
|
||||
And I click on "Yes" "button" in the "Confirm" "dialogue"
|
||||
And I open the action menu in "Teacher entry 1" "table_row"
|
||||
# Single view (for student).
|
||||
And I choose "Show more" in the open action menu
|
||||
And I should see "Teacher entry 1"
|
||||
And I should not see "Actions" in the "Teacher entry 1" "table_row"
|
||||
And I follow "Previous page"
|
||||
And I should see "Student entry 1"
|
||||
And I open the action menu in "Student entry 1" "table_row"
|
||||
And I should see "Export to portfolio"
|
||||
And I choose "Export to portfolio" in the open action menu
|
||||
And I should see "Configure exported data"
|
||||
|
||||
@javascript
|
||||
Scenario: The ##actionsmenu## replacement does not display the Export to portfolio option when there are no portfolios enabled
|
||||
Given I log in as "admin"
|
||||
And the following config values are set as admin:
|
||||
| enableportfolios | 1 |
|
||||
And I log out
|
||||
And I am on the "Test database name" "data activity" page logged in as teacher1
|
||||
When I open the action menu in "Student entry 1" "table_row"
|
||||
Then I should not see "Export to portfolio"
|
||||
And I log out
|
||||
# If we enable, at least, one portfolio, the Export to portfolio option should be displayed.
|
||||
But I log in as "admin"
|
||||
And I navigate to "Plugins > Portfolios > Manage portfolios" in site administration
|
||||
And I set portfolio instance "File download" to "Enabled and visible"
|
||||
And I click on "Save" "button"
|
||||
And I log out
|
||||
And I am on the "Test database name" "data activity" page logged in as teacher1
|
||||
And I open the action menu in "Student entry 1" "table_row"
|
||||
And I should see "Export to portfolio"
|
||||
|
||||
@javascript
|
||||
Scenario: The Edit option in the ##actionsmenu## replacement is working
|
||||
Given I navigate to "Database" in current page administration
|
||||
# Teachers should be able to edit any entry.
|
||||
And I open the action menu in "Student entry 1" "table_row"
|
||||
When I choose "Edit" in the open action menu
|
||||
And I set the field "field2" to "Some MODIFIED BY THE TEACHER student content 1"
|
||||
And I click on "Save" "button"
|
||||
# Single view (for teacher).
|
||||
Then I should see "Some MODIFIED BY THE TEACHER student content 1"
|
||||
And I should not see "Some student content 1"
|
||||
And I open the action menu in "Student entry 1" "table_row"
|
||||
And I choose "Edit" in the open action menu
|
||||
And I set the field "field2" to "Some MORE TEACHER MODIFICATIONS FOR student content 1"
|
||||
And I click on "Save" "button"
|
||||
And I should see "Some MORE TEACHER MODIFICATIONS FOR student content 1"
|
||||
And I should not see "Some MODIFIED BY THE TEACHER student content 1"
|
||||
And I log out
|
||||
# Students only should edit their entries.
|
||||
But I am on the "Test database name" "data activity" page logged in as student1
|
||||
And I open the action menu in "Student entry 1" "table_row"
|
||||
And I choose "Edit" in the open action menu
|
||||
And I set the field "field2" to "Some MODIFIED student content 1"
|
||||
And I click on "Save" "button"
|
||||
# Single view (for student).
|
||||
And I should see "Some MODIFIED student content 1"
|
||||
And I should not see "Some MORE TEACHER MODIFICATIONS FOR student content 1"
|
||||
And I open the action menu in "Student entry 1" "table_row"
|
||||
And I choose "Edit" in the open action menu
|
||||
And I set the field "field2" to "Some MORE MODIFICATIONS FOR student content 1"
|
||||
And I click on "Save" "button"
|
||||
And I should see "Some MORE MODIFICATIONS FOR student content 1"
|
||||
And I should not see "Some MODIFIED student content 1"
|
||||
|
||||
@javascript
|
||||
Scenario: The Delete option in the ##actionsmenu## replacement is working
|
||||
Given the following "mod_data > entries" exist:
|
||||
| database | user | field1 | field2 |
|
||||
| data1 | student1 | Student entry 2 | Some student content 2 |
|
||||
| data1 | teacher1 | Teacher entry 2 | Some teacher content 2 |
|
||||
And I navigate to "Database" in current page administration
|
||||
# Teachers should be able to delete any entry.
|
||||
And I open the action menu in "Student entry 1" "table_row"
|
||||
When I choose "Delete" in the open action menu
|
||||
Then I should see "Delete entry"
|
||||
# Cancel doesn't delete the entry.
|
||||
And I click on "Cancel" "button" in the "Confirm" "dialogue"
|
||||
And I open the action menu in "Teacher entry 1" "table_row"
|
||||
# But Delete removes the entry.
|
||||
And I choose "Delete" in the open action menu
|
||||
And I should see "Delete entry"
|
||||
And I click on "Delete" "button" in the "Confirm" "dialogue"
|
||||
And I should see "Entry deleted"
|
||||
And I should not see "Teacher entry 1"
|
||||
And I should see "Teacher entry 2"
|
||||
And I should see "Student entry 1"
|
||||
And I should see "Student entry 2"
|
||||
# Single view (for teacher).
|
||||
And I open the action menu in "Teacher entry 2" "table_row"
|
||||
And I choose "Delete" in the open action menu
|
||||
And I should see "Delete entry"
|
||||
And I click on "Delete" "button" in the "Confirm" "dialogue"
|
||||
And I should see "Entry deleted"
|
||||
And I should not see "Teacher entry 1"
|
||||
And I should not see "Teacher entry 2"
|
||||
And I should see "Student entry 1"
|
||||
And I should see "Student entry 2"
|
||||
And I log out
|
||||
# Students only should edit their entries.
|
||||
But I am on the "Test database name" "data activity" page logged in as student1
|
||||
And I open the action menu in "Student entry 1" "table_row"
|
||||
When I choose "Delete" in the open action menu
|
||||
Then I should see "Delete entry"
|
||||
# Cancel doesn't delete the entry.
|
||||
And I click on "Cancel" "button" in the "Confirm" "dialogue"
|
||||
And I open the action menu in "Student entry 1" "table_row"
|
||||
# But Delete removes the entry.
|
||||
And I choose "Delete" in the open action menu
|
||||
And I should see "Delete entry"
|
||||
And I click on "Delete" "button" in the "Confirm" "dialogue"
|
||||
And I should see "Entry deleted"
|
||||
And I should not see "Teacher entry 1"
|
||||
And I should not see "Teacher entry 2"
|
||||
And I should not see "Student entry 1"
|
||||
And I should see "Student entry 2"
|
||||
# Single view (for student).
|
||||
And I open the action menu in "Student entry 2" "table_row"
|
||||
And I choose "Delete" in the open action menu
|
||||
And I should see "Delete entry"
|
||||
And I click on "Delete" "button" in the "Confirm" "dialogue"
|
||||
And I should see "Entry deleted"
|
||||
And I should not see "Teacher entry 1"
|
||||
And I should not see "Teacher entry 2"
|
||||
And I should not see "Student entry 1"
|
||||
And I should not see "Student entry 2"
|
@ -35,7 +35,7 @@ class behat_mod_data_generator extends behat_generator_base {
|
||||
'singular' => 'entry',
|
||||
'datagenerator' => 'entry',
|
||||
'required' => ['database'],
|
||||
'switchids' => ['database' => 'databaseid'],
|
||||
'switchids' => ['database' => 'databaseid', 'user' => 'userid'],
|
||||
],
|
||||
'fields' => [
|
||||
'singular' => 'field',
|
||||
@ -81,6 +81,11 @@ class behat_mod_data_generator extends behat_generator_base {
|
||||
$database = $DB->get_record('data', ['id' => $data['databaseid']], '*', MUST_EXIST);
|
||||
|
||||
unset($data['databaseid']);
|
||||
$userid = 0;
|
||||
if (array_key_exists('userid', $data)) {
|
||||
$userid = $data['userid'];
|
||||
unset($data['userid']);
|
||||
}
|
||||
|
||||
$data = array_reduce(array_keys($data), function ($fields, $fieldname) use ($data, $database) {
|
||||
global $DB;
|
||||
@ -92,7 +97,7 @@ class behat_mod_data_generator extends behat_generator_base {
|
||||
return $fields;
|
||||
}, []);
|
||||
|
||||
$this->get_data_generator()->create_entry($database, $data);
|
||||
$this->get_data_generator()->create_entry($database, $data, 0, [], null, $userid);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -208,11 +208,19 @@ class mod_data_generator extends testing_module_generator {
|
||||
* @param int $groupid
|
||||
* @param array $tags
|
||||
* @param array $options
|
||||
* @param int $userid if defined, it will be the author of the entry
|
||||
* @return int id of the generated record in table {data_records}
|
||||
*/
|
||||
public function create_entry($data, array $contents, $groupid = 0, $tags = [], array $options = null) {
|
||||
public function create_entry($data, array $contents, $groupid = 0, $tags = [], array $options = null, int $userid = 0) {
|
||||
global $DB, $USER, $CFG;
|
||||
|
||||
// Set current user if defined.
|
||||
if (!empty($userid)) {
|
||||
$currentuser = $USER;
|
||||
$user = \core_user::get_user($userid);
|
||||
$this->set_user($user);
|
||||
}
|
||||
|
||||
$this->databaserecordcount++;
|
||||
|
||||
$recordid = data_add_record($data, $groupid);
|
||||
@ -362,6 +370,10 @@ class mod_data_generator extends testing_module_generator {
|
||||
context_module::instance($cm->id), $tags);
|
||||
}
|
||||
|
||||
if (isset($currentuser)) {
|
||||
$this->set_user($currentuser);
|
||||
}
|
||||
|
||||
return $recordid;
|
||||
}
|
||||
|
||||
|
@ -191,11 +191,41 @@ class template_test extends \advanced_testcase {
|
||||
'templatecontent' => 'Some ##more## tag',
|
||||
'expected' => '|Some .*more.*{cmid}.*rid.*{entryid}.*More.* tag|',
|
||||
'rolename' => 'editingteacher',
|
||||
'enableexport' => false,
|
||||
'approved' => true,
|
||||
'enablecomments' => false,
|
||||
'enableratings' => false,
|
||||
'options' => ['showmore' => true],
|
||||
],
|
||||
'Teacher more tag with showmore set to false' => [
|
||||
'templatecontent' => 'Some ##more## tag',
|
||||
'expected' => '|Some tag|',
|
||||
'rolename' => 'editingteacher',
|
||||
'enableexport' => false,
|
||||
'approved' => true,
|
||||
'enablecomments' => false,
|
||||
'enableratings' => false,
|
||||
'options' => ['showmore' => false],
|
||||
],
|
||||
'Teacher moreurl tag' => [
|
||||
'templatecontent' => 'Some ##moreurl## tag',
|
||||
'expected' => '|Some .*/mod/data/view.*{cmid}.*rid.*{entryid}.* tag|',
|
||||
'rolename' => 'editingteacher',
|
||||
'enableexport' => false,
|
||||
'approved' => true,
|
||||
'enablecomments' => false,
|
||||
'enableratings' => false,
|
||||
'options' => ['showmore' => true],
|
||||
],
|
||||
'Teacher moreurl tag with showmore set to false' => [
|
||||
'templatecontent' => 'Some ##moreurl## tag',
|
||||
'expected' => '|Some .*/mod/data/view.*{cmid}.*rid.*{entryid}.* tag|',
|
||||
'rolename' => 'editingteacher',
|
||||
'enableexport' => false,
|
||||
'approved' => true,
|
||||
'enablecomments' => false,
|
||||
'enableratings' => false,
|
||||
'options' => ['showmore' => false],
|
||||
],
|
||||
'Teacher delcheck tag' => [
|
||||
'templatecontent' => 'Some ##delcheck## tag',
|
||||
@ -361,6 +391,49 @@ class template_test extends \advanced_testcase {
|
||||
'enableratings' => true,
|
||||
'options' => ['ratings' => true],
|
||||
],
|
||||
'Teacher actionsmenu tag with default options' => [
|
||||
'templatecontent' => 'Some ##actionsmenu## tag',
|
||||
'expected' => '|Some .*edit.*{entryid}.*sesskey.*Edit.* .*delete.*{entryid}.*sesskey.*Delete.* tag|',
|
||||
'rolename' => 'editingteacher',
|
||||
],
|
||||
'Teacher actionsmenu tag with default options (check Show more is not there)' => [
|
||||
'templatecontent' => 'Some ##actionsmenu## tag',
|
||||
'expected' => '|^Some((?!Show more).)*tag$|',
|
||||
'rolename' => 'editingteacher',
|
||||
],
|
||||
'Teacher actionsmenu tag with show more enabled' => [
|
||||
'templatecontent' => 'Some ##actionsmenu## tag',
|
||||
'expected' => '|Some .*view.*{cmid}.*rid.*{entryid}.*Show more.* .*Edit.* .*Delete.* tag|',
|
||||
'rolename' => 'editingteacher',
|
||||
'enableexport' => false,
|
||||
'approved' => false,
|
||||
'enablecomments' => false,
|
||||
'enableratings' => false,
|
||||
'options' => ['showmore' => true],
|
||||
],
|
||||
'Teacher actionsmenu tag with export enabled' => [
|
||||
'templatecontent' => 'Some ##actionsmenu## tag',
|
||||
'expected' => '|Some .*Edit.* .*Delete.* .*portfolio/add.* tag|',
|
||||
'rolename' => 'editingteacher',
|
||||
'enableexport' => true,
|
||||
],
|
||||
'Teacher actionsmenu tag with approved enabled' => [
|
||||
'templatecontent' => 'Some ##actionsmenu## tag',
|
||||
'expected' => '|Some .*Edit.* .*Delete.* .*disapprove.*{entryid}.*sesskey.*Undo approval.* tag|',
|
||||
'rolename' => 'editingteacher',
|
||||
'enableexport' => false,
|
||||
'approved' => true,
|
||||
],
|
||||
'Teacher actionsmenu tag with export, approved and showmore enabled' => [
|
||||
'templatecontent' => 'Some ##actionsmenu## tag',
|
||||
'expected' => '|Some .*Show more.* .*Edit.* .*Delete.* .*Undo approval.* .*Export to portfolio.* tag|',
|
||||
'rolename' => 'editingteacher',
|
||||
'enableexport' => true,
|
||||
'approved' => true,
|
||||
'enablecomments' => false,
|
||||
'enableratings' => false,
|
||||
'options' => ['showmore' => true],
|
||||
],
|
||||
// Student scenarios.
|
||||
'Student id tag' => [
|
||||
'templatecontent' => 'Some ##id## tag',
|
||||
@ -403,11 +476,41 @@ class template_test extends \advanced_testcase {
|
||||
'templatecontent' => 'Some ##more## tag',
|
||||
'expected' => '|Some .*more.*{cmid}.*rid.*{entryid}.*More.* tag|',
|
||||
'rolename' => 'student',
|
||||
'enableexport' => false,
|
||||
'approved' => true,
|
||||
'enablecomments' => false,
|
||||
'enableratings' => false,
|
||||
'options' => ['showmore' => true],
|
||||
],
|
||||
'Student more tag with showmore set to false' => [
|
||||
'templatecontent' => 'Some ##more## tag',
|
||||
'expected' => '|Some tag|',
|
||||
'rolename' => 'student',
|
||||
'enableexport' => false,
|
||||
'approved' => true,
|
||||
'enablecomments' => false,
|
||||
'enableratings' => false,
|
||||
'options' => ['showmore' => false],
|
||||
],
|
||||
'Student moreurl tag' => [
|
||||
'templatecontent' => 'Some ##moreurl## tag',
|
||||
'expected' => '|Some .*/mod/data/view.*{cmid}.*rid.*{entryid}.* tag|',
|
||||
'rolename' => 'student',
|
||||
'enableexport' => false,
|
||||
'approved' => true,
|
||||
'enablecomments' => false,
|
||||
'enableratings' => false,
|
||||
'options' => ['showmore' => true],
|
||||
],
|
||||
'Student moreurl tag with showmore set to false' => [
|
||||
'templatecontent' => 'Some ##moreurl## tag',
|
||||
'expected' => '|Some .*/mod/data/view.*{cmid}.*rid.*{entryid}.* tag|',
|
||||
'rolename' => 'student',
|
||||
'enableexport' => false,
|
||||
'approved' => true,
|
||||
'enablecomments' => false,
|
||||
'enableratings' => false,
|
||||
'options' => ['showmore' => false],
|
||||
],
|
||||
'Student delcheck tag' => [
|
||||
'templatecontent' => 'Some ##delcheck## tag',
|
||||
@ -584,6 +687,49 @@ class template_test extends \advanced_testcase {
|
||||
'enableratings' => true,
|
||||
'options' => ['ratings' => true]
|
||||
],
|
||||
'Student actionsmenu tag with default options' => [
|
||||
'templatecontent' => 'Some ##actionsmenu## tag',
|
||||
'expected' => '|Some .*edit.*{entryid}.*sesskey.*Edit.* .*delete.*{entryid}.*sesskey.*Delete.* tag|',
|
||||
'rolename' => 'student',
|
||||
],
|
||||
'Student actionsmenu tag with default options (check Show more is not there)' => [
|
||||
'templatecontent' => 'Some ##actionsmenu## tag',
|
||||
'expected' => '|^Some((?!Show more).)*tag$|',
|
||||
'rolename' => 'student',
|
||||
],
|
||||
'Student actionsmenu tag with show more enabled' => [
|
||||
'templatecontent' => 'Some ##actionsmenu## tag',
|
||||
'expected' => '|Some .*view.*{cmid}.*rid.*{entryid}.*Show more.* .*Edit.* .*Delete.* tag|',
|
||||
'rolename' => 'student',
|
||||
'enableexport' => false,
|
||||
'approved' => false,
|
||||
'enablecomments' => false,
|
||||
'enableratings' => false,
|
||||
'options' => ['showmore' => true],
|
||||
],
|
||||
'Student actionsmenu tag with export enabled' => [
|
||||
'templatecontent' => 'Some ##actionsmenu## tag',
|
||||
'expected' => '|Some .*Edit.* .*Delete.* .*portfolio/add.* tag|',
|
||||
'rolename' => 'student',
|
||||
'enableexport' => true,
|
||||
],
|
||||
'Student actionsmenu tag with approved enabled' => [
|
||||
'templatecontent' => 'Some ##actionsmenu## tag',
|
||||
'expected' => '|^Some((?!Approve).)*tag$|',
|
||||
'rolename' => 'student',
|
||||
'enableexport' => false,
|
||||
'approved' => true,
|
||||
],
|
||||
'Student actionsmenu tag with export, approved and showmore enabled' => [
|
||||
'templatecontent' => 'Some ##actionsmenu## tag',
|
||||
'expected' => '|Some .*Show more.* .*Edit.* .*Delete.* .*Export to portfolio.* tag|',
|
||||
'rolename' => 'student',
|
||||
'enableexport' => true,
|
||||
'approved' => true,
|
||||
'enablecomments' => false,
|
||||
'enableratings' => false,
|
||||
'options' => ['showmore' => true],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user