Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

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

This file contains unit tests for (some of) lti/locallib.php

Author: Charles Severance csev@unmich.edu
Author: Marc Alier (marc.alier@upc.edu)
Author: Jordi Piguillem
Author: Nikolas Galanis
Author: Chris Scribner
Copyright: 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis
Copyright: 2009 Universitat Politecnica de Catalunya http://www.upc.edu
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 2162 lines (87 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

locallib_test:: (56 methods):
  test_split_parameters()
  test_split_custom_parameters()
  disabled_test_sign_parameters()
  disabled_test_parse_grade_replace_message()
  test_lti_ensure_url_is_https()
  test_lti_get_url_thumbprint()
  test_lti_buid_request_resource_link_id()
  test_lti_build_request_description()
  test_lti_prepare_type_for_save_forcessl()
  test_lti_load_type_from_cartridge()
  test_lti_load_tool_from_cartridge()
  test_lti_build_content_item_selection_request()
  test_lti_build_content_item_selection_request_invalid_tooltype()
  test_lti_build_content_item_selection_request_invalid_mediatypes()
  test_lti_build_content_item_selection_request_invalid_presentationtargets()
  lti_get_best_tool_by_url_provider()
  test_lti_get_best_tool_by_url()
  test_lti_get_jwt_message_type_mapping()
  test_lti_get_jwt_claim_mapping()
  test_lti_build_standard_message_institution_name_set()
  test_lti_build_standard_message_institution_name_not_set()
  test_lti_verify_jwt_signature()
  test_lti_verify_jwt_signature_jwk()
  test_lti_verify_jwt_signature_with_lti2()
  test_lti_verify_jwt_signature_no_consumer_key()
  test_lti_verify_jwt_signature_no_public_key()
  test_lti_convert_content_items()
  test_lti_tool_configuration_from_content_item_single_gradable()
  test_lti_tool_configuration_from_content_item_single_gradable_subreview_default_emptyurl()
  test_lti_tool_configuration_from_content_item_single_gradable_subreview_default()
  test_lti_tool_configuration_from_content_item_multiple()
  test_lti_tool_configuration_from_content_item_single()
  test_lti_sign_jwt()
  test_lti_convert_from_jwt()
  test_lti_get_permitted_service_scopes()
  test_get_tool_type_config()
  test_lti_new_access_token()
  test_lti_build_login_request()
  test_lti_get_launch_data_with_for_user()
  test_lti_get_launch_data_default_organizationid_unset_usehost()
  test_lti_get_launch_data_default_organizationid_set_usehost()
  test_lti_get_launch_data_default_organizationid_set_usesiteid()
  test_lti_get_launch_data_default_organizationid_orgid_override()
  test_get_course_history()
  test_lti_get_ims_role()
  lti_get_ims_role_provider()
  test_lti_get_lti_types_and_proxies_with_no_limit()
  test_lti_get_lti_types_and_proxies_with_limit()
  test_lti_get_lti_types_and_proxies_with_limit_and_orphaned_proxies()
  test_lti_get_lti_types_and_proxies_count_with_no_filters()
  test_lti_get_lti_types_and_proxies_count_with_only_orphaned_proxies()
  test_lti_get_lti_types_and_proxies_count_type_with_proxyid()
  test_empty_reponse_lti_load_cartridge()
  create_type()
  create_instance()
  generate_tool_types_and_proxies()


Class: locallib_test  - X-Ref

Local library tests

test_split_parameters()   X-Ref


test_split_custom_parameters()   X-Ref
No description

disabled_test_sign_parameters()   X-Ref
This test has been disabled because the test-tool is
being moved and probably it won't work anymore for this.
We should be testing here local stuff only and leave
outside-checks to the conformance tests. MDL-30347


disabled_test_parse_grade_replace_message()   X-Ref
This test has been disabled because, since its creation,
the sourceId generation has changed and surely this is outdated.
Some day these should be replaced by proper tests, but until then
conformance tests say this is working. MDL-30347


test_lti_ensure_url_is_https()   X-Ref
No description

test_lti_get_url_thumbprint()   X-Ref
Test lti_get_url_thumbprint against various URLs


test_lti_buid_request_resource_link_id()   X-Ref
No description

test_lti_build_request_description()   X-Ref
Test lti_build_request's resource_link_description and ensure
that the newlines in the description are correct.


test_lti_prepare_type_for_save_forcessl()   X-Ref
Tests lti_prepare_type_for_save's handling of the "Force SSL" configuration.


test_lti_load_type_from_cartridge()   X-Ref
Tests lti_load_type_from_cartridge and lti_load_type_if_cartridge


test_lti_load_tool_from_cartridge()   X-Ref
Tests lti_load_tool_from_cartridge and lti_load_tool_if_cartridge


test_lti_build_content_item_selection_request()   X-Ref
Tests for lti_build_content_item_selection_request().


test_lti_build_content_item_selection_request_invalid_tooltype()   X-Ref
Test for lti_build_content_item_selection_request() with nonexistent tool type ID parameter.


test_lti_build_content_item_selection_request_invalid_mediatypes()   X-Ref
Test for lti_build_content_item_selection_request() with invalid media types parameter.


test_lti_build_content_item_selection_request_invalid_presentationtargets()   X-Ref
Test for lti_build_content_item_selection_request() with invalid presentation targets parameter.


lti_get_best_tool_by_url_provider()   X-Ref
Provider for test_lti_get_best_tool_by_url.

return: array of [urlToTest, expectedTool, allTools]

test_lti_get_best_tool_by_url($url, $expected, $tools)   X-Ref
Test lti_get_best_tool_by_url.

param: string $url The URL to test.
param: object $expected The expected tool matching the URL.
param: array $tools The pool of tools to match the URL with.

test_lti_get_jwt_message_type_mapping()   X-Ref
Test lti_get_jwt_message_type_mapping().


test_lti_get_jwt_claim_mapping()   X-Ref
Test lti_get_jwt_claim_mapping()


test_lti_build_standard_message_institution_name_set()   X-Ref
Test lti_build_standard_message().


test_lti_build_standard_message_institution_name_not_set()   X-Ref
Test lti_build_standard_message().


test_lti_verify_jwt_signature()   X-Ref
Test lti_verify_jwt_signature().


test_lti_verify_jwt_signature_jwk()   X-Ref
Test lti_verify_jwt_signature_jwk().


test_lti_verify_jwt_signature_with_lti2()   X-Ref
Test lti_verify_jwt_signature().


test_lti_verify_jwt_signature_no_consumer_key()   X-Ref
Test lti_verify_jwt_signature().


test_lti_verify_jwt_signature_no_public_key()   X-Ref
Test lti_verify_jwt_signature().


test_lti_convert_content_items()   X-Ref
Test lti_convert_content_items().


test_lti_tool_configuration_from_content_item_single_gradable()   X-Ref
Test adding a single gradable item through content item.


test_lti_tool_configuration_from_content_item_single_gradable_subreview_default_emptyurl()   X-Ref


test_lti_tool_configuration_from_content_item_single_gradable_subreview_default()   X-Ref


test_lti_tool_configuration_from_content_item_multiple()   X-Ref
Test adding multiple gradable items through content item.


test_lti_tool_configuration_from_content_item_single()   X-Ref
Test adding a single non gradable item through content item.


test_lti_sign_jwt()   X-Ref
Test lti_sign_jwt().


test_lti_convert_from_jwt()   X-Ref
Test lti_convert_from_jwt()


test_lti_get_permitted_service_scopes()   X-Ref
Test lti_get_permitted_service_scopes().


test_get_tool_type_config()   X-Ref
Test get_tool_type_config().


test_lti_new_access_token()   X-Ref
Test lti_new_access_token().


test_lti_build_login_request()   X-Ref
Test lti_build_login_request().


test_lti_get_launch_data_with_for_user()   X-Ref


test_lti_get_launch_data_default_organizationid_unset_usehost()   X-Ref
Test default orgid is host if not specified in config (tool installed in earlier version of Moodle).


test_lti_get_launch_data_default_organizationid_set_usehost()   X-Ref
Test default org id is set to host when config is usehost.


test_lti_get_launch_data_default_organizationid_set_usesiteid()   X-Ref
Test default org id is set to site id when config is usesiteid.


test_lti_get_launch_data_default_organizationid_orgid_override()   X-Ref
Test orgid can be overridden in which case default is ignored.


test_get_course_history()   X-Ref
No description

test_lti_get_ims_role(bool $islti2, string $rolename, ?string $switchedto, string $expected)   X-Ref
Test the lti_get_ims_role helper function.

param: bool $islti2 whether the method is called with LTI 2.0 role names or not.
param: string $rolename the name of the role (student, teacher, admin)
param: null|string $switchedto the role to switch to, or false if not using the 'switch to' functionality.
param: string $expected the expected role name.

lti_get_ims_role_provider()   X-Ref
Data provider for testing lti_get_ims_role.

return: array[] the test case data.

test_lti_get_lti_types_and_proxies_with_no_limit()   X-Ref
Test lti_get_lti_types_and_proxies with no limit or offset.


test_lti_get_lti_types_and_proxies_with_limit()   X-Ref
Test lti_get_lti_types_and_proxies with limits.


test_lti_get_lti_types_and_proxies_with_limit_and_orphaned_proxies()   X-Ref
Test lti_get_lti_types_and_proxies with limits and only fetching orphaned proxies.


test_lti_get_lti_types_and_proxies_count_with_no_filters()   X-Ref
Test lti_get_lti_types_and_proxies_count.


test_lti_get_lti_types_and_proxies_count_with_only_orphaned_proxies()   X-Ref
Test lti_get_lti_types_and_proxies_count only counting orphaned proxies.


test_lti_get_lti_types_and_proxies_count_type_with_proxyid()   X-Ref
Test lti_get_lti_types_and_proxies_count only matching tool type with toolproxyid.


test_empty_reponse_lti_load_cartridge()   X-Ref
Verify that empty curl responses lead to the proper moodle_exception, not to XML ValueError.


create_type(object $config)   X-Ref
Create an LTI Tool.

param: object $config tool config.
return: object tool.

create_instance(object $type, object $course)   X-Ref
Create an LTI Instance for the tool in a given course.

param: object $type tool for which an instance should be added.
param: object $course course where the instance should be added.
return: object instance.

generate_tool_types_and_proxies(int $toolandproxycount = 0, int $orphanproxycount = 0)   X-Ref
Generate a number of LTI tool types and proxies.

param: int $toolandproxycount How many tool types and associated proxies to create. E.g. Value of 10 will create 10 types
param: int $orphanproxycount How many orphaned proxies to create.
return: array[]