Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402] [Versions 401 and 402]

(no description)

File Size: 5889 lines (259 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

externallib_test:: (142 methods):
  setUp()
  send_message()
  test_send_instant_messages()
  test_send_instant_messages_long_text()
  test_send_instant_messages_blocked_user()
  test_send_instant_messages_block_non_contacts()
  test_send_instant_messages_block_non_contacts_but_am_contact()
  test_send_instant_messages_no_capability()
  test_send_instant_messages_messaging_disabled()
  test_delete_contacts()
  test_get_contact_requests()
  test_get_contact_requests_blocked_sender()
  test_get_contact_requests_no_requests()
  test_get_contact_requests_with_limits()
  test_get_contact_requests_messaging_disabled()
  test_get_contact_requests_no_permission()
  test_get_received_contact_requests_count()
  test_get_received_contact_requests_count_blocked_sender()
  test_get_received_contact_requests_count_no_permission()
  test_get_received_contact_requests_count_messaging_disabled()
  test_create_contact_request()
  test_create_contact_request_not_allowed()
  test_create_contact_request_messaging_disabled()
  test_create_contact_request_no_permission()
  test_confirm_contact_request()
  test_confirm_contact_request_messaging_disabled()
  test_confirm_contact_request_no_permission()
  test_decline_contact_request()
  test_decline_contact_request_messaging_disabled()
  test_decline_contact_request_no_permission()
  test_mute_conversations()
  test_mute_conversations_messaging_disabled()
  test_mute_conversations_no_permission()
  test_unmute_conversations()
  test_unmute_conversation_messaging_disabled()
  test_unmute_conversation_no_permission()
  test_block_user()
  test_block_user_when_ineffective()
  test_block_user_messaging_disabled()
  test_block_user_no_permission()
  test_unblock_user()
  test_unblock_user_messaging_disabled()
  test_unblock_user_no_permission()
  test_search_contacts()
  test_get_messages()
  test_get_messages_useridto_all()
  test_get_messages_useridfrom_all()
  test_get_blocked_users()
  test_mark_message_read()
  test_mark_notification_read()
  test_delete_message()
  test_mark_all_notifications_as_read_invalid_user_exception()
  test_mark_all_notifications_as_read_access_denied_exception()
  test_mark_all_notifications_as_read_missing_from_user_exception()
  test_mark_all_notifications_as_read()
  test_mark_all_notifications_as_read_time_created_to()
  test_get_user_notification_preferences()
  test_get_user_notification_preferences_permissions()
  test_message_search_users_messagingallusers_disabled()
  test_message_search_users_messagingallusers_enabled()
  test_message_search_users_self_conversations()
  test_message_search_users_with_empty_result()
  test_message_search_users_limit_offset()
  test_message_search_users_with_cap()
  test_message_search_users_without_cap()
  test_message_search_users_messaging_disabled()
  test_messagearea_search_messages()
  test_messagearea_search_messages_as_other_user()
  test_messagearea_search_messages_as_other_user_without_cap()
  test_messagearea_search_messages_messaging_disabled()
  test_get_user_contacts()
  test_get_user_contacts_as_other_user()
  test_get_user_contacts_as_other_user_without_cap()
  test_get_user_contacts_messaging_disabled()
  test_get_user_contacts_no_results()
  test_get_conversation_messages()
  test_get_conversation_messages_timefrom()
  test_get_conversation_messages_as_other_user()
  test_get_conversation_messages_as_other_user_without_cap()
  test_get_conversation_messages_as_user_not_in_conversation()
  test_get_conversation_messages_messaging_disabled()
  test_mark_all_conversation_messages_as_read_invalid_user_exception()
  test_mark_all_conversation_messages_as_read_access_denied_exception()
  test_mark_all_conversation_messages_as_read_wrong_user()
  test_mark_all_conversation_messages_as_admin()
  test_mark_all_conversation_messages_as_read()
  test_get_unread_conversations_count()
  test_get_unread_conversations_count_as_other_user()
  test_get_unread_conversations_count_as_other_user_without_cap()
  test_delete_conversations_by_id()
  test_delete_conversations_by_id_as_other_user()
  test_delete_conversations_by_id_as_other_user_without_cap()
  test_delete_conversations_by_id_messaging_disabled()
  test_get_message_processor()
  test_get_user_message_preferences()
  test_get_user_message_preferences_permissions()
  sort_contacts()
  sort_contacts_id()
  test_set_favourite_conversations_basic()
  test_set_favourite_conversations_another_users_conversation()
  test_set_favourite_conversations_non_member()
  test_set_favourite_conversations_non_existent_conversation()
  test_unset_favourite_conversations_basic()
  test_unset_favourite_conversations_another_users_conversation()
  test_unset_favourite_conversations_non_existent_conversation()
  create_conversation_test_data()
  test_get_conversations_no_restrictions()
  test_get_conversations_message_format()
  test_get_conversations_limit_offset()
  test_get_conversations_type_filter()
  test_get_conversations_self_conversations()
  test_get_conversations_deleted_user()
  test_get_conversations_deleted_user_from_database()
  test_get_conversations_favourite_conversations()
  test_get_conversations_group_linked()
  test_get_conversations_group_with_mathjax()
  test_get_conversations_user_in_group_and_individual_chat()
  test_get_conversations_some_muted()
  test_get_conversation_members_messaging_disabled()
  test_get_conversation_members_wrong_user()
  test_get_conversation_members()
  test_get_conversation_members_with_contact_requests()
  test_get_conversation_members_not_a_member()
  test_send_messages_to_conversation_individual()
  test_send_messages_to_conversation_group()
  test_send_messages_to_conversation_non_existent_conversation()
  test_send_messages_to_conversation_non_member()
  test_send_messages_to_conversation_long_text()
  test_get_conversation_no_conversation()
  test_get_conversation_favourited()
  test_get_conversation_favourited_group_linked()
  test_get_conversation_no_messages()
  test_get_conversation_with_messages()
  get_conversation_counts_test_cases()
  test_get_conversation_counts()
  test_get_unread_conversation_counts()
  test_delete_message_for_all_users()
  test_delete_message_for_all_users_messaging_disabled()
  test_delete_message_for_all_users_no_permission()
  test_delete_message_for_all_users_private_conversation()
  test_get_conversation_messages_timefrom_higher_than_last_timecreated()
  create_delete_message_test_data()


Class: externallib_test  - X-Ref

External message functions unit tests

setUp()   X-Ref
Tests set up


send_message($userfrom, $userto, $message = 'Hello world!', $notification = 0, $time = 0)   X-Ref
Send a fake message.

{@link message_send()} does not support transaction, this function will simulate a message
sent from a user to another. We should stop using it once {@link message_send()} will support
transactions. This is not clean at all, this is just used to add rows to the table.

param: \stdClass $userfrom user object of the one sending the message.
param: \stdClass $userto user object of the one receiving the message.
param: string $message message to send.
param: int $notification is the message a notification.
param: int $time the time the message was sent

test_send_instant_messages()   X-Ref
Test send_instant_messages.


test_send_instant_messages_long_text()   X-Ref
Test send_instant_messages with a message text longer than permitted.


test_send_instant_messages_blocked_user()   X-Ref
Test send_instant_messages to a user who has blocked you.


test_send_instant_messages_block_non_contacts()   X-Ref
Test send_instant_messages when sending a message to a non-contact who has blocked non-contacts.


test_send_instant_messages_block_non_contacts_but_am_contact()   X-Ref
Test send_instant_messages when sending a message to a contact who has blocked non-contacts.


test_send_instant_messages_no_capability()   X-Ref
Test send_instant_messages with no capabilities


test_send_instant_messages_messaging_disabled()   X-Ref
Test send_instant_messages when messaging is disabled.


test_delete_contacts()   X-Ref
Test delete_contacts.


test_get_contact_requests()   X-Ref
Test getting contact requests.


test_get_contact_requests_blocked_sender()   X-Ref
Test the get_contact_requests() function when the user has blocked the sender of the request.


test_get_contact_requests_no_requests()   X-Ref
Test getting contact requests when there are none.


test_get_contact_requests_with_limits()   X-Ref
Test getting contact requests with limits.


test_get_contact_requests_messaging_disabled()   X-Ref
Test getting contact requests with messaging disabled.


test_get_contact_requests_no_permission()   X-Ref
Test getting contact requests with no permission.


test_get_received_contact_requests_count()   X-Ref
Test getting the number of received contact requests.


test_get_received_contact_requests_count_blocked_sender()   X-Ref
Test the get_received_contact_requests_count() function when the user has blocked the sender of the request.


test_get_received_contact_requests_count_no_permission()   X-Ref
Test getting the number of received contact requests with no permissions.


test_get_received_contact_requests_count_messaging_disabled()   X-Ref
Test getting the number of received contact requests with messaging disabled.


test_create_contact_request()   X-Ref
Test creating a contact request.


test_create_contact_request_not_allowed()   X-Ref
Test creating a contact request when not allowed.


test_create_contact_request_messaging_disabled()   X-Ref
Test creating a contact request with messaging disabled.


test_create_contact_request_no_permission()   X-Ref
Test creating a contact request with no permission.


test_confirm_contact_request()   X-Ref
Test confirming a contact request.


test_confirm_contact_request_messaging_disabled()   X-Ref
Test confirming a contact request with messaging disabled.


test_confirm_contact_request_no_permission()   X-Ref
Test confirming a contact request with no permission.


test_decline_contact_request()   X-Ref
Test declining a contact request.


test_decline_contact_request_messaging_disabled()   X-Ref
Test declining a contact request with messaging disabled.


test_decline_contact_request_no_permission()   X-Ref
Test declining a contact request with no permission.


test_mute_conversations()   X-Ref
Test muting conversations.


test_mute_conversations_messaging_disabled()   X-Ref
Test muting a conversation with messaging disabled.


test_mute_conversations_no_permission()   X-Ref
Test muting a conversation with no permission.


test_unmute_conversations()   X-Ref
Test unmuting conversations.


test_unmute_conversation_messaging_disabled()   X-Ref
Test unmuting a conversation with messaging disabled.


test_unmute_conversation_no_permission()   X-Ref
Test unmuting a conversation with no permission.


test_block_user()   X-Ref
Test blocking a user.


test_block_user_when_ineffective()   X-Ref
Test blocking a user.


test_block_user_messaging_disabled()   X-Ref
Test blocking a user with messaging disabled.


test_block_user_no_permission()   X-Ref
Test blocking a user with no permission.


test_unblock_user()   X-Ref
Test unblocking a user.


test_unblock_user_messaging_disabled()   X-Ref
Test unblocking a user with messaging disabled.


test_unblock_user_no_permission()   X-Ref
Test unblocking a user with no permission.


test_search_contacts()   X-Ref
Test search_contacts.


test_get_messages()   X-Ref
Test get_messages.


test_get_messages_useridto_all()   X-Ref
Test get_messages where we want all messages from a user, sent to any user.


test_get_messages_useridfrom_all()   X-Ref
Test get_messages where we want all messages to a user, sent by any user.


test_get_blocked_users()   X-Ref
Test get_blocked_users.


test_mark_message_read()   X-Ref
Test mark_message_read.


test_mark_notification_read()   X-Ref
Test mark_notification_read.


test_delete_message()   X-Ref
Test delete_message.


test_mark_all_notifications_as_read_invalid_user_exception()   X-Ref
No description

test_mark_all_notifications_as_read_access_denied_exception()   X-Ref
No description

test_mark_all_notifications_as_read_missing_from_user_exception()   X-Ref
No description

test_mark_all_notifications_as_read()   X-Ref
No description

test_mark_all_notifications_as_read_time_created_to()   X-Ref
No description

test_get_user_notification_preferences()   X-Ref
Test get_user_notification_preferences


test_get_user_notification_preferences_permissions()   X-Ref
Test get_user_notification_preferences permissions


test_message_search_users_messagingallusers_disabled()   X-Ref
Tests searching for users when site-wide messaging is disabled.

This test verifies that any contacts are returned, as well as any non-contacts whose profile we can view.
If checks this by placing some users in the same course, where default caps would permit a user to view another user's
profile.

test_message_search_users_messagingallusers_enabled()   X-Ref
Tests searching for users when site-wide messaging is enabled.

This test verifies that any contacts are returned, as well as any non-contacts, regardless of whether the searching user
can view their respective profile.

test_message_search_users_self_conversations()   X-Ref
Verify searching for users find themselves when they have self-conversations.


test_message_search_users_with_empty_result()   X-Ref
Verify searching for users works even if no matching users from either contacts, or non-contacts can be found.


test_message_search_users_limit_offset()   X-Ref
Test verifying that limits and offsets work for both the contacts and non-contacts return data.


test_message_search_users_with_cap()   X-Ref
Tests searching users as another user having the 'moodle/user:viewdetails' capability.


test_message_search_users_without_cap()   X-Ref
Tests searching users as another user without the 'moodle/user:viewdetails' capability.


test_message_search_users_messaging_disabled()   X-Ref
Tests searching users with messaging disabled.


test_messagearea_search_messages()   X-Ref
Tests searching messages.


test_messagearea_search_messages_as_other_user()   X-Ref
Tests searching messages as another user.


test_messagearea_search_messages_as_other_user_without_cap()   X-Ref
Tests searching messages as another user without the proper capabilities.


test_messagearea_search_messages_messaging_disabled()   X-Ref
Tests searching messages with messaging disabled


test_get_user_contacts()   X-Ref
Tests retrieving contacts.


test_get_user_contacts_as_other_user()   X-Ref
Tests retrieving contacts as another user.


test_get_user_contacts_as_other_user_without_cap()   X-Ref
Tests retrieving contacts as another user without the proper capabilities.


test_get_user_contacts_messaging_disabled()   X-Ref
Tests retrieving contacts with messaging disabled.


test_get_user_contacts_no_results()   X-Ref
Test getting contacts when there are no results.


test_get_conversation_messages()   X-Ref
Tests get_conversation_messages for retrieving messages.


test_get_conversation_messages_timefrom()   X-Ref
Tests get_conversation_messages for retrieving messages using timefrom parameter.


test_get_conversation_messages_as_other_user()   X-Ref
Tests get_conversation_messages for retrieving messages as another user.


test_get_conversation_messages_as_other_user_without_cap()   X-Ref
Tests get_conversation_messages for retrieving messages as another user without the proper capabilities.


test_get_conversation_messages_as_user_not_in_conversation()   X-Ref
Tests get_conversation_messages for retrieving messages as another user not in the conversation.


test_get_conversation_messages_messaging_disabled()   X-Ref
Tests get_conversation_messages for retrieving messages with messaging disabled.


test_mark_all_conversation_messages_as_read_invalid_user_exception()   X-Ref
Test marking all conversation messages as read with an invalid user.


test_mark_all_conversation_messages_as_read_access_denied_exception()   X-Ref
Test marking all conversation messages as read without proper access.


test_mark_all_conversation_messages_as_read_wrong_user()   X-Ref
Test marking all conversation messages as read for another user.


test_mark_all_conversation_messages_as_admin()   X-Ref
Test marking all conversation messages as admin.


test_mark_all_conversation_messages_as_read()   X-Ref
Test marking all conversation messages.


test_get_unread_conversations_count()   X-Ref
Test getting unread conversation count.


test_get_unread_conversations_count_as_other_user()   X-Ref
Test getting unread conversation count as other user.


test_get_unread_conversations_count_as_other_user_without_cap()   X-Ref
Test getting unread conversation count as other user without proper capability.


test_delete_conversations_by_id()   X-Ref
Test deleting conversations.


test_delete_conversations_by_id_as_other_user()   X-Ref
Test deleting conversations as other user.


test_delete_conversations_by_id_as_other_user_without_cap()   X-Ref
Test deleting conversations as other user without proper capability.


test_delete_conversations_by_id_messaging_disabled()   X-Ref
Test deleting conversations with messaging disabled.


test_get_message_processor()   X-Ref
Test get message processor.


test_get_user_message_preferences()   X-Ref
Test get_user_notification_preferences


test_get_user_message_preferences_permissions()   X-Ref
Test get_user_message_preferences permissions


sort_contacts($a, $b)   X-Ref
Comparison function for sorting contacts.

param: array $a
param: array $b
return: bool

sort_contacts_id($a, $b)   X-Ref
Comparison function for sorting contacts.

param: array $a
param: array $b
return: bool

test_set_favourite_conversations_basic()   X-Ref
Test verifying that conversations can be marked as favourite conversations.


test_set_favourite_conversations_another_users_conversation()   X-Ref
Test confirming that a user can't favourite a conversation on behalf of another user.


test_set_favourite_conversations_non_member()   X-Ref
Test confirming that a user can't mark a conversation as their own favourite if it's a conversation they're not a member of.


test_set_favourite_conversations_non_existent_conversation()   X-Ref
Test confirming that a user can't favourite a non-existent conversation.


test_unset_favourite_conversations_basic()   X-Ref
Test confirming that a user can unset a favourite conversation, or list of favourite conversations.


test_unset_favourite_conversations_another_users_conversation()   X-Ref
Test confirming that a user can't unfavourite a conversation for another user.


test_unset_favourite_conversations_non_existent_conversation()   X-Ref
Test confirming that a user can't unfavourite a non-existent conversation.


create_conversation_test_data()   X-Ref
Helper to seed the database with initial state.


test_get_conversations_no_restrictions()   X-Ref
Test confirming the basic use of get_conversations, with no limits, nor type or favourite restrictions.


test_get_conversations_message_format()   X-Ref
Test verifying that html format messages are supported, and that message_format_message_text() is being called appropriately.


test_get_conversations_limit_offset()   X-Ref
Tests retrieving conversations with a limit and offset to ensure pagination works correctly.


test_get_conversations_type_filter()   X-Ref
Test verifying the type filtering behaviour of the get_conversations external method.


test_get_conversations_self_conversations()   X-Ref
Tests retrieving conversations when a 'self' conversation exists.


test_get_conversations_deleted_user()   X-Ref
Tests retrieving conversations when a conversation contains a deleted user.


test_get_conversations_deleted_user_from_database()   X-Ref
Tests retrieving conversations when a conversation contains a deleted from the database user.


test_get_conversations_favourite_conversations()   X-Ref
Test verifying the behaviour of get_conversations() when fetching favourite conversations.


test_get_conversations_group_linked()   X-Ref
Test verifying that group linked conversations are returned and contain a subname matching the course name.


test_get_conversations_group_with_mathjax()   X-Ref
Test that group conversations containing MathJax don't break the WebService.


test_get_conversations_user_in_group_and_individual_chat()   X-Ref
Test verifying get_conversations when there are users in a group and/or individual conversation. The reason this
test is performed is because we do not need as much data for group conversations (saving DB calls), so we want
to confirm this happens.


test_get_conversations_some_muted()   X-Ref
Test verifying get_conversations identifies if a conversation is muted or not.


test_get_conversation_members_messaging_disabled()   X-Ref
Test returning members in a conversation with no contact requests.


test_get_conversation_members_wrong_user()   X-Ref
Test returning members in a conversation with no contact requests.


test_get_conversation_members()   X-Ref
Test returning members in a conversation with no contact requests.


test_get_conversation_members_with_contact_requests()   X-Ref
Test returning members in a conversation with contact requests.


test_get_conversation_members_not_a_member()   X-Ref
Test returning members in a conversation when you are not a member.


test_send_messages_to_conversation_individual()   X-Ref
Test verifying multiple messages can be sent to an individual conversation.


test_send_messages_to_conversation_group()   X-Ref
Test verifying multiple messages can be sent to an group conversation.


test_send_messages_to_conversation_non_existent_conversation()   X-Ref
Test verifying multiple messages can not be sent to a non existent conversation.


test_send_messages_to_conversation_non_member()   X-Ref
Test verifying multiple messages can not be sent to a conversation by a non-member.


test_send_messages_to_conversation_long_text()   X-Ref
Test verifying a to long message can not be sent to a conversation.


test_get_conversation_no_conversation()   X-Ref
Test getting a conversation that doesn't exist.


test_get_conversation_favourited()   X-Ref
Test verifying that the correct favourite information is returned for a non-linked converastion at user context.


test_get_conversation_favourited_group_linked()   X-Ref
Test verifying that the correct favourite information is returned for a group-linked conversation at course context.


test_get_conversation_no_messages()   X-Ref
Test getting a conversation with no messages.


test_get_conversation_with_messages()   X-Ref
Test getting a conversation with messages.


get_conversation_counts_test_cases()   X-Ref
Data provider for test_get_conversation_counts().


test_get_conversation_counts($conversationconfigs,$deletemessagesuser,$deletemessages,$arguments,$expectedcounts,$expectedunreadcounts,$deletedusers)   X-Ref
Test the get_conversation_counts() function.

param: array $conversationconfigs Conversations to create
param: int $deletemessagesuser The user who is deleting the messages
param: array $deletemessages The list of messages to delete (by index)
param: array $arguments Arguments for the count conversations function
param: array $expectedcounts the expected conversation counts
param: array $expectedunreadcounts the expected unread conversation counts
param: array $deletedusers the array of users to soft delete.

test_get_unread_conversation_counts($conversationconfigs,$deletemessagesuser,$deletemessages,$arguments,$expectedcounts,$expectedunreadcounts,$deletedusers)   X-Ref
Test the get_unread_conversation_counts() function.

param: array $conversationconfigs Conversations to create
param: int $deletemessagesuser The user who is deleting the messages
param: array $deletemessages The list of messages to delete (by index)
param: array $arguments Arguments for the count conversations function
param: array $expectedcounts the expected conversation counts
param: array $expectedunreadcounts the expected unread conversation counts
param: array $deletedusers the list of users to soft-delete.

test_delete_message_for_all_users()   X-Ref
Test delete_message for all users.


test_delete_message_for_all_users_messaging_disabled()   X-Ref
Test delete_message for all users with messaging disabled.


test_delete_message_for_all_users_no_permission()   X-Ref
Test delete_message for all users with no permission.


test_delete_message_for_all_users_private_conversation()   X-Ref
Test delete_message for all users in a private conversation.


test_get_conversation_messages_timefrom_higher_than_last_timecreated()   X-Ref
Test retrieving conversation messages by providing a timefrom higher than last message timecreated. It should return no
messages but keep the return structure to not break when called from the ws.


create_delete_message_test_data()   X-Ref
Helper to seed the database with initial state with data.