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 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]

Full functional accesslib test.

Copyright: 2011 Petr Skoda {@link http://skodak.org}
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 4630 lines (225 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 2 classes

core_accesslib_testcase:: (84 methods):
  test_context_comparisons()
  test_accesslib_clear_all_caches()
  test_capabilities_mutation()
  test_get_role_access()
  test_get_guest_role()
  test_is_siteadmin()
  test_is_enrolled()
  test_isloggedin()
  test_isguestuser()
  test_is_safe_capability()
  test_get_context_info_array()
  test_has_coursecontact_role()
  test_create_role()
  test_assign_capability()
  test_unassign_capability()
  test_role_assign()
  test_role_unassign()
  test_role_unassign_all()
  test_get_roles_with_capability()
  test_delete_role()
  test_get_all_roles()
  test_get_role_archetypes()
  test_get_archetype_roles()
  test_role_get_name()
  test_role_fix_names()
  test_get_default_role_archetype_allows()
  test_core_role_set_assign_allowed()
  test_core_role_set_override_allowed()
  test_core_role_set_switch_allowed()
  test_core_role_set_view_allowed()
  test_get_assignable_roles()
  test_get_assignable_roles_distinct_usercount()
  test_get_switchable_roles()
  test_get_overridable_roles()
  test_get_viewable_roles_course()
  test_get_viewable_roles_system()
  test_get_default_contextlevels()
  test_set_role_contextlevels()
  test_get_roles_for_contextlevels()
  test_get_default_enrol_roles()
  test_get_role_users()
  test_get_roles_used_in_context()
  test_get_user_roles_in_course()
  test_get_user_roles()
  test_has_capability_and_friends()
  test_fake_capability()
  test_fake_capability_assign()
  test_fake_capability_unassign()
  test_role_definition_caching()
  test_get_user_capability_course()
  assert_course_ids()
  test_guess_if_creator_will_have_course_capability()
  test_require_capability()
  test_get_enrolled_sql_different_course()
  test_get_enrolled_sql_role_only()
  test_get_enrolled_sql_multiple_enrolments()
  test_get_enrolled_sql_userswithoutgroup()
  get_enrolled_sql_provider()
  test_get_enrolled_sql_course()
  test_permission_evaluation()
  assert_capability_list_contains()
  test_context_module_caps_returned_by_get_capabilities_in_sys_context()
  test_context_module_caps_returned_by_get_capabilities_in_course_cat_context()
  test_context_module_caps_returned_by_get_capabilities_in_course_context()
  test_context_module_caps_returned_by_get_capabilities_mod_context()
  test_context_block_caps_returned_by_get_capabilities_block_context()
  test_context_user_caps_returned_by_get_capabilities_user_context()
  test_update_capabilities()
  test_reset_role_capabilities()
  test_count_role_users()
  test_get_users_by_capability()
  test_get_with_capability_sql()
  get_get_with_capability_join_override_cases()
  test_get_with_capability_join_when_overrides_present()
  test_get_profile_roles()
  is_parent_of_provider()
  test_is_parent_of()
  is_child_of_provider()
  test_is_child_of()
  test_get_parent_contexts_preload()
  test_get_with_capability_sql_locked()
  test_get_users_by_capability_locked()
  test_require_all_capabilities()
  test_get_navigation_filter_context()

context_inspection:: (1 method):
  test_context_cache_size()


Class: core_accesslib_testcase  - X-Ref

Functional test for accesslib.php

Note: execution may take many minutes especially on slower servers.
test_context_comparisons()   X-Ref
Verify comparison of context instances in phpunit asserts.


test_accesslib_clear_all_caches()   X-Ref
Test resetting works.


test_capabilities_mutation()   X-Ref
Check modifying capability record is not exposed to other code.


test_get_role_access()   X-Ref
Test getting of role access


test_get_guest_role()   X-Ref
Test getting of guest role.


test_is_siteadmin()   X-Ref
Test if user is admin.


test_is_enrolled()   X-Ref
Test if user is enrolled in a course


test_isloggedin()   X-Ref
Test logged in test.


test_isguestuser()   X-Ref
Test guest user test.


test_is_safe_capability()   X-Ref
Test capability riskiness.


test_get_context_info_array()   X-Ref
Test context fetching.


test_has_coursecontact_role()   X-Ref
Test looking for course contacts.


test_create_role()   X-Ref
Test creation of roles.


test_assign_capability()   X-Ref
Test adding of capabilities to roles.


test_unassign_capability()   X-Ref
Test removing of capabilities from roles.


test_role_assign()   X-Ref
Test role assigning.


test_role_unassign()   X-Ref
Test role unassigning.


test_role_unassign_all()   X-Ref
Test role unassigning.


test_get_roles_with_capability()   X-Ref
Test role queries.


test_delete_role()   X-Ref
Test deleting of roles.


test_get_all_roles()   X-Ref
Test fetching of all roles.


test_get_role_archetypes()   X-Ref
Test getting of all archetypes.


test_get_archetype_roles()   X-Ref
Test getting of roles with given archetype.


test_role_get_name()   X-Ref
Test aliased role names.


test_role_fix_names()   X-Ref
Test tweaking of role name arrays.


test_get_default_role_archetype_allows()   X-Ref
Test role default allows.


test_core_role_set_assign_allowed()   X-Ref
Test allowing of role assignments.


test_core_role_set_override_allowed()   X-Ref
Test allowing of role overrides.


test_core_role_set_switch_allowed()   X-Ref
Test allowing of role switching.


test_core_role_set_view_allowed()   X-Ref
Test allowing of role switching.


test_get_assignable_roles()   X-Ref
Test returning of assignable roles in context.


test_get_assignable_roles_distinct_usercount()   X-Ref
Test user count of assignable roles in context where users are assigned the role via different components.


test_get_switchable_roles()   X-Ref
Test getting of all switchable roles.


test_get_overridable_roles()   X-Ref
Test getting of all overridable roles.


test_get_viewable_roles_course()   X-Ref
Test getting of all overridable roles.


test_get_viewable_roles_system()   X-Ref
Test getting of all overridable roles.


test_get_default_contextlevels()   X-Ref
Test we have context level defaults.


test_set_role_contextlevels()   X-Ref
Test role context level setup.


test_get_roles_for_contextlevels()   X-Ref
Test getting of role context levels


test_get_default_enrol_roles()   X-Ref
Test default enrol roles.


test_get_role_users()   X-Ref
Test getting of role users.


test_get_roles_used_in_context()   X-Ref
Test used role query.


test_get_user_roles_in_course()   X-Ref
Test roles used in course.


test_get_user_roles()   X-Ref
Test get_user_roles and get_users_roles


test_has_capability_and_friends()   X-Ref
Test has_capability(), has_any_capability() and has_all_capabilities().


test_fake_capability()   X-Ref
Test that assigning a fake cap does not return.


test_fake_capability_assign()   X-Ref
Test that assigning a fake cap does not return.


test_fake_capability_unassign()   X-Ref
Test that assigning a fake cap does not return.


test_role_definition_caching()   X-Ref
Test that the caching in get_role_definitions() and get_role_definitions_uncached()
works as intended.


test_get_user_capability_course()   X-Ref
Tests get_user_capability_course() which checks a capability across all courses.


assert_course_ids(array $expected, array $courses)   X-Ref
Extracts an array of course ids to make the above test script shorter.

param: int[] $expected Array of expected course ids
param: stdClass[] $courses Array of course objects

test_guess_if_creator_will_have_course_capability()   X-Ref
Test if course creator future capability lookup works.


test_require_capability()   X-Ref
Test require_capability() exceptions.


test_get_enrolled_sql_different_course()   X-Ref
Test that enrolled users SQL does not return any values for users in
other courses.


test_get_enrolled_sql_role_only()   X-Ref
Test that enrolled users SQL does not return any values for role
assignments without an enrolment.


test_get_enrolled_sql_multiple_enrolments()   X-Ref
Test that multiple enrolments for the same user are counted correctly.


test_get_enrolled_sql_userswithoutgroup()   X-Ref
Test that enrolled users SQL does not return any values for users
without a group when $context is not a valid course context.


get_enrolled_sql_provider()   X-Ref
No description

test_get_enrolled_sql_course($users, $counts)   X-Ref


test_permission_evaluation()   X-Ref
A small functional test of permission evaluations.


assert_capability_list_contains($expected, $actual)   X-Ref
Helper that verifies a list of capabilities, as returned by
$context->get_capabilities() contains certain capabilities.

param: array $expected a list of capability names
param: array $actual a list of capability info from $context->get_capabilities().

test_context_module_caps_returned_by_get_capabilities_in_sys_context()   X-Ref
Test that context_system::get_capabilities returns capabilities relevant to all modules.


test_context_module_caps_returned_by_get_capabilities_in_course_cat_context()   X-Ref
Test that context_coursecat::get_capabilities returns capabilities relevant to all modules.


test_context_module_caps_returned_by_get_capabilities_in_course_context()   X-Ref
Test that context_course::get_capabilities returns capabilities relevant to all modules.


test_context_module_caps_returned_by_get_capabilities_mod_context()   X-Ref
Test that context_module::get_capabilities returns capabilities relevant to all modules.


test_context_block_caps_returned_by_get_capabilities_block_context()   X-Ref
Test that {@see context_block::get_capabilities} returns capabilities relevant to blocks


test_context_user_caps_returned_by_get_capabilities_user_context()   X-Ref
Test that {@see context_user::get_capabilities} returns capabilities relevant to users


test_update_capabilities()   X-Ref
Test updating of role capabilities during upgrade


test_reset_role_capabilities()   X-Ref
Tests reset_role_capabilities function.


test_count_role_users()   X-Ref
Tests count_role_users function.


test_get_users_by_capability()   X-Ref
Test fetching users by capability.


test_get_with_capability_sql()   X-Ref
No description

get_get_with_capability_join_override_cases()   X-Ref
Get the test cases for {@link test_get_with_capability_join_when_overrides_present()}.

The particular capabilties used here do not really matter. What is important is
that they are capabilities which the Student roles has by default, but the
authenticated suser role does not.

return: array

test_get_with_capability_join_when_overrides_present(bool $studentshouldbereturned, array $capabilitiestoprevent)   X-Ref
Test get_with_capability_join.

param: bool $studentshouldbereturned whether, with this combination of capabilities, the student should be in the results.
param: array $capabilitiestoprevent capabilities to override to prevent in the course context.

test_get_profile_roles()   X-Ref
Test the get_profile_roles() function.


is_parent_of_provider()   X-Ref
Data provider for is_parent_of context checks.

return: array

test_is_parent_of(string $contextpath, string $testpath, bool $testself, bool $expected)   X-Ref
Ensure that the is_parent_of() function works as anticipated.

param: string $contextpath The path of the context being compared with
param: string $testpath The path of the context being compared
param: bool $testself Whether to check the current context
param: bool $expected The expected result

is_child_of_provider()   X-Ref
Data provider for is_child_of context checks.

return: array

test_is_child_of(string $contextpath, string $testpath, bool $testself, bool $expected)   X-Ref
Ensure that the is_child_of() function works as anticipated.

param: string $contextpath The path of the context being compared with
param: string $testpath The path of the context being compared
param: bool $testself Whether to check the current context
param: bool $expected The expected result

test_get_parent_contexts_preload()   X-Ref
Ensure that the get_parent_contexts() function limits the number of queries it performs.


test_get_with_capability_sql_locked()   X-Ref
Ensure that get_with_capability_sql and get_with_capability_join respect context locking.


test_get_users_by_capability_locked()   X-Ref
Ensure that get_users_by_capability respects context freezing.


test_require_all_capabilities()   X-Ref
Test require_all_capabilities.


test_get_navigation_filter_context()   X-Ref
Test get_navigation_filter_context.


Class: context_inspection  - X-Ref

Context caching fixture

test_context_cache_size()   X-Ref
No description