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]

Unit tests for badges

Author: Yuliya Bozhko <yuliya.bozhko@totaralms.com>
Copyright: 2013 onwards Totara Learning Solutions Ltd {@link http://www.totaralms.com/}
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 1641 lines (73 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

badgeslib_test:: (44 methods):
  setUp()
  test_create_badge()
  test_clone_badge()
  test_badge_status()
  test_delete_badge()
  test_delete_badge_for_real()
  test_create_badge_criteria()
  test_add_badge_criteria_description()
  test_delete_badge_criteria()
  test_badge_awards()
  test_badges_get_user_badges()
  data_for_message_from_template()
  test_badge_message_from_template()
  test_badges_observer_course_module_criteria_review()
  test_badges_observer_course_criteria_review()
  test_badges_observer_profile_criteria_review()
  test_badges_observer_any_cohort_criteria_review()
  test_badges_observer_all_cohort_criteria_review()
  test_badges_assertion()
  test_core_badges_myprofile_navigation()
  test_core_badges_myprofile_navigation_badges_disabled()
  test_core_badges_myprofile_navigation_with_course_badge()
  test_badge_endorsement()
  test_badge_related()
  test_alignments()
  test_badges_delete_site_backpack()
  test_save_backpack_credentials()
  save_backpack_credentials_provider()
  test_badges_save_external_backpack()
  badges_save_external_backpack_provider()
  test_badges_create_site_backpack()
  badges_create_site_backpack_provider()
  test_badges_open_badges_backpack_api()
  test_badges_get_site_backpack()
  test_badges_get_user_backpack()
  test_badges_get_site_primary_backpack()
  badges_get_site_primary_backpack_provider()
  test_badges_change_sortorder_backpacks()
  badges_change_sortorder_backpacks_provider()
  test_badges_generate_badgr_open_url()
  badgr_open_url_generator()
  test_badges_external_get_mapping()
  badges_external_get_mapping_provider()
  move_backpack_to_first_position()


Class: badgeslib_test  - X-Ref

setUp()   X-Ref
No description

test_create_badge()   X-Ref
No description

test_clone_badge()   X-Ref
No description

test_badge_status()   X-Ref
No description

test_delete_badge()   X-Ref
No description

test_delete_badge_for_real()   X-Ref
Really delete the badge.


test_create_badge_criteria()   X-Ref
No description

test_add_badge_criteria_description()   X-Ref
No description

test_delete_badge_criteria()   X-Ref
No description

test_badge_awards()   X-Ref
No description

test_badges_get_user_badges()   X-Ref
Test the {@link badges_get_user_badges()} function in lib/badgeslib.php


data_for_message_from_template()   X-Ref
No description

test_badge_message_from_template($message, $params, $result)   X-Ref


test_badges_observer_course_module_criteria_review()   X-Ref
Test badges observer when course module completion event id fired.


test_badges_observer_course_criteria_review()   X-Ref
Test badges observer when course_completed event is fired.


test_badges_observer_profile_criteria_review()   X-Ref
Test badges observer when user_updated event is fired.


test_badges_observer_any_cohort_criteria_review()   X-Ref
Test badges observer when cohort_member_added event is fired and user required to belong to any cohort.


test_badges_observer_all_cohort_criteria_review()   X-Ref
Test badges observer when cohort_member_added event is fired and user required to belong to multiple (all) cohorts.


test_badges_assertion()   X-Ref
Test badges assertion generated when a badge is issued.


test_core_badges_myprofile_navigation()   X-Ref
Tests the core_badges_myprofile_navigation() function.


test_core_badges_myprofile_navigation_badges_disabled()   X-Ref
Tests the core_badges_myprofile_navigation() function with badges disabled..


test_core_badges_myprofile_navigation_with_course_badge()   X-Ref
Tests the core_badges_myprofile_navigation() function with a course badge.


test_badge_endorsement()   X-Ref
Test insert and update endorsement with a site badge.


test_badge_related()   X-Ref
Test insert and delete related badge with a site badge.


test_alignments()   X-Ref
Test insert, update, delete alignment with a site badge.


test_badges_delete_site_backpack()   X-Ref
Test badges_delete_site_backpack().


test_save_backpack_credentials(bool $addbackpack = true, ?string $mail = null, ?string $password = null)   X-Ref
Test to validate badges_save_backpack_credentials.

param: bool $addbackpack True if backpack data has to be created; false otherwise (empty data will be used then).
param: string|null  $mail  Backpack mail address.
param: string|null  $password  Backpack password.

save_backpack_credentials_provider()   X-Ref
Data provider for test_create_backpack_credentials().

return: array

test_badges_save_external_backpack(array $data, bool $adduser, bool $duplicates)   X-Ref
Test badges_save_external_backpack.

param: array $data  Backpack data to save.
param: bool $adduser True if a real user has to be used for creating the backpack; false otherwise.
param: bool $duplicates True if duplicates has to be tested too; false otherwise.

badges_save_external_backpack_provider()   X-Ref
Provider for test_badges_save_external_backpack

return: array

test_badges_create_site_backpack($isadmin, $updatetest)   X-Ref
Test backpack creation/update with auth details provided

param: boolean $isadmin
param: boolean $updatetest

badges_create_site_backpack_provider()   X-Ref
Provider for test_badges_(create/update)_site_backpack


test_badges_open_badges_backpack_api()   X-Ref
Test the badges_open_badges_backpack_api with different backpacks


test_badges_get_site_backpack()   X-Ref
Test the badges_get_site_backpack function


test_badges_get_user_backpack()   X-Ref
Test the badges_get_user_backpack function


test_badges_get_site_primary_backpack($withauth)   X-Ref
Test the badges_get_site_primary_backpack function

param: boolean $withauth Testing with authentication or not.

badges_get_site_primary_backpack_provider()   X-Ref
Test the test_badges_get_site_primary_backpack function.

return: array

test_badges_change_sortorder_backpacks(int $backpacktomove, int $direction, ?int $expectedsortorder)   X-Ref
Test badges_change_sortorder_backpacks().

param: int $backpacktomove Backpack index to move (from 0 to 5).
param: int $direction Direction to move the backpack.
param: int|null $expectedsortorder Expected sortorder or null if an exception is expected.

badges_change_sortorder_backpacks_provider()   X-Ref
Provider for test_badges_change_sortorder_backpacks.

return: array

test_badges_generate_badgr_open_url($type, $expected)   X-Ref
Test the Badgr URL generator function

param: mixed $type Type corresponding to the badge entites
param: string $expected Expected string result

badgr_open_url_generator()   X-Ref
Data provider for test_badges_generate_badgr_open_url

return: array

test_badges_external_get_mapping($internalid, $externalid, $expected, $field = null)   X-Ref
Test badges_external_get_mapping function

param: int $internalid The internal id of the mapping
param: int $externalid The external / remote ref to the mapping
param: mixed $expected The expected result from the function
param: string|null $field The field we are passing to the function. Null if we don't want to pass anything.ss

badges_external_get_mapping_provider()   X-Ref
Data provider for badges_external_get_mapping_provider

return: array

move_backpack_to_first_position(int $backpackid)   X-Ref
Move the backpack to the first position, to set it as primary site backpack.

param: int $backpackid The backpack identifier.