MDL-37792 Conditions: Interests condition offered but not implemented
This commit is contained in:
@@ -735,5 +735,56 @@ class conditionlib_testcase extends advanced_testcase {
|
||||
$this->assertFalse($ci->is_available($text, false, $USER->id + 1));
|
||||
$this->assertFalse($ci->is_available($text, true, $USER->id + 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests user fields to ensure that the list of provided fields includes only
|
||||
* fields which the equivalent function can be used to obtain the value of.
|
||||
*/
|
||||
public function test_condition_user_fields() {
|
||||
global $CFG, $DB, $USER;
|
||||
|
||||
// Set up basic data.
|
||||
$courseid = $this->make_course();
|
||||
$cmid = $this->make_course_module($courseid);
|
||||
$ci = new condition_info_testwrapper(
|
||||
(object)array('id' => $cmid), CONDITION_MISSING_EVERYTHING);
|
||||
|
||||
// Add a custom user profile field. Unfortunately there is no back-end
|
||||
// API for adding profile fields without having an actual form and doing
|
||||
// redirects and stuff! These are the default text field parameters.
|
||||
require_once($CFG->dirroot . '/user/profile/lib.php');
|
||||
$field = (object)array(
|
||||
'shortname' => 'myfield', 'name' => 'My field', 'required' => 0,
|
||||
'locked' => 0, 'forceunique' => 0, 'signup' => 0,
|
||||
'visible' => PROFILE_VISIBLE_ALL,
|
||||
'datatype' => 'text', 'description' => 'A field of mine',
|
||||
'descriptionformat' => FORMAT_HTML, 'defaultdata' => '',
|
||||
'defaultdataformat' => FORMAT_HTML, 'param1' => 30, 'param2' => 2048,
|
||||
'param3' => 0, 'param4' => '', 'param5' => '');
|
||||
$customfieldid = $DB->insert_record('user_info_field', $field);
|
||||
|
||||
// Get list of condition user fields.
|
||||
$fields = condition_info::get_condition_user_fields();
|
||||
|
||||
// Check custom field is included.
|
||||
$this->assertEquals('My field', $fields[$customfieldid]);
|
||||
|
||||
// For all other fields, check it actually works to get data from them.
|
||||
foreach ($fields as $fieldid => $name) {
|
||||
// Not checking the result, just that it's possible to get it
|
||||
// without error.
|
||||
$ci->get_cached_user_profile_field($USER->id, $fieldid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test wrapper used only to make protected functions public so they can be
|
||||
* tested.
|
||||
*/
|
||||
class condition_info_testwrapper extends condition_info {
|
||||
public function get_cached_user_profile_field($userid, $fieldid) {
|
||||
return parent::get_cached_user_profile_field($userid, $fieldid);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user