Skip to content

Commit

Permalink
MDL-67853 message: Adapt tests removing online/offline settings
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyserver committed Jan 27, 2022
1 parent d74bd79 commit b4c7598
Show file tree
Hide file tree
Showing 15 changed files with 188 additions and 72 deletions.
2 changes: 1 addition & 1 deletion admin/tool/mobile/tests/api_test.php
Expand Up @@ -107,7 +107,7 @@ public function test_pre_processor_message_send_callback() {
set_config('allowedemaildomains', 'example.com');

$DB->set_field_select('message_processors', 'enabled', 0, "name <> 'email'");
set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'email', $user2);
set_user_preference('message_provider_moodle_instantmessage_enabled', 'email', $user2);

// Extra content for all types of messages.
$message = new \core\message\message();
Expand Down
4 changes: 2 additions & 2 deletions admin/tool/monitor/tests/behat/subscription.feature
Expand Up @@ -103,7 +103,7 @@ Feature: tool_monitor_subscriptions
Given I log in as "admin"
And I follow "Preferences" in the user menu
And I click on "Notification preferences" "link" in the "#page-content" "css_element"
And I click on "//td[@data-processor-name='popup']//label[@data-state='loggedin']" "xpath_element" in the "Notifications of rule subscriptions" "table_row"
And I click on "//td[@data-processor-name='popup']//div[@class='preference-state']" "xpath_element" in the "Notifications of rule subscriptions" "table_row"
And I wait until the page is ready
And I follow "Preferences" in the user menu
And I follow "Event monitoring"
Expand All @@ -124,7 +124,7 @@ Feature: tool_monitor_subscriptions
Given I log in as "teacher1"
And I follow "Preferences" in the user menu
And I click on "Notification preferences" "link" in the "#page-content" "css_element"
And I click on "//td[@data-processor-name='popup']//label[@data-state='loggedin']" "xpath_element" in the "Notifications of rule subscriptions" "table_row"
And I click on "//td[@data-processor-name='popup']//div[@class='preference-state']" "xpath_element" in the "Notifications of rule subscriptions" "table_row"
And I wait until the page is ready
And I follow "Preferences" in the user menu
And I follow "Event monitoring"
Expand Down
2 changes: 1 addition & 1 deletion badges/tests/badgeslib_test.php
Expand Up @@ -305,7 +305,7 @@ public function test_badge_awards() {
$sink = $this->redirectMessages();

$DB->set_field_select('message_processors', 'enabled', 0, "name <> 'email'");
set_user_preference('message_provider_moodle_badgerecipientnotice_loggedoff', 'email', $user1);
set_user_preference('message_provider_moodle_badgerecipientnotice_enabled', 'email', $user1);

$badge->issue($user1->id, false);
$this->assertDebuggingCalled(); // Expect debugging while baking a badge via phpunit.
Expand Down
4 changes: 2 additions & 2 deletions lib/tests/message_test.php
Expand Up @@ -144,7 +144,7 @@ public function test_send_message() {
$this->assertFileExists("$CFG->dirroot/message/output/popup/version.php");

$DB->set_field_select('message_processors', 'enabled', 0, "name <> 'email'");
set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'email', $user2);
set_user_preference('message_provider_moodle_instantmessage_enabled', 'email', $user2);

// Extra content for all types of messages.
$message = new \core\message\message();
Expand Down Expand Up @@ -241,7 +241,7 @@ public function test_send_message_with_prefix() {
$this->assertFileExists("$CFG->dirroot/message/output/popup/version.php");

$DB->set_field_select('message_processors', 'enabled', 0, "name <> 'email'");
set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'email', $user2);
set_user_preference('message_provider_moodle_instantmessage_enabled', 'email', $user2);

// Check that prefix is ammended to the subject of the email.
$message = new \core\message\message();
Expand Down
26 changes: 13 additions & 13 deletions lib/tests/messagelib_test.php
Expand Up @@ -412,7 +412,7 @@ public function test_send_message() {
$eventsink = $this->redirectEvents();

// Will always use the pop-up processor.
set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'none', $user2);
set_user_preference('message_provider_moodle_instantmessage_enabled', 'none', $user2);

$message = new \core\message\message();
$message->courseid = 1;
Expand Down Expand Up @@ -500,7 +500,7 @@ public function test_send_message() {
$eventsink->clear();

// Will always use the pop-up processor.
set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'email', $user2);
set_user_preference('message_provider_moodle_instantmessage_enabled', 'email', $user2);

$message = new \core\message\message();
$message->courseid = 1;
Expand Down Expand Up @@ -533,7 +533,7 @@ public function test_send_message() {
$user2->emailstop = '0';

// Will always use the pop-up processor.
set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'email', $user2);
set_user_preference('message_provider_moodle_instantmessage_enabled', 'email', $user2);

$message = new \core\message\message();
$message->courseid = 1;
Expand Down Expand Up @@ -566,7 +566,7 @@ public function test_send_message() {
$this->assertInstanceOf('\core\event\message_sent', $events[0]);
$eventsink->clear();

set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'email,popup', $user2);
set_user_preference('message_provider_moodle_instantmessage_enabled', 'email,popup', $user2);

$message = new \core\message\message();
$message->courseid = 1;
Expand Down Expand Up @@ -600,7 +600,7 @@ public function test_send_message() {
$this->assertInstanceOf('\core\event\message_sent', $events[0]);
$eventsink->clear();

set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'popup', $user2);
set_user_preference('message_provider_moodle_instantmessage_enabled', 'popup', $user2);

$message = new \core\message\message();
$message->courseid = 1;
Expand Down Expand Up @@ -635,7 +635,7 @@ public function test_send_message() {
$transaction->allow_commit();

// Will always use the pop-up processor.
set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'none', $user2);
set_user_preference('message_provider_moodle_instantmessage_enabled', 'none', $user2);

$message = new \core\message\message();
$message->courseid = 1;
Expand Down Expand Up @@ -668,7 +668,7 @@ public function test_send_message() {
$this->assertInstanceOf('\core\event\message_sent', $events[0]);

// Will always use the pop-up processor.
set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'email', $user2);
set_user_preference('message_provider_moodle_instantmessage_enabled', 'email', $user2);

$message = new \core\message\message();
$message->courseid = 1;
Expand Down Expand Up @@ -783,7 +783,7 @@ public function test_message_send_to_conversation_individual() {

// Ensure we're going to hit the email processor for this user.
$DB->set_field_select('message_processors', 'enabled', 0, "name <> 'email'");
set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'email', $user2);
set_user_preference('message_provider_moodle_instantmessage_enabled', 'email', $user2);

// Now, send a message and verify the message processors (in this case, email) are hit.
$sink = $this->redirectEmails();
Expand Down Expand Up @@ -869,7 +869,7 @@ public function test_message_send_to_self_conversation() {

// Ensure we're going to hit the email processor for this user.
$DB->set_field_select('message_processors', 'enabled', 0, "name <> 'email'");
set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'email', $user1);
set_user_preference('message_provider_moodle_instantmessage_enabled', 'email', $user1);

// Now, send a message and verify the message processors are empty (self-conversations are not processed for now).
$sink = $this->redirectEmails();
Expand Down Expand Up @@ -941,8 +941,8 @@ public function test_message_send_to_conversation_group() {

// Ensure the email processor is enabled for the recipient users.
$DB->set_field_select('message_processors', 'enabled', 0, "name <> 'email'");
set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'email', $user2);
set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'email', $user3);
set_user_preference('message_provider_moodle_instantmessage_enabled', 'email', $user2);
set_user_preference('message_provider_moodle_instantmessage_enabled', 'email', $user3);

// Now, send a message and verify the email processor are hit.
$messageid = message_send($message);
Expand Down Expand Up @@ -1016,8 +1016,8 @@ public function test_send_message_to_conversation_group_with_buffering() {
$eventsink = $this->redirectEvents();

// Will always use the pop-up processor.
set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'email', $user2);
set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'email', $user3);
set_user_preference('message_provider_moodle_instantmessage_enabled', 'email', $user2);
set_user_preference('message_provider_moodle_instantmessage_enabled', 'email', $user3);

$message = new \core\message\message();
$message->courseid = 1;
Expand Down
2 changes: 1 addition & 1 deletion message/output/airnotifier/classes/privacy/provider.php
Expand Up @@ -68,7 +68,7 @@ public static function get_metadata(collection $collection) : collection {
'smallmessage' => 'privacy:metadata:smallmessage',
'fullmessage' => 'privacy:metadata:fullmessage'
], 'privacy:metadata:externalpurpose');
// This system is unaware of user preferences such as message_provider_moodle_instantmessage_loggedin.
// This system is unaware of user preferences such as message_provider_moodle_instantmessage_enabled.
return $collection;
}

Expand Down
1 change: 0 additions & 1 deletion message/output/airnotifier/externallib.php
Expand Up @@ -149,7 +149,6 @@ public static function are_notification_preferences_configured($userids) {
break;
}


$prefstocheck = [];
$prefname = 'message_provider_'.$provider->component.'_'.$provider->name.'_enabled';

Expand Down
22 changes: 4 additions & 18 deletions message/output/airnotifier/tests/externallib_test.php
Expand Up @@ -86,10 +86,8 @@ public function test_are_notification_preferences_configured() {

self::setUser($user1);

set_user_preference('message_provider_moodle_instantmessage_loggedin', 'airnotifier', $user1);
set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'airnotifier', $user1);
set_user_preference('message_provider_moodle_instantmessage_loggedin', 'airnotifier', $user2);
set_user_preference('message_provider_moodle_instantmessage_loggedin', 'airnotifier', $user3);
set_user_preference('message_provider_moodle_instantmessage_enabled', 'airnotifier', $user1);
set_user_preference('message_provider_moodle_instantmessage_enabled', 'airnotifier', $user2);

$params = array($user1->id, $user2->id, $user3->id);

Expand All @@ -116,23 +114,11 @@ public function test_are_notification_preferences_configured() {
$this->assertEquals($expected, $preferences['users']);
$this->assertEquals(2, count($preferences['warnings']));

// Now, remove one user1 preference (the user still has one prefernce for airnotifier).
unset_user_preference('message_provider_moodle_instantmessage_loggedin', $user1);
// Now, remove one user1 preference (the user still has one preference for airnotifier).
unset_user_preference('message_provider_moodle_instantmessage_enabled', $user1);
$preferences = message_airnotifier_external::are_notification_preferences_configured($params);
$preferences = external_api::clean_returnvalue($returnsdescription, $preferences);
$this->assertEquals($expected, $preferences['users']);

// Delete the last user1 preference.
unset_user_preference('message_provider_moodle_instantmessage_loggedoff', $user1);
$preferences = message_airnotifier_external::are_notification_preferences_configured($params);
$preferences = external_api::clean_returnvalue($returnsdescription, $preferences);
$expected = array(
array(
'userid' => $user1->id,
'configured' => 1
)
);
$this->assertEquals($expected, $preferences['users']);
}

/**
Expand Down
Expand Up @@ -13,9 +13,8 @@ Feature: Notification popover unread notifications
| 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_permitted | permitted | message |
| message_provider_mod_assign_assign_notification_loggedin | popup | message |
| message_provider_mod_assign_assign_notification_loggedoff | popup | message |
| 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 |
| teacher1 | Teacher | 1 | teacher1@example.com |
Expand Down
8 changes: 4 additions & 4 deletions message/tests/api_test.php
Expand Up @@ -2967,15 +2967,15 @@ public function test_get_all_message_preferences() {
$this->setUser($user);

// Set a couple of preferences to test.
set_user_preference('message_provider_mod_assign_assign_notification_loggedin', 'popup', $user);
set_user_preference('message_provider_mod_assign_assign_notification_loggedoff', 'email', $user);
set_user_preference('message_provider_mod_assign_assign_notification_enabled', 'popup', $user);
set_user_preference('message_provider_mod_feedback_submission_enabled', 'email', $user);

$processors = get_message_processors();
$providers = message_get_providers_for_user($user->id);
$prefs = \core_message\api::get_all_message_preferences($processors, $providers, $user);

$this->assertEquals(1, $prefs->mod_assign_assign_notification_loggedin['popup']);
$this->assertEquals(1, $prefs->mod_assign_assign_notification_loggedoff['email']);
$this->assertEquals(1, $prefs->mod_assign_assign_notification_enabled['popup']);
$this->assertEquals(1, $prefs->mod_feedback_submission_enabled['email']);
}

/**
Expand Down

0 comments on commit b4c7598

Please sign in to comment.