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

    Details

    • Testing Instructions:
      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.
    • Affected Branches:
      MOODLE_27_STABLE
    • Fixed Branches:
      MOODLE_27_STABLE
    • Pull from Repository:
    • Pull Master Branch:

      Description

      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
      

        Attachments

          Activity

            People

            • Assignee:
              timhunt Tim Hunt
              Reporter:
              johno John Okely
              Peer reviewer:
              Sam Marshall
              Integrator:
              Dan Poltawski
              Tester:
              Simey Lameze
              Participants:
              Component watchers:
              Amaia Anabitarte, Bas Brands, Carlos Escobedo, Sara Arjona (@sarjona), Víctor Déniz Falcón, Andrew Nicols, Mathew May, Michael Hawkins, Shamim Rezaie, Simey Lameze
            • Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

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