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

Filebrowser unit tests shouldn't assume content of system context

XMLWordPrintable

    • MOODLE_34_STABLE, MOODLE_35_STABLE
    • MOODLE_34_STABLE, MOODLE_35_STABLE
    • MDL-62488_master
    • Hide
      1. Open your terminal and go to your moodle instance's root folder.
      2. Initialise PHPUnit and run the tests for lib/filebrowser/tests/file_browser_test.php
        • Normal method

          php admin/tool/phpunit/cli/init.php
          vendor/bin/phpunit lib/filebrowser/tests/file_browser_test.php
          

        • If using MDK (easier way):

          mdk phpunit -r -u lib/filebrowser/tests/file_browser_test.php

      3. Confirm that the test passes.
      4. Edit mod/folder/db/install.php and replace the xmldb_folder_install function with:

        function xmldb_folder_install() {
            global $DB;
            $category = (object) array(
                'name' => 'New category',
                '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);
        }
        

      5. Reinitialise PHPUnit and run the tests for lib/filebrowser/tests/file_browser_test.php again
        • Normal method:

          php admin/tool/phpunit/cli/util.php --drop
          php admin/tool/phpunit/cli/init.php
          vendor/bin/phpunit lib/filebrowser/tests/file_browser_test.php
          

        • If using MDK (way easier!)

          mdk phpunit -f -r -u lib/filebrowser/tests/file_browser_test.php

      6. Confirm that the tests pass
      Show
      Open your terminal and go to your moodle instance's root folder. Initialise PHPUnit and run the tests for lib/filebrowser/tests/file_browser_test.php Normal method php admin/tool/phpunit/cli/init.php vendor/bin/phpunit lib/filebrowser/tests/file_browser_test.php If using MDK (easier way): mdk phpunit -r -u lib/filebrowser/tests/file_browser_test.php Confirm that the test passes. Edit mod/folder/db/install.php and replace the xmldb_folder_install function with: function xmldb_folder_install() { global $DB; $category = (object) array( 'name' => 'New category', '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); } Reinitialise PHPUnit and run the tests for lib/filebrowser/tests/file_browser_test.php again Normal method: php admin/tool/phpunit/cli/util.php --drop php admin/tool/phpunit/cli/init.php vendor/bin/phpunit lib/filebrowser/tests/file_browser_test.php If using MDK (way easier!) mdk phpunit -f -r -u lib/filebrowser/tests/file_browser_test.php Confirm that the tests pass

      The file browser unit tests assume that there is 1 course category and no courses in the system context before the tests begin.

      If another plugin creates some categories or courses as part of its install code (as is the case for one of our plugins), or the default setup changes in the future, this breaks the file browser unit tests.

            marxjohnson Mark Johnson
            marxjohnson Mark Johnson
            Tim Hunt Tim Hunt
            Andrew Lyons Andrew Lyons
            Anna Carissa Sadia Anna Carissa Sadia
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 30 minutes
                30m

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