Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

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

Unit tests for the user profile condition.

Copyright: 2014 The Open University
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 554 lines (24 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

availability_profile_condition_testcase:: (11 methods):
  setUp()
  test_in_tree()
  test_constructor()
  test_save()
  test_is_available()
  test_custom_textarea_field()
  set_field()
  assert_is_available_result()
  test_filter_users()
  test_get_user_list_sql()
  assert_user_list_sql_results()


Class: availability_profile_condition_testcase  - X-Ref

Unit tests for the user profile condition.

setUp()   X-Ref
No description

test_in_tree()   X-Ref
Tests constructing and using date condition as part of tree.


test_constructor()   X-Ref
Tests the constructor including error conditions. Also tests the
string conversion feature (intended for debugging only).


test_save()   X-Ref
Tests the save() function.


test_is_available()   X-Ref
Tests the is_available function. There is no separate test for
get_full_information because that function is called from is_available
and we test its values here.


test_custom_textarea_field()   X-Ref
Tests what happens with custom fields that are text areas. These should
not be offered in the menu because their data is not included in user
object


set_field($userid, $value, $fieldid = 0)   X-Ref
Sets the custom profile field used for testing.

param: int $userid User id
param: string|null $value Field value or null to clear
param: int $fieldid Field id or 0 to use default one

assert_is_available_result($yes, $failpattern, condition $cond,\core_availability\info $info, $userid)   X-Ref
Checks the result of is_available. This function is to save duplicated
code; it does two checks (the normal is_available with $not set to true
and set to false). Whichever result is expected to be true, it checks
$information ends up as empty string for that one, and as a regex match
for another one.

param: bool $yes If the positive test is expected to return true
param: string $failpattern Regex pattern to match text when it returns false
param: condition $cond Condition
param: \core_availability\info $info Information about current context
param: int $userid User id

test_filter_users()   X-Ref
Tests the filter_users (bulk checking) function.


test_get_user_list_sql()   X-Ref
Tests getting user list SQL. This is a different test from the above because
there is some additional code in this function so more variants need testing.


assert_user_list_sql_results(array $expected, $not = false)   X-Ref
Convenience function. Gets the user list SQL and runs it, then checks
results.

param: array $expected Array of expected user ids
param: bool $not True if using NOT condition