Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-47667

test_get_custom_fields makes false assumpiton that no plugin will create a custom user profile field on install

XMLWordPrintable

    • MOODLE_27_STABLE
    • MOODLE_27_STABLE
    • Hide

      1. Find or make an add-on that creates a custom user profile field in install.php. E.g.

      function xmldb_local_profilevisibility_install() {
          global $DB, $CFG;
          require_once($CFG->dirroot.'/local/profilevisibility/lib.php');
          //check or add the category
          $strprofvis = get_string('profilevisibility', 'local_profilevisibility');
          if (!$category = $DB->get_record('user_info_category', array('name'=>$strprofvis))) {
              $sql = 'SELECT MAX(sortorder) FROM {user_info_category}';
              if ($sort = $DB->get_record_sql($sql)) {
                  $sortorder = $sort->max;
              } else {
                  $sortorder = 0;
              }
              $category = new StdClass;
              $category->name = $strprofvis;
              $category->sortorder = $sortorder + 1;
              $category->id = $DB->insert_record('user_info_category', $category);
          }
          //check or add the user profile field
          if (!$DB->count_records('user_info_field', array('shortname'=>'profilevisibility'))) {
              $field = new StdClass;
              $field->shortname = 'profilevisibility';
              $field->name = $strprofvis;
              $field->datatype = 'menu';
              $field->description = '';
              $field->descriptionformat = 1;
              $field->categoryid = $category->id;
              $field->sortorder = 1;
              $field->required = 0;
              $field->locked = 0;
              $field->visible = 1;
              $field->forceunique = 0;
              $field->signup = 0;
              $field->defaultdata = LOCAL_PROFILE_VISIBILITY_COURSE;
              $field->defaultdataformat = 0;
              $field->param1 = LOCAL_PROFILE_VISIBILITY_COURSE."\n".
                      LOCAL_PROFILE_VISIBILITY_NONE."\n".LOCAL_PROFILE_VISIBILITY_ALL;
              $DB->insert_record('user_info_field', $field);
          }
      }
      

      2. Run the unit tests.

      Show
      1. Find or make an add-on that creates a custom user profile field in install.php. E.g. function xmldb_local_profilevisibility_install() { global $DB , $CFG ; require_once ( $CFG ->dirroot. '/local/profilevisibility/lib.php' ); //check or add the category $strprofvis = get_string( 'profilevisibility' , 'local_profilevisibility' ); if (! $category = $DB ->get_record( 'user_info_category' , array ( 'name' => $strprofvis ))) { $sql = 'SELECT MAX(sortorder) FROM {user_info_category}' ; if ( $sort = $DB ->get_record_sql( $sql )) { $sortorder = $sort ->max; } else { $sortorder = 0; } $category = new StdClass; $category ->name = $strprofvis ; $category ->sortorder = $sortorder + 1; $category ->id = $DB ->insert_record( 'user_info_category' , $category ); } //check or add the user profile field if (! $DB ->count_records( 'user_info_field' , array ( 'shortname' => 'profilevisibility' ))) { $field = new StdClass; $field ->shortname = 'profilevisibility' ; $field ->name = $strprofvis ; $field ->datatype = 'menu' ; $field ->description = '' ; $field ->descriptionformat = 1; $field ->categoryid = $category ->id; $field ->sortorder = 1; $field ->required = 0; $field ->locked = 0; $field ->visible = 1; $field ->forceunique = 0; $field ->signup = 0; $field ->defaultdata = LOCAL_PROFILE_VISIBILITY_COURSE; $field ->defaultdataformat = 0; $field ->param1 = LOCAL_PROFILE_VISIBILITY_COURSE. "\n" . LOCAL_PROFILE_VISIBILITY_NONE. "\n" .LOCAL_PROFILE_VISIBILITY_ALL; $DB ->insert_record( 'user_info_field' , $field ); } } 2. Run the unit tests.

      We are getting unit tests failures at the OU due to this false assumption:

      6) core_user_profilelib_testcase::test_get_custom_fields
      Failed asserting that two arrays are equal.
      --- Expected
      +++ Actual
      @@ @@
       Array (
      +    1 => stdClass Object (...)
       )
       
      C:\Users\rg3598\workspace\ou-moodle2\user\tests\profilelib_test.php:49
      C:\Users\rg3598\workspace\ou-moodle2\lib\phpunit\classes\advanced_testcase.php:80
       
      To re-run:
       c:/Users/rg3598/workspace/ou-moodle2/vendor/phpunit/phpunit/composer/bin/phpunit core_user_profilelib_testcase user\tests\profilelib_test.php
      

            timhunt Tim Hunt
            timhunt Tim Hunt
            Ray Guo Ray Guo
            Damyon Wiese Damyon Wiese
            John Okely John Okely
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.