Permalink
Browse files

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

… into MOODLE_24_STABLE
  • Loading branch information...
2 parents 823b45c + 1a44518 commit db0c7b4e7ba76470c8fff975188c0ab78321aa24 @damyon damyon committed Feb 26, 2013
Showing with 63 additions and 3 deletions.
  1. +1 −2 lib/conditionlib.php
  2. +10 −0 lib/db/upgrade.php
  3. +51 −0 lib/tests/conditionlib_test.php
  4. +1 −1 version.php
@@ -613,7 +613,6 @@ public static function get_condition_user_fields() {
'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 @@ private function is_field_condition_met($operator, $uservalue, $value) {
* @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) {
View
@@ -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;
}
@@ -735,5 +735,56 @@ public function test_section_is_available() {
$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);
+ }
+}
View
@@ -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

0 comments on commit db0c7b4

Please sign in to comment.