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

test_custom_textarea_field fails when a plugin creates a custom user text field during 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 (must be text to cause this failure). 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 = 'text';
                $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 = 'Default';
                $field->defaultdataformat = 0;
                $DB->insert_record('user_info_field', $field);
            }
        }
        

      2. Run the unit tests.
      Show
      Find or make an add-on that creates a custom user profile field in install.php (must be text to cause this failure). 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 = 'text' ; $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 = 'Default' ; $field ->defaultdataformat = 0; $DB ->insert_record( 'user_info_field' , $field ); } } Run the unit tests.

      Reproduction steps

      1. Find or make an add-on that creates a custom user profile field in install.php (must be text to cause this failure). 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 = 'text';
                $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 = 'Default';
                $field->defaultdataformat = 0;
                $DB->insert_record('user_info_field', $field);
            }
        }
        

      2. Run the unit tests.

      Result

      There was 1 failure:
       
      1) availability_profile_condition_testcase::test_custom_textarea_field
      Failed asserting that two arrays are equal.
      --- Expected
      +++ Actual
      @@ @@
       Array (
      -    0 => 'frogtype'
      +    0 => 'newfield'
      +    1 => 'frogtype'
       )
       
      /home/moodle/moodles/peer_review/moodle/availability/condition/profile/tests/condition_test.php:345
      /home/moodle/moodles/peer_review/moodle/lib/phpunit/classes/advanced_testcase.php:80
       
      To re-run:
       vendor/bin/phpunit availability_profile_condition_testcase availability/condition/profile/tests/condition_test.php
      

            timhunt Tim Hunt
            johno John Okely
            Sam Marshall Sam Marshall
            Dan Poltawski Dan Poltawski
            Simey Lameze Simey Lameze
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:

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