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

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Blocker Blocker
    • 2.6.2, 2.7
    • 2.6.1
    • Unit tests
    • MOODLE_26_STABLE
    • MOODLE_26_STABLE, MOODLE_27_STABLE
      1. Install mod_oublog.
      2. Run the unit tests.
    • 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.

      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.

            timhunt Tim Hunt
            timhunt Tim Hunt
            Petr Skoda Petr Skoda
            Marina Glancy Marina Glancy
            Ankit Agarwal Ankit Agarwal
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

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