Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311] [Versions 311 and 403] [Versions 39 and 311]

(no description)

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

Defines 1 class

api_test:: (68 methods):
  test_check_can_manage_data_registry_admin()
  test_check_can_manage_data_registry_without_cap_default()
  test_check_can_manage_data_registry_without_cap_system()
  test_check_can_manage_data_registry_without_cap_own_user()
  test_update_request_status()
  test_get_site_dpos_no_dpos()
  test_get_site_dpos()
  test_get_assigned_privacy_officer_roles()
  test_approve_data_request()
  test_approve_data_request_non_dpo_user()
  test_reject_data_deletion_request_primary_admin()
  test_can_contact_dpo()
  test_can_manage_data_requests()
  test_can_create_data_request_for_user_no()
  test_can_create_data_request_for_user_some()
  test_can_create_data_request_for_user_own_child()
  test_require_can_create_data_request_for_user_no()
  test_require_can_create_data_request_for_user_some()
  test_require_can_create_data_request_for_user_own_child()
  test_can_download_data_request_for_user()
  data_request_creation_provider()
  test_create_data_request()
  test_create_data_request_by_parent()
  test_deny_data_request()
  get_data_requests_provider()
  test_get_data_requests()
  status_provider()
  test_has_ongoing_request()
  test_is_active()
  test_is_site_dpo()
  notify_dpo_provider()
  test_notify_dpo()
  test_purpose_crud()
  test_category_crud()
  test_context_instances()
  test_contextlevel()
  test_effective_contextlevel_defaults()
  test_get_effective_contextlevel_unset()
  test_get_effective_context_unset()
  test_set_contextlevel_invalid_contextlevels()
  test_effective_contextlevel()
  test_effective_contextlevel_invalid_contextlevels()
  invalid_effective_contextlevel_provider()
  test_effective_context_inheritance()
  test_effective_context_inheritance_explicitly_set()
  add_purposes_and_categories()
  test_get_approved_contextlist_collection_for_collection_delete_course_no_site_config()
  test_get_approved_contextlist_collection_for_collection_delete_course_expired_protected()
  test_get_approved_contextlist_collection_for_collection_delete_course_unexpired_protected()
  test_get_approved_contextlist_collection_for_collection_delete_course_unexpired_unprotected()
  set_context_defaults_provider()
  test_set_context_defaults()
  setup_basics()
  create_and_set_purpose_for_contextlevel()
  test_find_ongoing_request_types_for_users()
  create_request_with_type_and_status()
  test_can_create_data_download_request_for_self()
  test_can_create_data_deletion_request_for_self_no()
  test_can_create_data_deletion_request_for_self_primary_admin()
  test_can_create_data_deletion_request_for_self_secondary_admin()
  test_can_create_data_deletion_request_for_self_yes()
  test_can_create_data_deletion_request_for_other_no()
  test_can_create_data_deletion_request_for_other_yes()
  test_can_create_data_deletion_request_for_children()
  queue_data_request_task_provider()
  test_queue_data_request_task()
  automatic_request_approval_setting_provider()
  test_is_automatic_request_approval_on()


Class: api_test  - X-Ref

API tests.

test_check_can_manage_data_registry_admin()   X-Ref
Ensure that the check_can_manage_data_registry function fails cap testing when a user without capabilities is
tested with the default context.


test_check_can_manage_data_registry_without_cap_default()   X-Ref
Ensure that the check_can_manage_data_registry function fails cap testing when a user without capabilities is
tested with the default context.


test_check_can_manage_data_registry_without_cap_system()   X-Ref
Ensure that the check_can_manage_data_registry function fails cap testing when a user without capabilities is
tested with the default context.


test_check_can_manage_data_registry_without_cap_own_user()   X-Ref
Ensure that the check_can_manage_data_registry function fails cap testing when a user without capabilities is
tested with the default context.


test_update_request_status()   X-Ref
Test for api::update_request_status().


test_get_site_dpos_no_dpos()   X-Ref
Test for api::get_site_dpos() when there are no users with the DPO role.


test_get_site_dpos()   X-Ref
Test for api::get_site_dpos() when there are no users with the DPO role.


test_get_assigned_privacy_officer_roles()   X-Ref
Test for \tool_dataprivacy\api::get_assigned_privacy_officer_roles().


test_approve_data_request()   X-Ref
Test for api::approve_data_request().


test_approve_data_request_non_dpo_user()   X-Ref
Test for api::approve_data_request() when called by a user who doesn't have the DPO role.


test_reject_data_deletion_request_primary_admin()   X-Ref
Test that deletion requests for the primary admin are rejected


test_can_contact_dpo()   X-Ref
Test for api::can_contact_dpo()


test_can_manage_data_requests()   X-Ref
Test for api::can_manage_data_requests()


test_can_create_data_request_for_user_no()   X-Ref
Test that a user who has no capability to make any data requests for children cannot create data requests for any
other user.


test_can_create_data_request_for_user_some()   X-Ref
Test that a user who has the capability to make any data requests for one other user cannot create data requests
for any other user.


test_can_create_data_request_for_user_own_child()   X-Ref
Test that a user who has the capability to make any data requests for one other user cannot create data requests
for any other user.


test_require_can_create_data_request_for_user_no()   X-Ref
Test that a user who has no capability to make any data requests for children cannot create data requests for any
other user.


test_require_can_create_data_request_for_user_some()   X-Ref
Test that a user who has the capability to make any data requests for one other user cannot create data requests
for any other user.


test_require_can_create_data_request_for_user_own_child()   X-Ref
Test that a user who has the capability to make any data requests for one other user cannot create data requests
for any other user.


test_can_download_data_request_for_user()   X-Ref
Test for api::can_download_data_request_for_user()


data_request_creation_provider()   X-Ref
Data provider for data request creation tests.

return: array

test_create_data_request($asprivacyofficer, $type, $setting, $automaticapproval, $expecteddpoval,$expectedstatus, $expectedtaskcount)   X-Ref
Test for api::create_data_request()

param: bool $asprivacyofficer Whether the request is made as the Privacy Officer or the user itself.
param: string $type The data request type.
param: string $setting The automatic approval setting.
param: bool $automaticapproval Whether automatic data request approval is turned on or not.
param: int|string $expecteddpoval The expected value for the 'dpo' field. 'dpo' means we'd the expected value would be the
param: int $expectedstatus The expected status of the data request.
param: int $expectedtaskcount The number of expected queued data requests tasks.

test_create_data_request_by_parent()   X-Ref
Test for api::create_data_request() made by a parent.


test_deny_data_request()   X-Ref
Test for api::deny_data_request()


get_data_requests_provider()   X-Ref
Data provider for \tool_dataprivacy_api_testcase::test_get_data_requests().

return: array

test_get_data_requests($usertype, $fetchall, $statuses)   X-Ref
Test for api::get_data_requests()

param: string $usertype The type of the user logging in.
param: boolean $fetchall Whether to fetch all records.
param: int[] $statuses Status filters.

status_provider()   X-Ref
Data provider for test_has_ongoing_request.


test_has_ongoing_request($status, $expected)   X-Ref
Test for api::has_ongoing_request()

param: int $status The request status.
param: bool $expected The expected result.

test_is_active($status, $expected)   X-Ref
Test for api::is_active()

param: int $status The request status
param: bool $expected The expected result

test_is_site_dpo()   X-Ref
Test for api::is_site_dpo()


notify_dpo_provider()   X-Ref
Data provider function for test_notify_dpo

return: array

test_notify_dpo($byadmin, $type, $typestringid, $comments)   X-Ref
Test for api::notify_dpo()

param: bool $byadmin Whether the admin requests data on behalf of the user
param: int $type The request type
param: string $typestringid The request lang string identifier
param: string $comments The requestor's message to the DPO.

test_purpose_crud()   X-Ref
Test data purposes CRUD actions.

return: null

test_category_crud()   X-Ref
Test data categories CRUD actions.

return: null

test_context_instances()   X-Ref
Test context instances.

return: null

test_contextlevel()   X-Ref
Test contextlevel.

return: null

test_effective_contextlevel_defaults()   X-Ref
Test effective context levels purpose and category defaults.

return: null

test_get_effective_contextlevel_unset()   X-Ref
Ensure that when nothing is configured, all values return false.


test_get_effective_context_unset()   X-Ref
Ensure that when nothing is configured, all values return false.


test_set_contextlevel_invalid_contextlevels($contextlevel)   X-Ref
Ensure that fetching the effective value for context levels is only available to system, and user context levels.

param: int $contextlevel

test_effective_contextlevel()   X-Ref
Test effective contextlevel return.


test_effective_contextlevel_invalid_contextlevels($contextlevel)   X-Ref
Ensure that fetching the effective value for context levels is only available to system, and user context levels.

param: int $contextlevel

invalid_effective_contextlevel_provider()   X-Ref
Data provider for invalid contextlevel fetchers.


test_effective_context_inheritance()   X-Ref
Ensure that context inheritance works up the context tree.


test_effective_context_inheritance_explicitly_set()   X-Ref
Ensure that context inheritance works up the context tree when inherit values are explicitly set at the
contextlevel.

Although it should not be possible to set hard INHERIT values at this level, there may be legacy data which still
contains this.

add_purposes_and_categories()   X-Ref
Creates test purposes and categories.

return: null

test_get_approved_contextlist_collection_for_collection_delete_course_no_site_config()   X-Ref
Test that delete requests do not filter out protected purpose contexts if the the site is properly configured.


test_get_approved_contextlist_collection_for_collection_delete_course_expired_protected()   X-Ref
Test that delete requests do not filter out protected purpose contexts if they are already expired.


test_get_approved_contextlist_collection_for_collection_delete_course_unexpired_protected()   X-Ref
Test that delete requests does filter out protected purpose contexts which are not expired.


test_get_approved_contextlist_collection_for_collection_delete_course_unexpired_unprotected()   X-Ref
Test that delete requests do not filter out unexpired contexts if they are not protected.


set_context_defaults_provider()   X-Ref
Data provider for \tool_dataprivacy_api_testcase::test_set_context_defaults


test_set_context_defaults($contextlevel, $inheritcategory, $inheritpurpose, $foractivity, $override)   X-Ref
Test for \tool_dataprivacy\api::set_context_defaults()

param: int $contextlevel The context level
param: bool $inheritcategory Whether to set category value as INHERIT.
param: bool $inheritpurpose Whether to set purpose value as INHERIT.
param: bool $foractivity Whether to set defaults for an activity.
param: bool $override Whether to override instances.

setup_basics(string $system, string $user, string $course = null, string $activity = null)   X-Ref
Setup the basics with the specified retention period.

param: string  $system Retention policy for the system.
param: string  $user Retention policy for users.
param: string  $course Retention policy for courses.
param: string  $activity Retention policy for activities.

create_and_set_purpose_for_contextlevel(string $retention, int $contextlevel)   X-Ref
Create a retention period and set it for the specified context level.

param: string  $retention
param: int     $contextlevel

test_find_ongoing_request_types_for_users()   X-Ref
Ensure that the find_ongoing_request_types_for_users only returns requests which are active.


create_request_with_type_and_status(int $userid, int $type, int $status)   X-Ref
Create  a new data request for the user with the type and status specified.

param: int     $userid
param: int     $type
param: int     $status
return: \tool_dataprivacy\data_request

test_can_create_data_download_request_for_self()   X-Ref
Test whether user can create data download request for themselves


test_can_create_data_deletion_request_for_self_no()   X-Ref
Test user cannot create data deletion request for themselves if they don't have
"tool/dataprivacy:requestdelete" capability.


test_can_create_data_deletion_request_for_self_primary_admin()   X-Ref
Test primary admin cannot create data deletion request for themselves


test_can_create_data_deletion_request_for_self_secondary_admin()   X-Ref
Test secondary admin can create data deletion request for themselves


test_can_create_data_deletion_request_for_self_yes()   X-Ref
Test user can create data deletion request for themselves if they have
"tool/dataprivacy:requestdelete" capability.


test_can_create_data_deletion_request_for_other_no()   X-Ref
Test user cannot create data deletion request for another user if they
don't have "tool/dataprivacy:requestdeleteforotheruser" capability.


test_can_create_data_deletion_request_for_other_yes()   X-Ref
Test user can create data deletion request for another user if they
don't have "tool/dataprivacy:requestdeleteforotheruser" capability.


test_can_create_data_deletion_request_for_children()   X-Ref
Check parents can create data deletion request for their children (unless the child is the primary admin),
but not other users.


queue_data_request_task_provider()   X-Ref
Data provider function for testing \tool_dataprivacy\api::queue_data_request_task().

return: array

test_queue_data_request_task(bool $withuserid)   X-Ref
Test for \tool_dataprivacy\api::queue_data_request_task().

param: bool $withuserid

automatic_request_approval_setting_provider()   X-Ref
Data provider for test_is_automatic_request_approval_on().


test_is_automatic_request_approval_on($setting, $type, $value, $expected)   X-Ref
Test for \tool_dataprivacy\api::is_automatic_request_approval_on().

param: string $setting The automatic approval setting.
param: int $type The data request type.
param: bool $value The setting's value.
param: bool $expected The expected result.