Merge branch 'MDL-37792-m24' of git://github.com/sammarshallou/moodle into MOODLE_24_STABLE

This commit is contained in:
Damyon Wiese
2013-02-26 10:54:48 +08:00
4 changed files with 63 additions and 3 deletions
+1 -2
View File
@@ -613,7 +613,6 @@ abstract class condition_info_base {
'email' => get_user_field_name('email'),
'city' => get_user_field_name('city'),
'country' => get_user_field_name('country'),
'interests' => get_user_field_name('interests'),
'url' => get_user_field_name('url'),
'icq' => get_user_field_name('icq'),
'skype' => get_user_field_name('skype'),
@@ -1252,7 +1251,7 @@ abstract class condition_info_base {
* @param int $fieldid the user profile field id
* @return string the user value, or false if user does not have a user field value yet
*/
private function get_cached_user_profile_field($userid, $fieldid) {
protected function get_cached_user_profile_field($userid, $fieldid) {
global $USER, $DB, $CFG;
if ($userid === 0) {
+10
View File
@@ -1600,5 +1600,15 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2012120301.11);
}
if ($oldversion < 2012120301.13) {
// Delete entries regarding invalid 'idnumber' option which breaks course.
$DB->delete_records('course_sections_avail_fields', array('userfield' => 'idnumber'));
$DB->delete_records('course_modules_avail_fields', array('userfield' => 'idnumber'));
// Clear course cache (will be rebuilt on first visit) in case of changes to these.
rebuild_course_cache(0, true);
upgrade_main_savepoint(true, 2012120301.13);
}
return true;
}
+51
View File
@@ -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);
}
}
+1 -1
View File
@@ -30,7 +30,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2012120301.12; // 20121203 = branching date YYYYMMDD - do not modify!
$version = 2012120301.13; // 20121203 = branching date YYYYMMDD - do not modify!
// RR = release increments - 00 in DEV branches
// .XX = incremental changes