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

Filebrowser unit tests shouldn't assume content of system context

    XMLWordPrintable

    Details

    • Testing Instructions:
      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
    • Affected Branches:
      MOODLE_34_STABLE, MOODLE_35_STABLE
    • Fixed Branches:
      MOODLE_34_STABLE, MOODLE_35_STABLE
    • Pull 3.5 Branch:
      MDL-62488_35_STABLE
    • Pull Master Branch:
      MDL-62488_master

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                marxjohnson Mark Johnson
                Reporter:
                marxjohnson Mark Johnson
                Peer reviewer:
                Tim Hunt
                Integrator:
                Andrew Nicols
                Tester:
                Anna Carissa Sadia
                Participants:
                Component watchers:
                Matteo Scaramuccia, Jake Dallimore, Jun Pataleta, Andrew Nicols, Mathew May, Michael Hawkins, Shamim Rezaie, Simey Lameze
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  9/Jul/18

                  Time Tracking

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