Commit db7178ed authored by Alfonso Salces's avatar Alfonso Salces
Browse files

MDL-74674 core: create notification generators

parent ceb41588
...@@ -287,6 +287,12 @@ class behat_core_generator extends behat_generator_base { ...@@ -287,6 +287,12 @@ class behat_core_generator extends behat_generator_base {
'required' => ['user', 'course', 'lastaccess'], 'required' => ['user', 'course', 'lastaccess'],
'switchids' => ['user' => 'userid', 'course' => 'courseid'], 'switchids' => ['user' => 'userid', 'course' => 'courseid'],
], ],
'notifications' => [
'singular' => 'notification',
'datagenerator' => 'notification',
'required' => ['subject', 'userfrom', 'userto'],
'switchids' => ['userfrom' => 'userfromid', 'userto' => 'usertoid'],
],
]; ];
return $entities; return $entities;
...@@ -1040,6 +1046,39 @@ class behat_core_generator extends behat_generator_base { ...@@ -1040,6 +1046,39 @@ class behat_core_generator extends behat_generator_base {
$DB->insert_record('badge_backpack', $backpack); $DB->insert_record('badge_backpack', $backpack);
} }
/**
* Creates notifications to specific user.
*
* @param array $data
* @return void
*/
protected function process_notification(array $data) {
global $DB;
$notification = new stdClass();
$notification->useridfrom = $data['userfromid'];
$notification->useridto = $data['usertoid'];
$notification->subject = $data['subject'];
$notification->fullmessage = $data['subject'] . ' description';
$notification->smallmessage = $data['subject'] . ' description';
$notification->fullmessagehtml = $data['subject'] . ' description';
if ($data['timecreated'] !== 'null') {
$notification->timecreated = $data['timecreated'];
}
if ($data['timeread'] !== 'null') {
$notification->timeread = $data['timeread'];
}
if (!empty($data)) {
$popupnotification = new stdClass();
$popupnotification->notificationid = $DB->insert_record('notifications', $notification);
$DB->insert_record('message_popup_notifications', $popupnotification);
}
}
/** /**
* Creates user last access data within given courses. * Creates user last access data within given courses.
* *
......
...@@ -316,6 +316,36 @@ abstract class behat_generator_base { ...@@ -316,6 +316,36 @@ abstract class behat_generator_base {
return $id; return $id;
} }
/**
* Gets the user id from it's username.
* @throws Exception
* @param string $username
* @return int
*/
protected function get_userfrom_id(string $username) {
global $DB;
if (!$id = $DB->get_field('user', 'id', ['username' => $username])) {
throw new Exception('The specified user with username "' . $username . '" does not exist');
}
return $id;
}
/**
* Gets the user id from it's username.
* @throws Exception
* @param string $username
* @return int
*/
protected function get_userto_id(string $username) {
global $DB;
if (!$id = $DB->get_field('user', 'id', ['username' => $username])) {
throw new Exception('The specified user with username "' . $username . '" does not exist');
}
return $id;
}
/** /**
* Gets the role id from it's shortname. * Gets the role id from it's shortname.
* @throws Exception * @throws Exception
......
...@@ -5,60 +5,41 @@ Feature: Notification popover unread notifications ...@@ -5,60 +5,41 @@ Feature: Notification popover unread notifications
I am notified about relevant events in Moodle I am notified about relevant events in Moodle
Background: Background:
# This will make sure popup notifications are enabled and create Given the following "users" exist:
# two assignment notifications. One for the student submitting their
# assignment and another for the teacher grading it.
Given the following "courses" exist:
| fullname | shortname | category | groupmode |
| Course 1 | C1 | 0 | 1 |
# Make sure the popup notifications are enabled for assignments.
And the following config values are set as admin:
| popup_provider_mod_assign_assign_notification_locked | 0 | message |
| message_provider_mod_assign_assign_notification_enabled | popup | message |
And the following "users" exist:
| username | firstname | lastname | email | | username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com | | student1 | Student | 1 | student1@example.com |
And the following "course enrolments" exist: | student2 | Student | 2 | student2@example.com |
| user | course | role | # This should generate some notifications
| teacher1 | C1 | editingteacher | And the following "notifications" exist:
| student1 | C1 | student | | subject | userfrom | userto | timecreated | timeread |
And the following "activity" exists: | Test 01 | student2 | student1 | 1654587996 | null |
| activity | assign | | Test 02 | student2 | student1 | 1654587997 | null |
| course | C1 |
| name | Test assignment name |
| assignsubmission_onlinetext_enabled | 1 |
| assignsubmission_file_enabled | 0 |
| submissiondrafts | 0 |
# This should generate a notification.
And the following "mod_assign > submissions" exist:
| assign | user | onlinetext |
| Test assignment name | student1 | I'm the student1 submission |
Scenario: Notification popover shows correct unread count Scenario: Notification popover shows correct unread count
When I log in as "student1" Given I log in as "student1"
# Confirm the popover is saying 1 unread notifications. # Confirm the popover is saying 1 unread notifications.
Then I should see "1" in the "#nav-notification-popover-container [data-region='count-container']" "css_element" And I should see "2" in the "#nav-notification-popover-container [data-region='count-container']" "css_element"
# Open the popover. # Open the popover.
And I open the notification popover When I open the notification popover
# Confirm the submission notification is visible. # Confirm the notifications are visible.
And I should see "You have submitted your assignment submission for Test assignment name" in the "#nav-notification-popover-container" "css_element" Then I should see "Test 01" in the "#nav-notification-popover-container" "css_element"
And I should see "Test 02" in the "#nav-notification-popover-container" "css_element"
@_bug_phantomjs @_bug_phantomjs
Scenario: Clicking a notification marks it as read Scenario: Clicking a notification marks it as read
When I log in as "student1" Given I log in as "student1"
# Open the popover. # Open the notifications.
When I open the notification popover
And I follow "Test 01"
And I open the notification popover And I open the notification popover
# Click on the submission notification. And I follow "Test 02"
And I follow "You have submitted your assignment submission for Test assignment name"
# Confirm the count element is hidden (i.e. there are no unread notifications). # Confirm the count element is hidden (i.e. there are no unread notifications).
Then "[data-region='count-container']" "css_element" in the "#nav-notification-popover-container" "css_element" should not be visible Then "[data-region='count-container']" "css_element" in the "#nav-notification-popover-container" "css_element" should not be visible
Scenario: Mark all notifications as read Scenario: Mark all notifications as read
When I log in as "student1" Given I log in as "student1"
# Open the popover. When I open the notification popover
And I open the notification popover
# Click the mark all as read button.
And I click on "Mark all as read" "link" in the "#nav-notification-popover-container" "css_element" And I click on "Mark all as read" "link" in the "#nav-notification-popover-container" "css_element"
# Refresh the page to make sure we send a new request for the unread count. # Refresh the page to make sure we send a new request for the unread count.
And I reload the page And I reload the page
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment