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

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.7.2
    • Fix Version/s: 2.7.3
    • Component/s: Libraries, Unit tests
    • Labels:
    • Testing Instructions:
      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.
    • Affected Branches:
      MOODLE_27_STABLE
    • Fixed Branches:
      MOODLE_27_STABLE
    • Pull from Repository:
    • Pull Master Branch:

      Description

      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
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                timhunt Tim Hunt
                Reporter:
                timhunt Tim Hunt
                Peer reviewer:
                Ray Guo
                Integrator:
                Damyon Wiese
                Tester:
                John Okely
                Participants:
                Component watchers:
                Amaia Anabitarte, Carlos Escobedo, Sara Arjona (@sarjona), Víctor Déniz Falcón, Andrew Nicols, Mathew May, Michael Hawkins, Shamim Rezaie, Simey Lameze
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  10/Nov/14