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

Unit tests fail if an add-on creates a course category at install time

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: 2.6.1
    • Fix Version/s: 2.6.2, 2.7
    • Component/s: Unit tests
    • Labels:
    • Testing Instructions:
      Hide

      1. Knock up a local add-on with an install.php containing something like

      function xmldb_local_convertoldbackup_install() {
          global $DB, $CFG;
          require_once($CFG->dirroot . '/local/convertoldbackup/locallib.php');
       
          // Create category if it doesn't exist
          if (!$DB->record_exists('course_categories',
                  array('name'=>'Converted 1.9 websites'))) {
              $category = (object)array(
                  'name'=>'Converted 1.9 websites',
                  'parent'=>0,
                  'sortorder'=>90000,
                  'coursecount'=>0,
                  'visible'=>1,
                  'visibleold'=>1,
                  'depth'=>1);
              $id = $DB->insert_record('course_categories', $category);
              $DB->set_field('course_categories', 'path', '/' . $id, array('id'=>$id));
              cache::make('core', 'coursecat')->purge();
              context_coursecat::instance($id);
          }
      }
      

      and a version.php.

      Re-install your PHPUnit tables, and run the unit tests.

      Show
      1. Knock up a local add-on with an install.php containing something like function xmldb_local_convertoldbackup_install() { global $DB, $CFG; require_once($CFG->dirroot . '/local/convertoldbackup/locallib.php');   // Create category if it doesn't exist if (!$DB->record_exists('course_categories', array('name'=>'Converted 1.9 websites'))) { $category = (object)array( 'name'=>'Converted 1.9 websites', 'parent'=>0, 'sortorder'=>90000, 'coursecount'=>0, 'visible'=>1, 'visibleold'=>1, 'depth'=>1); $id = $DB->insert_record('course_categories', $category); $DB->set_field('course_categories', 'path', '/' . $id, array('id'=>$id)); cache::make('core', 'coursecat')->purge(); context_coursecat::instance($id); } } and a version.php. Re-install your PHPUnit tables, and run the unit tests.
    • Workaround:
      1. Install mod_oublog.
      2. Run the unit tests.
    • Affected Branches:
      MOODLE_26_STABLE
    • Fixed Branches:
      MOODLE_26_STABLE, MOODLE_27_STABLE
    • Pull from Repository:
    • Pull Master Branch:

      Description

      Core unit tests must not hard-code things like context ids. If you install an Add-on like mod_oublog, then logs of core unit tests fail.

      I'm fixing this.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

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